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
6bc6b3f0
Commit
6bc6b3f0
authored
Dec 16, 2015
by
wajeeha-khalid
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10989 from edx/jia/MA-1046
MA-1046 added valid form field test
parents
a8a88390
08471834
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
4 deletions
+72
-4
lms/djangoapps/discussion_api/tests/test_forms.py
+39
-4
lms/djangoapps/discussion_api/tests/test_views.py
+33
-0
No files found.
lms/djangoapps/discussion_api/tests/test_forms.py
View file @
6bc6b3f0
...
...
@@ -100,14 +100,20 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase):
self
.
form_data
.
setlist
(
"topic_id"
,
[
""
,
"not empty"
])
self
.
assert_error
(
"topic_id"
,
"This field cannot be empty."
)
def
test_following_true
(
self
):
self
.
form_data
[
"following"
]
=
"True"
@ddt.data
(
"True"
,
"true"
,
1
,
True
)
def
test_following_true
(
self
,
value
):
self
.
form_data
[
"following"
]
=
value
self
.
assert_field_value
(
"following"
,
True
)
def
test_following_false
(
self
):
self
.
form_data
[
"following"
]
=
"False"
@ddt.data
(
"False"
,
"false"
,
0
,
False
)
def
test_following_false
(
self
,
value
):
self
.
form_data
[
"following"
]
=
value
self
.
assert_error
(
"following"
,
"The value of the 'following' parameter must be true."
)
def
test_invalid_following
(
self
):
self
.
form_data
[
"following"
]
=
"invalid-boolean"
self
.
assert_error
(
"following"
,
"Invalid Boolean Value."
)
@ddt.data
(
*
itertools
.
combinations
([
"topic_id"
,
"text_search"
,
"following"
],
2
))
def
test_mutually_exclusive
(
self
,
params
):
self
.
form_data
.
update
({
param
:
"True"
for
param
in
params
})
...
...
@@ -134,7 +140,22 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase):
"Select a valid choice. not_a_valid_choice is not one of the available choices."
)
@ddt.data
(
(
"view"
,
"unread"
),
(
"view"
,
"unanswered"
),
(
"order_by"
,
"last_activity_at"
),
(
"order_by"
,
"comment_count"
),
(
"order_by"
,
"vote_count"
),
(
"order_direction"
,
"asc"
),
(
"order_direction"
,
"desc"
),
)
@ddt.unpack
def
test_valid_choice_fields
(
self
,
field
,
value
):
self
.
form_data
[
field
]
=
value
self
.
assert_field_value
(
field
,
value
)
@ddt.ddt
class
CommentListGetFormTest
(
FormTestMixin
,
PaginationTestMixin
,
TestCase
):
"""Tests for CommentListGetForm"""
FORM_CLASS
=
CommentListGetForm
...
...
@@ -167,3 +188,17 @@ class CommentListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase):
def
test_missing_endorsed
(
self
):
self
.
form_data
.
pop
(
"endorsed"
)
self
.
assert_field_value
(
"endorsed"
,
None
)
@ddt.data
(
"True"
,
"true"
,
True
,
1
)
def
test_endorsed_true
(
self
,
value
):
self
.
form_data
[
"endorsed"
]
=
value
self
.
assert_field_value
(
"endorsed"
,
True
)
@ddt.data
(
"False"
,
"false"
,
False
,
0
)
def
test_endorsed_false
(
self
,
value
):
self
.
form_data
[
"endorsed"
]
=
value
self
.
assert_field_value
(
"endorsed"
,
False
)
def
test_invalid_endorsed
(
self
):
self
.
form_data
[
"endorsed"
]
=
"invalid-boolean"
self
.
assert_error
(
"endorsed"
,
"Invalid Boolean Value."
)
lms/djangoapps/discussion_api/tests/test_views.py
View file @
6bc6b3f0
...
...
@@ -1014,6 +1014,39 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
parsed_content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
parsed_content
[
"results"
][
0
][
"id"
],
comment_id
)
def
test_question_invalid_endorsed
(
self
):
response
=
self
.
client
.
get
(
self
.
url
,
{
"thread_id"
:
self
.
thread_id
,
"endorsed"
:
"invalid-boolean"
})
self
.
assert_response_correct
(
response
,
400
,
{
"field_errors"
:
{
"endorsed"
:
{
"developer_message"
:
"Invalid Boolean Value."
}
}}
)
def
test_question_missing_endorsed
(
self
):
self
.
register_get_user_response
(
self
.
user
)
thread
=
self
.
make_minimal_cs_thread
({
"thread_type"
:
"question"
,
"endorsed_responses"
:
[
make_minimal_cs_comment
({
"id"
:
"endorsed_comment"
})],
"non_endorsed_responses"
:
[
make_minimal_cs_comment
({
"id"
:
"non_endorsed_comment"
})],
"non_endorsed_resp_total"
:
1
,
})
self
.
register_get_thread_response
(
thread
)
response
=
self
.
client
.
get
(
self
.
url
,
{
"thread_id"
:
thread
[
"id"
]
})
self
.
assert_response_correct
(
response
,
400
,
{
"field_errors"
:
{
"endorsed"
:
{
"developer_message"
:
"This field is required for question threads."
}
}}
)
@httpretty.activate
@disable_signal
(
api
,
'comment_deleted'
)
...
...
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