def test_active_user_can_see_pin(self): user = UserFactory() user.is_active = True user.save() self.client.login(username=user.email, password='******', follow=True) response = self.client.get(self.update_url) self.assertNotEqual(response.context_data['pin'], None)
def test_deactivated_user_has_None_pin(self): user = UserFactory() user.is_active = True user.save() self.assertNotEqual(user.pin, None) user.is_active = False user.save() self.assertEqual(user.pin, None)
def test_active_user_can_change_his_password_with_generated_link(self): new_pw = "testtest" # Request password reset self.client.post(self.reset_url, data={'email': self.active_user.email}, follow=True) # Get generated link from the email link = re.findall(r'(http://\S+)', mail.outbox[0].body)[0] # Access generated link and submit new password data = {'new_password1': new_pw, 'new_password2': new_pw} response = self.client.post(link, data, follow=True) self.assertRedirects(response, expected_url=reverse('homepage'), status_code=http_client.FOUND, target_status_code=http_client.OK) self.assertEqual( 'Your password has been set. You may go ahead and log in now.', list(response.context['messages'])[0].message) # Check if user can login with the new password login_data = {'username': self.active_user.email, 'password': new_pw} response = self.client.post(UserFactory.get_login_url(), login_data) self.assertRedirects(response, expected_url=reverse('homepage'), status_code=http_client.FOUND, target_status_code=http_client.OK)
def test_anon_user_cannot_post_reservation(self): start, end = self.get_valid_datetime(12, 5) res_d = {'start': start, 'end': end, 'field': 'A'} response = self.client.post(self.reservation_url, res_d, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.assertEqual(len(Reservation.objects.all()), 0, _("Anonymous user can make a valid reservation")) self.assertRedirects( response, expected_url=UserFactory.get_login_url(next='/reservation/add/'))
def test_anonymous_user_cannot_access_confirmation_page(self): self.reservation.paid = True self.reservation.save() start = self.reservation.start + timedelta(hours=1) end = self.reservation.end + timedelta(hours=1) data = { 'start': start.strftime('%Y-%m-%d %H'), 'end': end.strftime('%Y-%m-%d %H'), 'field': self.reservation.field.id } response = self.client.post(self.detail_url + 'confirm/', data) self.assertRedirects(response, UserFactory.get_login_url( next='/reservation/update/%s/confirm/' % self.reservation.id))
def setUp(self): self.user = UserFactory(is_active=True) self.field = FieldFactory() self.login_data = { 'username': self.user.email, 'password': '******' } self.reservation_url = ReservationFactory.get_reservation_url() self.remove_url = ReservationFactory.get_remove_url() self.remove_all_url = ReservationFactory.get_remove_all_url() self.payment_url = ReservationFactory.get_reservation_list_url() self.all_reservations_url = ReservationFactory.get_all_reservations_url( ) self.reservation_list_url = ReservationFactory.get_reservation_list_url( )
def test_anonymous_user_cannot_access_confirmation_page(self): self.reservation.paid = True self.reservation.save() start = self.reservation.start + timedelta(hours=1) end = self.reservation.end + timedelta(hours=1) data = { 'start': start.strftime('%Y-%m-%d %H'), 'end': end.strftime('%Y-%m-%d %H'), 'field': self.reservation.field.id } response = self.client.post(self.detail_url + 'confirm/', data) self.assertRedirects( response, UserFactory.get_login_url(next='/reservation/update/%s/confirm/' % self.reservation.id))
def test_active_user_can_change_his_password_with_generated_link(self): new_pw = "testtest" # Request password reset self.client.post(self.reset_url, data={'email': self.active_user.email}, follow=True) # Get generated link from the email link = re.findall(r'(http://\S+)', mail.outbox[0].body)[0] # Access generated link and submit new password data = {'new_password1': new_pw, 'new_password2': new_pw} response = self.client.post(link, data, follow=True) self.assertRedirects(response, expected_url=reverse('homepage'), status_code=http_client.FOUND, target_status_code=http_client.OK) self.assertEqual('Your password has been set. You may go ahead and log in now.', list(response.context['messages'])[0].message) # Check if user can login with the new password login_data = {'username': self.active_user.email, 'password': new_pw} response = self.client.post(UserFactory.get_login_url(), login_data) self.assertRedirects(response, expected_url=reverse('homepage'), status_code=http_client.FOUND, target_status_code=http_client.OK)
def test_anonymous_user_cannot_access_history_page(self): response = self.client.get(self.history_url) self.assertRedirects( response, UserFactory.get_login_url(next='/reservation/history/'))
def setUp(self): self.disabled_user = UserFactory() self.active_user = UserFactory(is_active=True) self.reset_url = UserFactory.get_password_reset_url() mail.outbox = []
def setUp(self): self.user = UserFactory(is_active=True) self.balance_url = UserFactory.get_update_balance_url()
def test_anonymous_user_cannot_access_budget_payment_page(self): response = self.client.get(self.budget_url) self.assertRedirects(response, UserFactory.get_login_url(next='/reservation/payment/budget/'))
class BudgetPaymentTest(TransactionTestCase): def setUp(self): self.user = UserFactory(is_active=True) self.budget_url = factories.PaymentFactory.get_budget_payment_url() self.list_url = factories.ReservationFactory.get_reservation_list_url() def test_anonymous_user_cannot_access_budget_payment_page(self): response = self.client.get(self.budget_url) self.assertRedirects(response, UserFactory.get_login_url(next='/reservation/payment/budget/')) def test_user_cannot_access_budget_page_without_staged_payment(self): self.client.login(username=self.user.email, password='******') response = self.client.get(self.budget_url) self.assertEqual(response.status_code, client.FORBIDDEN) def test_user_can_access_budget_page_with_staged_payment(self): self.client.login(username=self.user.email, password='******') reservation = factories.ReservationFactory(user=self.user) payment = factories.PaymentFactory(user=self.user, type=models.Payment.STAGED) payment.reservation_set.add(reservation) response = self.client.get(self.budget_url) self.assertEqual(response.status_code, client.OK) def test_user_cannot_pay_with_budget_with_invalid_password(self): self.client.login(username=self.user.email, password='******') reservation = factories.ReservationFactory(user=self.user) payment = factories.PaymentFactory(user=self.user, type=models.Payment.STAGED) payment.reservation_set.add(reservation) response = self.client.post(self.budget_url, {'password': '******'}) self.assertEqual(response.status_code, client.OK) staged_payment = models.Payment.objects.filter(user=self.user, type=models.Payment.BUDGET) self.assertFalse(staged_payment.exists()) def test_user_cannot_pay_with_budget_with_not_enough_money(self): self.client.login(username=self.user.email, password='******') factories.ReservationFactory.create_batch(3, user=self.user) response = self.client.get(self.list_url) self.assertEqual(response.status_code, client.OK) response = self.client.post(self.budget_url, {'password': '******'}) self.assertRedirects(response, '/reservation/list/') def test_user_can_pay_with_budget_with_enough_money(self): self.client.login(username=self.user.email, password='******') reservations = factories.ReservationFactory.create_batch(3, user=self.user) amount = sum(reservation.price for reservation in reservations) self.user.budget = amount self.user.save() response = self.client.get(self.list_url) self.assertEqual(response.status_code, client.OK) response = self.client.post(self.budget_url, {'password': '******'}) self.assertRedirects(response, '/') self.assertEqual(user_models.User.objects.get(id=self.user.id).budget, 0) staged_payment = models.Payment.objects.filter(user=self.user, type=models.Payment.BUDGET) self.assertTrue(staged_payment.exists())
def setUp(self): self.user = UserFactory(is_active=True) self.budget_url = factories.PaymentFactory.get_budget_payment_url() self.list_url = factories.ReservationFactory.get_reservation_list_url()
class BudgetPaymentTest(TransactionTestCase): def setUp(self): self.user = UserFactory(is_active=True) self.budget_url = factories.PaymentFactory.get_budget_payment_url() self.list_url = factories.ReservationFactory.get_reservation_list_url() def test_anonymous_user_cannot_access_budget_payment_page(self): response = self.client.get(self.budget_url) self.assertRedirects( response, UserFactory.get_login_url(next='/reservation/payment/budget/')) def test_user_cannot_access_budget_page_without_staged_payment(self): self.client.login(username=self.user.email, password='******') response = self.client.get(self.budget_url) self.assertEqual(response.status_code, client.FORBIDDEN) def test_user_can_access_budget_page_with_staged_payment(self): self.client.login(username=self.user.email, password='******') reservation = factories.ReservationFactory(user=self.user) payment = factories.PaymentFactory(user=self.user, type=models.Payment.STAGED) payment.reservation_set.add(reservation) response = self.client.get(self.budget_url) self.assertEqual(response.status_code, client.OK) def test_user_cannot_pay_with_budget_with_invalid_password(self): self.client.login(username=self.user.email, password='******') reservation = factories.ReservationFactory(user=self.user) payment = factories.PaymentFactory(user=self.user, type=models.Payment.STAGED) payment.reservation_set.add(reservation) response = self.client.post(self.budget_url, {'password': '******'}) self.assertEqual(response.status_code, client.OK) staged_payment = models.Payment.objects.filter( user=self.user, type=models.Payment.BUDGET) self.assertFalse(staged_payment.exists()) def test_user_cannot_pay_with_budget_with_not_enough_money(self): self.client.login(username=self.user.email, password='******') factories.ReservationFactory.create_batch(3, user=self.user) response = self.client.get(self.list_url) self.assertEqual(response.status_code, client.OK) response = self.client.post(self.budget_url, {'password': '******'}) self.assertRedirects(response, '/reservation/list/') def test_user_can_pay_with_budget_with_enough_money(self): self.client.login(username=self.user.email, password='******') reservations = factories.ReservationFactory.create_batch( 3, user=self.user) amount = sum(reservation.price for reservation in reservations) self.user.budget = amount self.user.save() response = self.client.get(self.list_url) self.assertEqual(response.status_code, client.OK) response = self.client.post(self.budget_url, {'password': '******'}) self.assertRedirects(response, '/') self.assertEqual( user_models.User.objects.get(id=self.user.id).budget, 0) staged_payment = models.Payment.objects.filter( user=self.user, type=models.Payment.BUDGET) self.assertTrue(staged_payment.exists())
def setUp(self): self.user = UserFactory(is_active=True) self.list_url = factories.ReservationFactory.get_reservation_list_url() self.transaction_url = factories.ReservationFactory.get_transaction_url( )
def test_anonymous_user_cannot_access_reservation_update_page(self): response = self.client.get(self.detail_url) self.assertRedirects( response, UserFactory.get_login_url(next='/reservation/update/%s/' % self.reservation.id))
def setUp(self): self.user = UserFactory(is_active=True) self.reservation = ReservationFactory(user=self.user) self.detail_url = ReservationFactory.get_reservation_detail_url( self.reservation.id)
def test_anonymous_user_cannot_access_budget_payment_page(self): response = self.client.get(self.budget_url) self.assertRedirects( response, UserFactory.get_login_url(next='/reservation/payment/budget/'))
def setUp(self): self.registration_url = UserFactory.get_registration_url() self.form_data = UserFactory.get_form_data()
def setUp(self): self.user = UserFactory(is_active=True) mail.outbox = [] self.deactivate_url = UserFactory.get_deactivate_url() self.homepage_url = reverse('homepage')
def test_anonymous_user_cannot_add_money_to_the_balance(self): response = self.client.get(self.balance_url) self.assertRedirects( response, expected_url=UserFactory.get_login_url(next='/user/balance/'))
def test_anonymous_user_is_redirected_to_the_login_page(self): response = self.client.get(self.deactivate_url) self.assertRedirects(response, expected_url=UserFactory.get_login_url(next='/user/deactivate/'))
def test_anonymous_user_cannot_add_money_to_the_balance(self): response = self.client.get(self.balance_url) self.assertRedirects(response, expected_url=UserFactory.get_login_url(next='/user/balance/'))
def test_anon_user_cannot_add_reservation(self): response = self.client.get(self.reservation_url) self.assertRedirects( response, expected_url=UserFactory.get_login_url(next='/reservation/add/'))
def test_anonymous_user_cannot_access_history_page(self): response = self.client.get(self.history_url) self.assertRedirects(response, UserFactory.get_login_url(next='/reservation/history/'))
def test_anon_user_cannot_post_reservation(self): start, end = self.get_valid_datetime(12, 5) res_d = {'start': start, 'end': end, 'field': 'A'} response = self.client.post(self.reservation_url, res_d, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.assertEqual(len(Reservation.objects.all()), 0, _("Anonymous user can make a valid reservation")) self.assertRedirects(response, expected_url=UserFactory.get_login_url(next='/reservation/add/'))
def test_anon_user_cannot_add_reservation(self): response = self.client.get(self.reservation_url) self.assertRedirects(response, expected_url=UserFactory.get_login_url(next='/reservation/add/'))
def test_anon_user_cannot_remove_specific_reservation(self): response = self.client.post(self.remove_url, {'id': str(1)}, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.assertRedirects(response, expected_url=UserFactory.get_login_url( next='/reservation/remove/'))
def setUp(self): self.user = UserFactory(is_active=True) self.history_url = ReservationFactory.get_reservation_history_url()
def test_active_user_has_pin(self): user = UserFactory() user.is_active = True user.save() self.assertNotEqual(user.pin, None)
def test_inactive_user_has_None_pin(self): user = UserFactory() self.assertEqual(user.pin, None)
def test_anonymous_user_cannot_access_reservation_update_page(self): response = self.client.get(self.detail_url) self.assertRedirects(response, UserFactory.get_login_url( next='/reservation/update/%s/' % self.reservation.id))
def test_anon_user_cannot_remove_specific_reservation(self): response = self.client.post(self.remove_url, {'id': str(1)}, HTTP_X_REQUESTED_WITH="XMLHttpRequest") self.assertRedirects(response, expected_url=UserFactory.get_login_url(next='/reservation/remove/'))