Skip to content

Instantly share code, notes, and snippets.

@luiscberrocal
Created January 23, 2019 16:38
Show Gist options
  • Save luiscberrocal/ad8e1e625e3e26ea20e928101dc274e2 to your computer and use it in GitHub Desktop.
Save luiscberrocal/ad8e1e625e3e26ea20e928101dc274e2 to your computer and use it in GitHub Desktop.
Test CRUD API Views
class Test$MODEL$ListAPIView(JWTTestMixin, TestCase):
def test_get(self):
$MODEL$Factory.create_batch(10)
url = reverse('$URL_NAMESPACE$:list-$MODEL_LOWER$')
user = UserFactory.create()
response = self.get_with_token(url, user)
self.response_200(response)
$MODEL_LOWER$_data = response.data
write_assertions($MODEL_LOWER$_data, '$MODEL_LOWER$_data')
#self.fail('Not Implmented')
class Test$MODEL$DetailAPIView(JWTTestMixin, TestCase):
def test_get(self):
$MODEL_LOWER$ = $MODEL$Factory.create()
url = reverse('$URL_NAMESPACE$:list-$MODEL_LOWER$', kwargs={'pk': $MODEL_LOWER$.pk})
user = UserFactory.create()
response = self.get_with_token(url, user)
self.response_200(response)
$MODEL_LOWER$_data = response.data
write_assertions($MODEL_LOWER$_data, '$MODEL_LOWER$_data')
def test_put(self):
$MODEL_LOWER$ = $MODEL$Factory.create()
url = reverse('$URL_NAMESPACE$:update-$MODEL_LOWER$', kwargs={'pk': $MODEL_LOWER$.pk})
user = UserFactory.create()
$MODEL_LOWER$_data = model_to_dict($MODEL_LOWER$)
$MODEL_LOWER$_data[''] = '' #FIXME Change something
response = self.put_with_token(url, user, data=$MODEL_LOWER$_data)
self.response_200(response)
$MODEL_LOWER$_api_data = response.data
#write_assertions($MODEL_LOWER$_api_data, '$MODEL_LOWER$_api_data')
self.assertEqual($MODEL_LOWER$_api_data[''], '') #FIXME Compare the data that changed
def test_delete(self):
$MODEL_LOWER$ = $MODEL$Factory.create()
url = reverse('$URL_NAMESPACE$:delete-$MODEL_LOWER$', kwargs={'pk': $MODEL_LOWER$.pk})
user = UserFactory.create()
response = self.put_with_token(url, user)
self.response_204(response)
self.assertEqual($MODEL$.objects.count(), 0)
class Test$MODEL$CreateAPIView(JWTTestMixin, TestCase):
def test_post(self):
self.fail('Not Implemented')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment