Skip to content

Instantly share code, notes, and snippets.

@guilatrova
Last active October 21, 2017 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilatrova/5bd20c98104f7515cdd37b8e4fe3ea4b to your computer and use it in GitHub Desktop.
Save guilatrova/5bd20c98104f7515cdd37b8e4fe3ea4b to your computer and use it in GitHub Desktop.
Latrova Commits DRF Tests 1.4
def test_list_url_only_allows_get_and_post(self):
resolver = self.resolve_by_name('transactions')
self.assert_has_actions(['get', 'post'], resolver.func.actions)
def test_single_url_allows_all_methods_except_post(self):
"""All methods are: GET, PUT, PATCH and DELETE"""
resolver = self.resolve_by_name('transaction', pk=1)
self.assert_has_actions(['get', 'put', 'patch', 'delete'], resolver.func.actions)
def assert_has_actions(self, allowed, actions):
self.assertEqual(len(allowed), len(actions))
for allows in allowed:
self.assertIn(allows, actions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment