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
eaf6be2a
Commit
eaf6be2a
authored
Oct 22, 2015
by
Peter Fogg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix up quality errors in config model API.
parent
96b49759
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
9 deletions
+23
-9
common/djangoapps/config_models/models.py
+1
-1
common/djangoapps/config_models/tests.py
+8
-3
common/djangoapps/config_models/views.py
+8
-2
common/test/acceptance/fixtures/config.py
+6
-3
No files found.
common/djangoapps/config_models/models.py
View file @
eaf6be2a
...
...
@@ -94,7 +94,7 @@ class ConfigurationModel(models.Model):
Clear the cached value when saving a new configuration entry
"""
# Always create a new entry, instead of updating an existing model
self
.
pk
=
None
self
.
pk
=
None
# pylint: disable=invalid-name
super
(
ConfigurationModel
,
self
)
.
save
(
*
args
,
**
kwargs
)
cache
.
delete
(
self
.
cache_key_name
(
*
[
getattr
(
self
,
key
)
for
key
in
self
.
KEY_FIELDS
]))
if
self
.
KEY_FIELDS
:
...
...
common/djangoapps/config_models/tests.py
View file @
eaf6be2a
...
...
@@ -95,7 +95,7 @@ class ConfigurationModelTests(TestCase):
self
.
assertEqual
(
rows
[
1
]
.
string_field
,
'first'
)
self
.
assertEqual
(
rows
[
1
]
.
is_active
,
False
)
def
test_always_insert
(
self
,
mock_cache
):
def
test_always_insert
(
self
,
__
):
config
=
ExampleConfig
(
changed_by
=
self
.
user
,
string_field
=
'first'
)
config
.
save
()
config
.
string_field
=
'second'
...
...
@@ -297,7 +297,11 @@ class KeyedConfigurationModelTests(TestCase):
@ddt.ddt
class
ConfigurationModelAPITests
(
TestCase
):
"""
Tests for the configuration model API.
"""
def
setUp
(
self
):
super
(
ConfigurationModelAPITests
,
self
)
.
setUp
()
self
.
factory
=
APIRequestFactory
()
self
.
user
=
User
.
objects
.
create_user
(
username
=
'test_user'
,
...
...
@@ -319,7 +323,7 @@ class ConfigurationModelAPITests(TestCase):
request
=
self
.
factory
.
post
(
'/config/ExampleConfig'
,
{
"string_field"
:
"string_value"
})
request
.
user
=
self
.
user
response
=
self
.
current_view
(
request
)
__
=
self
.
current_view
(
request
)
self
.
assertEquals
(
"string_value"
,
ExampleConfig
.
current
()
.
string_field
)
self
.
assertEquals
(
self
.
user
,
ExampleConfig
.
current
()
.
changed_by
)
...
...
@@ -333,13 +337,14 @@ class ConfigurationModelAPITests(TestCase):
response
=
self
.
current_view
(
request
)
self
.
assertEquals
(
201
,
response
.
status_code
)
self
.
assertEquals
(
i
+
1
,
ExampleConfig
.
objects
.
all
()
.
count
())
self
.
assertEquals
(
i
+
1
,
ExampleConfig
.
objects
.
all
()
.
count
())
self
.
assertEquals
(
str
(
i
),
ExampleConfig
.
current
()
.
string_field
)
def
test_get_current
(
self
):
request
=
self
.
factory
.
get
(
'/config/ExampleConfig'
)
request
.
user
=
self
.
user
response
=
self
.
current_view
(
request
)
# pylint: disable=no-member
self
.
assertEquals
(
''
,
response
.
data
[
'string_field'
])
self
.
assertEquals
(
10
,
response
.
data
[
'int_field'
])
self
.
assertEquals
(
None
,
response
.
data
[
'changed_by'
])
...
...
common/djangoapps/config_models/views.py
View file @
eaf6be2a
"""
API view to allow manipulation of configuration models.
"""
from
rest_framework.generics
import
CreateAPIView
,
RetrieveAPIView
from
rest_framework.permissions
import
DjangoModelPermissions
from
rest_framework.authentication
import
SessionAuthentication
...
...
@@ -5,6 +8,7 @@ from rest_framework.serializers import ModelSerializer
class
ReadableOnlyByAuthors
(
DjangoModelPermissions
):
"""Only allow access by users with `add` permissions on the model."""
perms_map
=
DjangoModelPermissions
.
perms_map
.
copy
()
perms_map
[
'GET'
]
=
perms_map
[
'OPTIONS'
]
=
perms_map
[
'HEAD'
]
=
perms_map
[
'POST'
]
...
...
@@ -32,7 +36,9 @@ class ConfigurationModelCurrentAPIView(CreateAPIView, RetrieveAPIView):
def
get_serializer_class
(
self
):
if
self
.
serializer_class
is
None
:
class
AutoConfigModelSerializer
(
ModelSerializer
):
class
Meta
:
"""Serializer class for configuration models."""
class
Meta
(
object
):
"""Meta information for AutoConfigModelSerializer."""
model
=
self
.
model
self
.
serializer_class
=
AutoConfigModelSerializer
...
...
@@ -41,4 +47,4 @@ class ConfigurationModelCurrentAPIView(CreateAPIView, RetrieveAPIView):
def
perform_create
(
self
,
serializer
):
# Set the requesting user as the one who is updating the configuration
serializer
.
save
(
changed_by
=
self
.
request
.
user
)
serializer
.
save
(
changed_by
=
self
.
request
.
user
)
common/test/acceptance/fixtures/config.py
View file @
eaf6be2a
"""
Fixture to manipulate configuration models.
"""
import
requests
import
re
import
json
...
...
@@ -79,11 +82,11 @@ class ConfigModelFixture(object):
if
response
.
ok
:
# auto_auth returns information about the newly created user
# capture this so it can be used by by the testcases.
user_pattern
=
re
.
compile
(
'Logged in user {0}
\
({1}
\
) with password {2} and user_id {3}'
.
format
(
'(?P<username>
\
S+)'
,
'(?P<email>[^
\
)]+)'
,
'(?P<password>
\
S+)'
,
'(?P<user_id>
\
d+)'
))
user_pattern
=
re
.
compile
(
r
'Logged in user {0} \({1}\) with password {2} and user_id {3}'
.
format
(
r'(?P<username>\S+)'
,
r'(?P<email>[^\)]+)'
,
r'(?P<password>\S+)'
,
r
'(?P<user_id>\d+)'
))
user_matches
=
re
.
match
(
user_pattern
,
response
.
text
)
if
user_matches
:
self
.
user
=
user_matches
.
groupdict
()
self
.
user
=
user_matches
.
groupdict
()
# pylint: disable=attribute-defined-outside-init
return
session
...
...
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