-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix JSON format bug and duplicate test clean-up #2418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| from django.test import TestCase | ||
| from django.urls import reverse | ||
|
|
||
|
|
||
| class ApiTestCase(TestCase): | ||
|
|
||
| def setUp(self): | ||
|
|
@@ -13,27 +12,22 @@ def test_invalid_text(self): | |
| response = self.client.post( | ||
| self.api_url, | ||
| data=json.dumps({ | ||
| 'type': 'classmethod' | ||
| 'type': 'classmethod' # Missing 'text' field | ||
| }), | ||
| content_type='application/json', | ||
| format='json' | ||
| content_type='application/json' | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 400) | ||
| self.assertIn('text', response.json()) | ||
| self.assertEqual(['The attribute "text" is required.'], response.json()['text']) | ||
|
|
||
| def test_post(self): | ||
| """ | ||
| Test that a response is returned. | ||
| """ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the docstrings in these functions have been improved instead of removed? |
||
| response = self.client.post( | ||
| self.api_url, | ||
| data=json.dumps({ | ||
| 'text': 'How are you?' | ||
| }), | ||
| content_type='application/json', | ||
| format='json' | ||
| content_type='application/json' | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
|
|
@@ -42,16 +36,12 @@ def test_post(self): | |
| self.assertIn('in_response_to', response.json()) | ||
|
|
||
| def test_post_unicode(self): | ||
| """ | ||
| Test that a response is returned. | ||
| """ | ||
| response = self.client.post( | ||
| self.api_url, | ||
| data=json.dumps({ | ||
| 'text': u'سلام' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to look this one up, but this seems safe to remove ✅ |
||
| 'text': 'سلام' # Unicode string | ||
| }), | ||
| content_type='application/json', | ||
| format='json' | ||
| content_type='application/json' | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
|
|
@@ -60,16 +50,12 @@ def test_post_unicode(self): | |
| self.assertIn('in_response_to', response.json()) | ||
|
|
||
| def test_escaped_unicode_post(self): | ||
| """ | ||
| Test that unicode reponce | ||
| """ | ||
| response = self.client.post( | ||
| self.api_url, | ||
| data=json.dumps({ | ||
| 'text': '\u2013' | ||
| 'text': '\u2013' # Unicode escape | ||
| }), | ||
| content_type='application/json', | ||
| format=json | ||
| content_type='application/json' | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
|
|
@@ -86,8 +72,7 @@ def test_post_tags(self): | |
| response = self.client.post( | ||
| self.api_url, | ||
| data=json.dumps(post_data), | ||
| content_type='application/json', | ||
| format='json' | ||
| content_type='application/json' | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
|
|
@@ -98,20 +83,16 @@ def test_post_tags(self): | |
|
|
||
| def test_get(self): | ||
| response = self.client.get(self.api_url) | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| def test_patch(self): | ||
| response = self.client.patch(self.api_url) | ||
|
|
||
| self.assertEqual(response.status_code, 405) | ||
|
|
||
| def test_put(self): | ||
| response = self.client.put(self.api_url) | ||
|
|
||
| self.assertEqual(response.status_code, 405) | ||
|
|
||
| def test_delete(self): | ||
| response = self.client.delete(self.api_url) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A space between test calls and assertions is preferred. |
||
| self.assertEqual(response.status_code, 405) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two blank lines before a top level function is preferred to adhere to pep8:
https://peps.python.org/pep-0008/#blank-lines