Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 8 additions & 27 deletions examples/django_example/django_example/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.test import TestCase
from django.urls import reverse


Copy link
Owner

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

class ApiTestCase(TestCase):

def setUp(self):
Expand All @@ -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.
"""
Copy link
Owner

Choose a reason for hiding this comment

The 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)
Expand All @@ -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'سلام'
Copy link
Owner

Choose a reason for hiding this comment

The 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 ✅
(Python 3 no longer needs the u bytemark, good to know)

'text': 'سلام' # Unicode string
}),
content_type='application/json',
format='json'
content_type='application/json'
)

self.assertEqual(response.status_code, 200)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Copy link
Owner

Choose a reason for hiding this comment

The 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)