Commit 7a3c9f15 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Rework the testcase classes

parent 09a95fe1
......@@ -3,13 +3,13 @@
import logging
from feudal.backend import models
from feudal.backend.tests import FeudalTest
from feudal.backend.models import deployments
from feudal.backend.tests import BaseTestCase
from feudal.backend.models import deployments
LOGGER = logging.getLogger(__name__)
class DeploymentTest(FeudalTest):
class DeploymentTest(BaseTestCase):
def tearDown(self):
deployments.Deployment.objects.all().delete()
......@@ -63,7 +63,6 @@ class DeploymentTest(FeudalTest):
self.assertEqual(deployment.state, deployments.NOT_DEPLOYED)
self.assertTrue(deployment.target_reached)
# service count: prior to delayed service
def deployment_run_delayed_service(self, deployment, vo, service_count):
self.check_new_deployment(deployment, service_count)
......@@ -131,4 +130,4 @@ class DeploymentTest(FeudalTest):
# a vo with two services loses one service *after* the user requested the deployment
def test_group_with_vanishing_service(self):
deployment = deployments.get_deployment(self.user, vo=self.group_two)
deployments.get_deployment(self.user, vo=self.group_two)
......@@ -3,12 +3,13 @@ import logging
from django.contrib.auth import authenticate
from feudal.backend import models, tests
from feudal.backend import models
from feudal.backend.tests import BaseTestCase
LOGGER = logging.getLogger(__name__)
class UserTest(tests.FeudalTest):
class UserTest(BaseTestCase):
def test_user_construction(self):
user = models.User.get_user(
......
# pylint: disable=line-too-long,invalid-name
import logging
import base64
from django.contrib.auth import authenticate
from django.test import Client, TestCase
......@@ -13,8 +12,8 @@ from feudal.backend.auth.v1.models.vo import Group, Entitlement
LOGGER = logging.getLogger(__name__)
class FeudalTest(TestCase):
client = None
# base test
class BaseTestCase(TestCase):
@classmethod
def setUpTestData(cls):
......@@ -108,8 +107,13 @@ class FeudalTest(TestCase):
user=cls.user,
).save()
# Tests that use the client must call this in setUp
def setup_client(self):
# the user is logged in using session authentication
class LoggedInTest(BaseTestCase):
client = None
def setUp(self):
self.client = Client()
user = authenticate(
username=self.USER_NAME,
......@@ -119,47 +123,3 @@ class FeudalTest(TestCase):
self.client.force_login(
user=user,
)
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()
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
import base64
from feudal.backend import tests
from django.test import TestCase, Client
from feudal.backend import models
LOGGER = logging.getLogger(__name__)
class ClientViewTest(tests.APIClientTest):
class ClientViewTest(TestCase):
client = None
@classmethod
def setUpTestData(cls):
cls.CLIENT_NAME = 'TEST_DOWNSTREAM_CLIENT'
cls.CLIENT_PASSWORD = 'test1234'
cls.api_client = models.User.construct_client(
cls.CLIENT_NAME,
cls.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()
def auth_headers(self):
auth_str = '{}:{}'.format(
self.CLIENT_NAME,
self.CLIENT_PASSWORD,
)
return {
'HTTP_AUTHORIZATION': 'Basic ' + base64.b64encode(auth_str.encode()).decode(),
}
def test_configuration_entitlement(self):
response = self.client.put(
......
import logging
from feudal.backend import models, tests
from feudal.backend import models
from feudal.backend.tests import LoggedInTest
from feudal.backend.models import deployments
LOGGER = logging.getLogger(__name__)
......@@ -13,7 +13,7 @@ def make_path(path, *args):
return '/user/'+p
class UserViewTest(tests.ClientFeudalTest):
class UserViewTest(LoggedInTest):
def test_user_deletion(self):
response = self.client.delete(
......@@ -23,7 +23,7 @@ class UserViewTest(tests.ClientFeudalTest):
self.assertEqual(response.status_code, 204)
class SSHPublicKeyViewTest(tests.ClientFeudalTest):
class SSHPublicKeyViewTest(LoggedInTest):
def test_list(self):
response = self.client.get(
......@@ -102,7 +102,7 @@ class SSHPublicKeyViewTest(tests.ClientFeudalTest):
self.assertEqual(response.status_code, 404)
class VORestTest(tests.ClientFeudalTest):
class VORestTest(LoggedInTest):
def test_vos(self):
response = self.client.get(
......@@ -112,7 +112,7 @@ class VORestTest(tests.ClientFeudalTest):
self.assertEqual(response.status_code, 200)
class DeploymentsViewTest(tests.ClientFeudalTest):
class DeploymentsViewTest(LoggedInTest):
def test_service_deployment(self):
service = self.service_one
......@@ -181,7 +181,7 @@ class DeploymentsViewTest(tests.ClientFeudalTest):
)
class DeploymentStateViewTest(tests.ClientFeudalTest):
class DeploymentStateViewTest(LoggedInTest):
def test_questionnaire_answers(self):
service = self.service_one
......
import logging
from feudal.backend import tests
from feudal.backend.tests import LoggedInTest
LOGGER = logging.getLogger(__name__)
class StateViewTest(tests.ClientFeudalTest):
class StateViewTest(LoggedInTest):
def test_api_state(self):
response = self.client.get('/webpage/state')
......
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