Commit 613b2c56 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add tests for the client API

parent 111ad149
# pylint: disable=line-too-long,invalid-name
import logging
import base64
from django.contrib.auth import authenticate
from django.test import Client, TestCase
......@@ -122,7 +123,52 @@ class FeudalTest(TestCase):
class ClientFeudalTest(FeudalTest):
client = None
def setUp(self):
self.setup_client()
class APIClientTest(TestCase):
client = None
@classmethod
def setUpTestData(cls):
cls.API_CLIENT_NAME = 'TEST_API_CLIENT'
cls.API_CLIENT_PASSWORD = 'test1234'
cls.api_client = models.User.construct_client(
cls.API_CLIENT_NAME,
cls.API_CLIENT_PASSWORD,
)
cls.api_client.save()
cls.SITE_NAME = 'TEST_SITE'
cls.site = models.Site(
client=cls.api_client,
name=cls.SITE_NAME,
)
cls.site.save()
def setupUp(self):
self.client = Client()
logged_in_client = authenticate(
username=self.API_CLIENT_NAME,
password=self.API_CLIENT_PASSWORD,
)
self.assertIsNotNone(logged_in_client)
self.client.force_login(
user=logged_in_client,
)
def auth_headers(self):
auth_str = '{}:{}'.format(
self.API_CLIENT_NAME,
self.API_CLIENT_PASSWORD,
)
return {
'HTTP_AUTHORIZATION': 'Basic ' + base64.b64encode( auth_str.encode()).decode(),
}
import logging
from feudal.backend import tests
LOGGER = logging.getLogger(__name__)
class ConfigurationViewTest(tests.APIClientTest):
def test_configuration_entitlement(self):
response = self.client.put(
'/backend/clientapi/config',
{
"services": {
"CVMFS": {
"name": "CERN VM FS",
"command": "xxxxxxxxxxxx",
"description": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
},
"entitlement_to_service_ids": {
"urn:geant:h-df.de:group:myExampleColab#unity.helmholtz-data-federation.de": [
"CVMFS"
]
}
},
content_type='application/json',
**self.auth_headers(),
)
LOGGER.debug('response: %s', response)
LOGGER.debug('response json: %s', response.json())
self.assertEqual(response.status_code, 200)
def test_configuration_group(self):
response = self.client.put(
'/backend/clientapi/config',
{
"services": {
"CVMFS": {
"name": "CERN VM FS",
"command": "xxxxxxxxxxxx",
"description": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
},
"group_to_service_ids": {
"/foobar": [
"CVMFS"
]
}
},
content_type='application/json',
**self.auth_headers(),
)
LOGGER.debug('response: %s', response)
LOGGER.debug('response json: %s', response.json())
self.assertEqual(response.status_code, 200)
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