diff --git a/accounts/tests.py b/accounts/tests.py index 90bc85f955e26dd157bde8ab664e27f354746573..487bc0b054d39997d13b8704390e5b048ce05f22 100644 --- a/accounts/tests.py +++ b/accounts/tests.py @@ -30,11 +30,11 @@ class AddAccountTests(TestCase): # NOT NULL contraint failed: accounts_account.balance # Test: create a new account # Expected result: new account created with unique id - # def testAccountCreated(self): - # self.client.login(username="test", password="test") - # response = self.client.post(reverse('create_account'), {'discount_rate': 2.00}) - # self.assertEqual(response.status_code, 200) - # print(response.context) + def testAccountCreated(self): + self.client.login(username="test", password="test") + response = self.client.post(reverse('create_account'), {'discount_rate': 2.00}) + self.assertEqual(response.status_code, 200) + print(response.context) # Test: update an existing account # Expected result: account's discount rate is changed @@ -70,11 +70,11 @@ class AddAccountTests(TestCase): # DOES NOT CURRENTLY PASS # Test: update an existing statement # Expected result: statement details are altered - # def testStatementUpdated(self): - # response = self.client.post(reverse('update_statement', args=[2,1]), {'date': datetime.date.today, 'total_spent': 1.00, 'total_paid': 1.00, 'outstanding': 0.00}) - # self.assertEqual(response.status_code, 200) - # self.assertEqual(len(EndOfMonthStatement.objects.filter(outstanding=0.00)), 1) - # self.assertEqual(len(EndOfMonthStatement.objects.filter(outstanding=0.5)), 0) + def testStatementUpdated(self): + response = self.client.post(reverse('update_statement', args=[2,1]), {'date': datetime.date.today, 'total_spent': 1.00, 'total_paid': 1.00, 'outstanding': 0.00}) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(EndOfMonthStatement.objects.filter(outstanding=0.00)), 1) + self.assertEqual(len(EndOfMonthStatement.objects.filter(outstanding=0.5)), 0) # Test: delete a statement # Expected result: no statements found @@ -86,19 +86,19 @@ class AddAccountTests(TestCase): # CURRENTLY DOES NOT WORK: paymentConfirm is not a valid url # Test: top up an account's balance # Expected result: the account's balance is increased by 10 - # def testTopUpBalance(self): - # #self.client.login(username="test", password="test") - # acc = Account.objects.get(id=1) - # response = self.client.post(reverse('top_up_balance', args=[1]), {'amount':10.00, 'cardNumber':'1234567812345678', 'expiryMonth': 12, 'expiry_year': 3000, 'cvc': '123', 'cardHolderName': 'Mr Test'}) - # self.assertEqual(acc.balance, 30) + def testTopUpBalance(self): + #self.client.login(username="test", password="test") + acc = Account.objects.get(id=1) + response = self.client.post(reverse('top_up_balance', args=[1]), {'amount':10.00, 'cardNumber':'1234567812345678', 'expiryMonth': 12, 'expiry_year': 3000, 'cvc': '123', 'cardHolderName': 'Mr Test'}) + self.assertEqual(acc.balance, 30) # AttributeError: 'Settings' object has no attribute 'USER_AUTH_MODEL' # Test: create a student discount request # Expected result: new student discount request object is created - # def testStudentDiscountRequestCreated(self): - # acc = Account.objects.get(id=1) - # request = self.client.post(reverse('create_student_discount_request', args=[1]), {'new_discount_rate': 5.0, 'reason': 'Test'}) - # self.assertEqual(len(StudentDiscountRequest.objects.filter()), 2) + def testStudentDiscountRequestCreated(self): + acc = Account.objects.get(id=1) + request = self.client.post(reverse('create_student_discount_request', args=[1]), {'new_discount_rate': 5.0, 'reason': 'Test'}) + self.assertEqual(len(StudentDiscountRequest.objects.filter()), 2) # Test: approve a student discount request # Expected result: request is approved and deleted, user's discount rate is changed diff --git a/authentication/tests.py b/authentication/tests.py index 1f2df9d23596085daf9eaef7a141112da05b561d..36597f21b84e7f261eb1b35b81e8532c14ac8725 100644 --- a/authentication/tests.py +++ b/authentication/tests.py @@ -41,11 +41,11 @@ class AddAuthenticationTests(TestCase): # print(response.context) # #ERROR: doesn't successfully create a user -# def testRegistration(self): -# form = UserRegistrationForm(data={"email": "test@example.com", "username": "test1", "first_name": "Jim", "last_name": "Johnson", "date_of_birth": datetime.datetime(1999, 7, 13), "password1": "test", "password2": "test"}) -# response = self.client.post("/register/", form=form) -# self.assertEqual(response.status_code, HTTPStatus.OK) -# self.assertEqual(User.objects.get(email="test@example.com").exists(),True) + def testRegistration(self): + form = UserRegistrationForm(data={"email": "test@example.com", "username": "test1", "first_name": "Jim", "last_name": "Johnson", "date_of_birth": datetime.datetime(1999, 7, 13), "password1": "test", "password2": "test"}) + response = self.client.post("/register/", form=form) + self.assertEqual(response.status_code, HTTPStatus.OK) + self.assertEqual(User.objects.get(email="test@example.com").exists(),True) # Test: login with a club rep account # Expected result: client successfully logs in @@ -66,8 +66,8 @@ class AddAuthenticationTests(TestCase): self.assertTrue(False) # #ERROR: view didn't return an HttpResponse object - # def testUserElevation(self): - # self.client.login(username="test", password="test") - # response = self.client.post(reverse('elevate_user'), {"user": "test", "group": "admin"}) - # user = User.objects.get(username="test") - # print(user.groups) + def testUserElevation(self): + self.client.login(username="test", password="test") + response = self.client.post(reverse('elevate_user'), {"user": "test", "group": "admin"}) + user = User.objects.get(username="test") + print(user.groups) diff --git a/cinema/tests.py b/cinema/tests.py index daa54f5a64b70c15b8c066aec1958ddc47844110..ea618e1c93323877400167e87dc69ec1fc0227e7 100644 --- a/cinema/tests.py +++ b/cinema/tests.py @@ -110,11 +110,11 @@ class AddCinemaTests(TestCase): # CURRENTLY DOESN'T WORK (because update_film isn't fully implemented) # Test: update an existing film # Expected result: film's title is changed - # def testFilmUpdated(self): - # response = self.client.post(reverse('update_film', args=[1]), {'title': 'Film2', 'length': 120, 'rating': "12", "genre": "Comedy"}) - # self.assertEqual(response.status_code, 302) - # print(response.context) - # print(Film.objects.get(id=1).title) + def testFilmUpdated(self): + response = self.client.post(reverse('update_film', args=[1]), {'title': 'Film2', 'length': 120, 'rating': "12", "genre": "Comedy"}) + self.assertEqual(response.status_code, 302) + print(response.context) + print(Film.objects.get(id=1).title) # Test: view the list of showings for a film # Expected result: three showing objects found @@ -142,14 +142,14 @@ class AddCinemaTests(TestCase): # check is update_showing even works # Test: update an existing showing # Expected result: showing's time is changed - # def testShowingUpdated(self): - # self.client.login(username="test", password="test") - # tz = timezone.get_current_timezone() - # newtime = datetime.datetime(2023, 12, 1, 12, 45, 0, tzinfo=tz) - # response = self.client.post(reverse('update_showing', args=[1]), {'screen':Screen.objects.get(screen_number=1).id, 'film':Film.objects.get(title="Film1").id, 'start_time':"0023-04-24 16:44:00", 'social_distancing': False}) - # self.assertEqual(response.status_code, 302) - # print(response) - # self.assertEqual(Showing.objects.get(id=1).start_time, newtime) + def testShowingUpdated(self): + self.client.login(username="test", password="test") + tz = timezone.get_current_timezone() + newtime = datetime.datetime(2023, 12, 1, 12, 45, 0, tzinfo=tz) + response = self.client.post(reverse('update_showing', args=[1]), {'screen':Screen.objects.get(screen_number=1).id, 'film':Film.objects.get(title="Film1").id, 'start_time':"0023-04-24 16:44:00", 'social_distancing': False}) + self.assertEqual(response.status_code, 302) + print(response) + self.assertEqual(Showing.objects.get(id=1).start_time, newtime) # Test: view the list of users # Expected result: three user objects found