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
6bc6b3f0
Commit
6bc6b3f0
authored
9 years ago
by
wajeeha-khalid
Browse files
Options
Downloads
Plain Diff
Merge pull request #10989 from edx/jia/MA-1046
MA-1046 added valid form field test
parents
a8a88390
08471834
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/discussion_api/tests/test_forms.py
+39
-4
39 additions, 4 deletions
lms/djangoapps/discussion_api/tests/test_forms.py
lms/djangoapps/discussion_api/tests/test_views.py
+33
-0
33 additions, 0 deletions
lms/djangoapps/discussion_api/tests/test_views.py
with
72 additions
and
4 deletions
lms/djangoapps/discussion_api/tests/test_forms.py
+
39
−
4
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.
"
)
This diff is collapsed.
Click to expand it.
lms/djangoapps/discussion_api/tests/test_views.py
+
33
−
0
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
'
)
...
...
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