Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
541419e3
Commit
541419e3
authored
Sep 10, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5141 from edx/will/fix-embargo-tests
Fix embargo middleware with tests
parents
d21384fe
512db7be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletions
+20
-1
common/djangoapps/embargo/middleware.py
+1
-1
common/djangoapps/embargo/tests/test_middleware.py
+19
-0
No files found.
common/djangoapps/embargo/middleware.py
View file @
541419e3
...
...
@@ -166,7 +166,7 @@ class EmbargoMiddleware(object):
profile_country
=
cache
.
get
(
cache_key
)
if
profile_country
is
None
:
profile
=
getattr
(
user
,
'profile'
,
None
)
if
profile
is
not
None
and
profile
.
country
is
not
None
:
if
profile
is
not
None
and
profile
.
country
.
code
is
not
None
:
profile_country
=
profile
.
country
.
code
.
upper
()
else
:
profile_country
=
""
...
...
common/djangoapps/embargo/tests/test_middleware.py
View file @
541419e3
...
...
@@ -8,6 +8,7 @@ import unittest
from
django.core.urlresolvers
import
reverse
from
django.conf
import
settings
from
django.db
import
connection
,
transaction
from
django.test.utils
import
override_settings
import
ddt
...
...
@@ -267,6 +268,24 @@ class EmbargoMiddlewareTests(ModuleStoreTestCase):
with
self
.
assertNumQueries
(
12
):
self
.
client
.
get
(
self
.
embargoed_page
)
def
test_embargo_profile_country_db_null
(
self
):
# Django country fields treat NULL values inconsistently.
# When saving a profile with country set to None, Django saves an empty string to the database.
# However, when the country field loads a NULL value from the database, it sets
# `country.code` to `None`. This caused a bug in which country values created by
# the original South schema migration -- which defaulted to NULL -- caused a runtime
# exception when the embargo middleware treated the value as a string.
# In order to simulate this behavior, we can't simply set `profile.country = None`.
# (because when we save it, it will set the database field to an empty string instead of NULL)
query
=
"UPDATE auth_userprofile SET country = NULL WHERE id =
%
s"
connection
.
cursor
()
.
execute
(
query
,
[
str
(
self
.
user
.
profile
.
id
)])
transaction
.
commit_unless_managed
()
# Attempt to access an embargoed course
# Verify that the student can access the page without an error
response
=
self
.
client
.
get
(
self
.
embargoed_page
)
self
.
assertEqual
(
response
.
status_code
,
200
)
@mock.patch.dict
(
settings
.
FEATURES
,
{
'EMBARGO'
:
False
})
def
test_countries_embargo_off
(
self
):
# When the middleware is turned off, all requests should go through
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment