Newer
Older
from django.conf import settings
from django.test import TestCase
from model_bakery import baker
from .main.models import Schedule
from .main.models import Invitation
class TestInvitationApiView(TestCase):
def setUp(self):
self.client.defaults['HTTP_AUTHORIZATION'] = 'token ' + settings.API_TOKEN
def test_get(self):
invitation = baker.make(Invitation)
url = '/api/{}/{}/'.format(invitation.schedule.uuid, invitation.token)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_put(self):
schedule = baker.make(Schedule)
url = '/api/{}/{}/'.format(schedule.uuid, 'sometoken')
response = self.client.put(url)
self.assertEqual(response.status_code, 204)
self.assertTrue(Invitation.objects.filter(token='sometoken').exists())
def test_delete(self):
invitation = baker.make(Invitation)
url = '/api/{}/{}/'.format(invitation.schedule.uuid, invitation.token)
response = self.client.delete(url)
self.assertEqual(response.status_code, 204)
self.assertFalse(Invitation.objects.filter(token=invitation.token).exists())