aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking/tests
diff options
context:
space:
mode:
authorGergely Csatari <gergely.csatari@nokia.com>2023-10-26 10:33:28 +0300
committerGergely Csatari <gergely.csatari@nokia.com>2023-10-26 10:34:28 +0300
commit2ec0d7b9f5c1354977b821c6b06c24a3ffa13142 (patch)
tree6e449d92ddfc880ed007e9d8a8f25bda8fc7cb0f /src/booking/tests
parent0d3dd290aa6e7f39e7b0b3cbe448b6622f924240 (diff)
Removing project content and adding a noteHEADmaster
that the development continues in GitHub Change-Id: I25c58a679dbf92b2367d826429b7cda936bf9f0e Signed-off-by: Gergely Csatari <gergely.csatari@nokia.com>
Diffstat (limited to 'src/booking/tests')
-rw-r--r--src/booking/tests/__init__.py8
-rw-r--r--src/booking/tests/test_models.py210
-rw-r--r--src/booking/tests/test_quick_booking.py180
-rw-r--r--src/booking/tests/test_stats.py59
4 files changed, 0 insertions, 457 deletions
diff --git a/src/booking/tests/__init__.py b/src/booking/tests/__init__.py
deleted file mode 100644
index b6fef6c..0000000
--- a/src/booking/tests/__init__.py
+++ /dev/null
@@ -1,8 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
diff --git a/src/booking/tests/test_models.py b/src/booking/tests/test_models.py
deleted file mode 100644
index 37eb655..0000000
--- a/src/booking/tests/test_models.py
+++ /dev/null
@@ -1,210 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-from datetime import timedelta
-
-from django.contrib.auth.models import User
-from django.test import TestCase
-from django.utils import timezone
-
-from booking.models import Booking
-from dashboard.testing_utils import make_resource_template, make_user
-
-
-class BookingModelTestCase(TestCase):
- """
- Test the Booking model.
-
- Creates all the scafolding needed and tests the Booking model
- """
-
- def setUp(self):
- """
- Prepare for Booking model tests.
-
- Creates all the needed models, such as users, resources, and configurations
- """
- self.owner = User.objects.create(username='owner')
- self.res1 = make_resource_template(name="Test template 1")
- self.res2 = make_resource_template(name="Test template 2")
- self.user1 = make_user(username='user1')
-
- def test_start_end(self):
- """
- Verify the start and end fields.
-
- if the start of a booking is greater or equal then the end,
- saving should raise a ValueException
- """
- start = timezone.now()
- end = start - timedelta(weeks=1)
- self.assertRaises(
- ValueError,
- Booking.objects.create,
- start=start,
- end=end,
- resource=self.res1,
- owner=self.user1,
- )
- end = start
- self.assertRaises(
- ValueError,
- Booking.objects.create,
- start=start,
- end=end,
- resource=self.res1,
- owner=self.user1,
- )
-
- def test_conflicts(self):
- """
- Verify conflicting dates are dealt with.
-
- saving an overlapping booking on the same resource
- should raise a ValueException
- saving for different resources should succeed
- """
- start = timezone.now()
- end = start + timedelta(weeks=1)
- self.assertTrue(
- Booking.objects.create(
- start=start,
- end=end,
- owner=self.user1,
- resource=self.res1,
- )
- )
-
- self.assertRaises(
- ValueError,
- Booking.objects.create,
- start=start,
- end=end,
- resource=self.res1,
- owner=self.user1,
- )
-
- self.assertRaises(
- ValueError,
- Booking.objects.create,
- start=start + timedelta(days=1),
- end=end - timedelta(days=1),
- resource=self.res1,
- owner=self.user1,
- )
-
- self.assertRaises(
- ValueError,
- Booking.objects.create,
- start=start - timedelta(days=1),
- end=end,
- resource=self.res1,
- owner=self.user1,
- )
-
- self.assertRaises(
- ValueError,
- Booking.objects.create,
- start=start - timedelta(days=1),
- end=end - timedelta(days=1),
- resource=self.res1,
- owner=self.user1,
- )
-
- self.assertRaises(
- ValueError,
- Booking.objects.create,
- start=start,
- end=end + timedelta(days=1),
- resource=self.res1,
- owner=self.user1,
- )
-
- self.assertRaises(
- ValueError,
- Booking.objects.create,
- start=start + timedelta(days=1),
- end=end + timedelta(days=1),
- resource=self.res1,
- owner=self.user1,
- )
-
- self.assertTrue(
- Booking.objects.create(
- start=start - timedelta(days=1),
- end=start,
- owner=self.user1,
- resource=self.res1,
- )
- )
-
- self.assertTrue(
- Booking.objects.create(
- start=end,
- end=end + timedelta(days=1),
- owner=self.user1,
- resource=self.res1,
- )
- )
-
- self.assertTrue(
- Booking.objects.create(
- start=start - timedelta(days=2),
- end=start - timedelta(days=1),
- owner=self.user1,
- resource=self.res1,
- )
- )
-
- self.assertTrue(
- Booking.objects.create(
- start=end + timedelta(days=1),
- end=end + timedelta(days=2),
- owner=self.user1,
- resource=self.res1,
- )
- )
-
- self.assertTrue(
- Booking.objects.create(
- start=start,
- end=end,
- owner=self.user1,
- resource=self.res2,
- )
- )
-
- def test_extensions(self):
- """
- Test booking extensions.
-
- saving a booking with an extended end time is allows to happen twice,
- and each extension must be a maximum of one week long
- """
- start = timezone.now()
- end = start + timedelta(weeks=1)
- self.assertTrue(
- Booking.objects.create(
- start=start,
- end=end,
- owner=self.user1,
- resource=self.res1,
- )
- )
-
- booking = Booking.objects.all().first() # should be only thing in db
-
- self.assertEquals(booking.ext_count, 2)
- booking.end = booking.end + timedelta(days=3)
- try:
- booking.save()
- except Exception:
- self.fail("save() threw an exception")
diff --git a/src/booking/tests/test_quick_booking.py b/src/booking/tests/test_quick_booking.py
deleted file mode 100644
index f405047..0000000
--- a/src/booking/tests/test_quick_booking.py
+++ /dev/null
@@ -1,180 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import datetime
-import json
-
-from django.test import TestCase, Client
-
-from booking.models import Booking
-from dashboard.testing_utils import (
- make_user,
- make_user_profile,
- make_lab,
- make_image,
- make_os,
- make_opnfv_role,
- make_public_net,
- make_resource_template,
- make_server
-)
-
-
-class QuickBookingValidFormTestCase(TestCase):
- @classmethod
- def setUpTestData(cls):
- cls.user = make_user(False, username="newtestuser")
- cls.user.set_password("testpassword")
- cls.user.save()
- make_user_profile(cls.user, True)
-
- cls.lab = make_lab()
-
- cls.res_template = make_resource_template(owner=cls.user, lab=cls.lab)
- cls.res_profile = cls.res_template.getConfigs()[0].profile
- os = make_os()
- cls.image = make_image(cls.res_profile, lab=cls.lab, owner=cls.user, os=os)
- cls.server = make_server(cls.res_profile, cls.lab)
- cls.role = make_opnfv_role()
- cls.pubnet = make_public_net(10, cls.lab)
-
- cls.post_data = cls.build_post_data()
- cls.client = Client()
-
- @classmethod
- def build_post_data(cls):
- return {
- 'filter_field': json.dumps({
- "resource": {
- "resource_" + str(cls.res_profile.id): {
- "selected": True,
- "id": cls.res_template.id
- }
- },
- "lab": {
- "lab_" + str(cls.lab.lab_user.id): {
- "selected": True,
- "id": cls.lab.lab_user.id
- }
- }
- }),
- 'purpose': 'my_purpose',
- 'project': 'my_project',
- 'length': '3',
- 'ignore_this': 1,
- 'users': '',
- 'hostname': 'my_host',
- 'image': str(cls.image.id),
- }
-
- def post(self, changed_fields={}):
- payload = self.post_data.copy()
- payload.update(changed_fields)
- response = self.client.post('/booking/quick/', payload)
- return response
-
- def setUp(self):
- self.client.login(username="newtestuser", password="testpassword")
-
- def assertValidBooking(self, booking):
- self.assertEqual(booking.owner, self.user)
- self.assertEqual(booking.purpose, 'my_purpose')
- self.assertEqual(booking.project, 'my_project')
- delta = booking.end - booking.start
- delta -= datetime.timedelta(days=3)
- self.assertLess(delta, datetime.timedelta(minutes=1))
-
- resource_bundle = booking.resource
-
- host = resource_bundle.get_resources()[0]
- self.assertEqual(host.profile, self.res_profile)
- self.assertEqual(host.name, 'my_host')
-
- def test_with_too_long_length(self):
- response = self.post({'length': '22'})
-
- self.assertEqual(response.status_code, 200)
- self.assertIsNone(Booking.objects.first())
-
- def test_with_negative_length(self):
- response = self.post({'length': '-1'})
-
- self.assertEqual(response.status_code, 200)
- self.assertIsNone(Booking.objects.first())
-
- def test_with_invalid_installer(self):
- response = self.post({'installer': str(self.installer.id + 100)})
-
- self.assertEqual(response.status_code, 200)
- self.assertIsNone(Booking.objects.first())
-
- def test_with_invalid_scenario(self):
- response = self.post({'scenario': str(self.scenario.id + 100)})
-
- self.assertEqual(response.status_code, 200)
- self.assertIsNone(Booking.objects.first())
-
- def test_with_invalid_host_id(self):
- response = self.post({'filter_field': json.dumps({
- "resource": {
- "resource_" + str(self.res_profile.id + 100): {
- "selected": True,
- "id": self.res_profile.id + 100
- }
- },
- "lab": {
- "lab_" + str(self.lab.lab_user.id): {
- "selected": True,
- "id": self.lab.lab_user.id
- }
- }
- })})
-
- self.assertEqual(response.status_code, 200)
- self.assertIsNone(Booking.objects.first())
-
- def test_with_invalid_lab_id(self):
- response = self.post({'filter_field': json.dumps({
- "resource": {
- "resource_" + str(self.res_profile.id): {
- "selected": True,
- "id": self.res_profile.id
- }
- },
- "lab": {
- "lab_" + str(self.lab.lab_user.id + 100): {
- "selected": True,
- "id": self.lab.lab_user.id + 100
- }
- }
- })})
-
- self.assertEqual(response.status_code, 200)
- self.assertIsNone(Booking.objects.first())
-
- def test_with_invalid_empty_filter_field(self):
- response = self.post({'filter_field': ''})
-
- self.assertEqual(response.status_code, 200)
- self.assertIsNone(Booking.objects.first())
-
- def test_with_garbage_users_field(self): # expected behavior: treat as though field is empty if it has garbage data
- response = self.post({'users': ['X�]QP�槰DP�+m���h�U�_�yJA:.rDi��QN|.��C��n�P��F!��D�����5ȅj�9�LV��']}) # output from /dev/urandom
-
- self.assertEqual(response.status_code, 200)
- booking = Booking.objects.first()
- self.assertIsNone(booking)
-
- def test_with_valid_form(self):
- response = self.post()
-
- self.assertEqual(response.status_code, 302) # success should redirect
- booking = Booking.objects.first()
- self.assertIsNotNone(booking)
- self.assertValidBooking(booking)
diff --git a/src/booking/tests/test_stats.py b/src/booking/tests/test_stats.py
deleted file mode 100644
index 5501355..0000000
--- a/src/booking/tests/test_stats.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#############################################################################
-# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, Sean Smith, and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-import pytz
-from datetime import timedelta, datetime
-
-from django.test import TestCase
-
-from booking.models import Booking
-from booking.stats import StatisticsManager as sm
-from dashboard.testing_utils import make_user
-
-
-class StatsTestCases(TestCase):
-
- def test_no_booking_outside_span(self):
- now = datetime.now(pytz.utc)
-
- bad_date = now + timedelta(days=1200)
- Booking.objects.create(start=now, end=bad_date, owner=make_user(username='jj'))
-
- actual = sm.getContinuousBookingTimeSeries()
- dates = actual['booking'][0]
-
- for date in dates:
- self.assertNotEqual(date, bad_date)
-
- def check_booking_and_user_counts(self):
- now = datetime.now(pytz.utc)
-
- for i in range(20):
- Booking.objects.create(
- start=now,
- end=now + timedelta(weeks=3),
- owner=make_user(username='a'))
-
- for i in range(30):
- Booking.objects.create(
- start=now + timedelta(days=5),
- end=now + timedelta(weeks=3, days=5),
- owner=make_user(username='a'))
-
- for i in range(120):
- Booking.objects.create(
- start=now + timedelta(weeks=1),
- end=now + timedelta(weeks=4),
- owner=make_user(username='a'))
-
- dates = [[now, 20], [now + timedelta(days=5), 30], [now + timedelta(weeks=1), 120]]
- actual = sm.getContinuousBookingTimeSeries()
-
- for date in dates:
- self.assertEqual(date[1], actual['booking'][date[0]])
- self.assertEqual(date[1], actual['booking'][date[1]])