1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Refactored the tests to remove a lot of boilerplate

This commit is contained in:
Jeremy Stretch
2018-08-03 11:39:26 -04:00
parent 1bdfcd1dbe
commit bd5e860be0
10 changed files with 153 additions and 279 deletions

View File

@@ -1,11 +1,25 @@
from __future__ import unicode_literals
from django.contrib.auth.models import User
from rest_framework.test import APITestCase as _APITestCase
from users.models import Token
class APITestCase(_APITestCase):
def setUp(self):
"""
Create a superuser and token for API calls.
"""
self.user = User.objects.create(username='testuser', is_superuser=True)
self.token = Token.objects.create(user=self.user)
self.header = {'HTTP_AUTHORIZATION': 'Token {}'.format(self.token.key)}
class HttpStatusMixin(object):
"""
Custom mixin to provide more detail in the event of an unexpected HTTP response.
"""
def assertHttpStatus(self, response, expected_status):
"""
Provide more detail in the event of an unexpected HTTP response.
"""
err_message = "Expected HTTP status {}; received {}: {}"
self.assertEqual(response.status_code, expected_status, err_message.format(
expected_status, response.status_code, response.data