Source code for intranet.apps.parking.tests

from django.conf import settings
from django.contrib.auth import get_user_model
from django.urls import reverse

from ...test.ion_test import IonTestCase
from .models import CarApplication, ParkingApplication


[docs]class ParkingTest(IonTestCase): """Tests for the parking module."""
[docs] def login_with_args(self, uname, grad_year): user = get_user_model().objects.get_or_create(username=uname, graduation_year=grad_year)[0] with self.settings(MASTER_PASSWORD="pbkdf2_sha256$24000$qp64pooaIEAc$j5wiTlyYzcMu08dVaMRus8Kyfvn5ZfaJ/Rn+Z/fH2Bw="): self.client.login(username=uname, password="dankmemes") return user
[docs] def test_parking_form_junior(self): user = self.login_with_args("awilliam", settings.SENIOR_GRADUATION_YEAR + 1) response = self.client.post(reverse("parking_form"), data={"email": user.tj_email, "mentorship": False}) self.assertEqual(response.status_code, 302) # Check that a parking application was created parking_apps = ParkingApplication.objects.filter(user=user) self.assertTrue(parking_apps.exists()) self.assertEqual(parking_apps.count(), 1) response = self.client.post(reverse("parking_car"), data={"license_plate": "TJCSL", "make": "Lamborghini", "model": "Veneno", "year": 2018}) self.assertEqual(response.status_code, 302) # Check that a parking application was created car_apps = CarApplication.objects.filter(user=user) self.assertTrue(car_apps.exists()) self.assertEqual(car_apps.count(), 1) # Check for association with parking form parking_apps = ParkingApplication.objects.filter(user=user) self.assertTrue(parking_apps[0].cars.count(), 1)
[docs] def test_invalid_user(self): user = self.login_with_args("bwilliam", settings.SENIOR_GRADUATION_YEAR + 2) response = self.client.post(reverse("parking_form"), data={"email": user.tj_email, "mentorship": False}) # Check that parking application was not created self.assertEqual(response.status_code, 302) self.assertFalse(ParkingApplication.objects.filter(user=user).exists()) response = self.client.post(reverse("parking_car"), data={"license_plate": "TJCSL", "make": "Lamborghini", "model": "Veneno", "year": "2018"}) # Check that car application is not created self.assertEqual(response.status_code, 302) self.assertFalse(ParkingApplication.objects.filter(user=user).exists())