30 lines
944 B
Python
30 lines
944 B
Python
import json
|
|
|
|
from django.test import TestCase, Client
|
|
|
|
from core.factories import UserFactory
|
|
|
|
|
|
class ApiAccessTestCase(TestCase):
|
|
|
|
def setUp(self):
|
|
self.query = json.dumps({
|
|
'operationName': 'ModulesQuery',
|
|
'query': 'query ModulesQuery { modules { edges { node { id }}}}',
|
|
'variables': None,
|
|
})
|
|
|
|
def test_graphqlEndpoint_shouldNotBeAccessibleWithoutLogin(self):
|
|
c = Client()
|
|
response = c.post('/api/graphql/', data=self.query, content_type='application/json')
|
|
self.assertRedirects(response, '/accounts/login/?next=/api/graphql/')
|
|
|
|
def test_graphqlEndpoint_shouldBeAccessibleWithLogin(self):
|
|
user = UserFactory(username='admin')
|
|
|
|
c = Client()
|
|
c.login(username='admin', password='test')
|
|
response = c.post('/api/graphql/', data=self.query, content_type='application/json')
|
|
|
|
self.assertEqual(200, response.status_code)
|