Skip to content

Instantly share code, notes, and snippets.

@CryceTruly
Last active February 14, 2019 13:11
Show Gist options
  • Save CryceTruly/128da5494e62cdd419548242ab02291e to your computer and use it in GitHub Desktop.
Save CryceTruly/128da5494e62cdd419548242ab02291e to your computer and use it in GitHub Desktop.
Simple DJANGO rest api test
import json
from rest_framework.test import APIClient
class TestClass():
def setUp():
self.client = APIClient()
self.register_url=reverse('authentication:register')
def test_create_user(self):
"""Tests if a user can create an account"""
valid_register_data = {
'user': {
'email': '[email protected]',
'username': 'aquaman',
'password': 'testpass!XY'
}
response = self.client.post(self.register_url,
data=json.dumps(
valid_register_data),
content_type='application/json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
@CryceTruly
Copy link
Author

The test above uses API client built into django's restframework to test if a user can create an account successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment