Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
4776ab15
Commit
4776ab15
authored
3 years ago
by
stvn
Browse files
Options
Downloads
Patches
Plain Diff
test: Add CourseFactory to discussions API tests
parent
d7a4947e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openedx/core/djangoapps/discussions/tests/test_views.py
+16
-22
16 additions, 22 deletions
openedx/core/djangoapps/discussions/tests/test_views.py
with
16 additions
and
22 deletions
openedx/core/djangoapps/discussions/tests/test_views.py
+
16
−
22
View file @
4776ab15
...
...
@@ -10,29 +10,32 @@ from opaque_keys.edx.keys import CourseKey
from
rest_framework
import
status
from
rest_framework.test
import
APITestCase
from
common.djangoapps.student.tests.factories
import
GlobalStaffFactory
from
common.djangoapps.student.tests.factories
import
StaffFactory
from
common.djangoapps.student.tests.factories
import
UserFactory
from
common.lib.xmodule.xmodule.modulestore.tests.django_utils
import
CourseUserType
from
common.lib.xmodule.xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore.tests.factories
import
CourseFactory
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'
lms.urls
'
,
'
URLs are only configured in LMS
'
)
class
ApiTest
(
APITestCase
):
class
ApiTest
(
ModuleStoreTestCase
,
APITestCase
):
"""
Test basic API operations
"""
CREATE_USER
=
True
USER_TYPE
=
None
def
setUp
(
self
):
super
().
setUp
()
self
.
course_key
=
CourseKey
.
from_string
(
'
course-v1:Test+Course+Configured
'
)
store
=
ModuleStoreEnum
.
Type
.
split
self
.
course
=
CourseFactory
.
create
(
default_store
=
store
)
self
.
url
=
reverse
(
'
discussions
'
,
kwargs
=
{
'
course_key_string
'
:
str
(
self
.
course
_key
),
'
course_key_string
'
:
str
(
self
.
course
.
id
),
}
)
self
.
password
=
'
password
'
self
.
user_student
=
UserFactory
(
username
=
'
dummy
'
,
password
=
self
.
password
)
self
.
user_staff_course
=
StaffFactory
(
course_key
=
self
.
course_key
,
password
=
self
.
password
)
self
.
user_staff_global
=
GlobalStaffFactory
(
password
=
self
.
password
)
if
self
.
USER_TYPE
:
self
.
user
=
self
.
create_user_for_course
(
self
.
course
,
user_type
=
self
.
USER_TYPE
)
class
UnauthorizedApiTest
(
ApiTest
):
...
...
@@ -65,13 +68,7 @@ class AuthenticatedApiTest(UnauthorizedApiTest):
"""
expected_response_code
=
status
.
HTTP_403_FORBIDDEN
def
setUp
(
self
):
super
().
setUp
()
self
.
_login
()
def
_login
(
self
):
self
.
client
.
login
(
username
=
self
.
user_student
.
username
,
password
=
self
.
password
)
USER_TYPE
=
CourseUserType
.
ENROLLED
class
AuthorizedApiTest
(
AuthenticatedApiTest
):
...
...
@@ -80,9 +77,7 @@ class AuthorizedApiTest(AuthenticatedApiTest):
"""
expected_response_code
=
status
.
HTTP_200_OK
def
_login
(
self
):
self
.
client
.
login
(
username
=
self
.
user_staff_global
.
username
,
password
=
self
.
password
)
USER_TYPE
=
CourseUserType
.
GLOBAL_STAFF
def
test_access_patch
(
self
):
response
=
self
.
client
.
patch
(
self
.
url
)
...
...
@@ -98,5 +93,4 @@ class CourseStaffAuthorizedTest(AuthorizedApiTest):
Course Staff should have the same access as Global Staff
"""
def
_login
(
self
):
self
.
client
.
login
(
username
=
self
.
user_staff_course
.
username
,
password
=
self
.
password
)
USER_TYPE
=
CourseUserType
.
UNENROLLED_STAFF
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment