Commit dd5fb06b authored by Bengfort's avatar Bengfort
Browse files

add api tests

parent 65b7ca16
Pipeline #9034 passed with stages
in 2 minutes and 47 seconds
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.id, 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.id, '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.id, invitation.token)
response = self.client.delete(url)
self.assertEqual(response.status_code, 204)
self.assertFalse(Invitation.objects.filter(token=invitation.token).exists())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment