예제 #1
0
 def test_user_does_not_get_other_user_reservations(self):
     ReservationFactory.create_batch(3, paid=True)
     data = {
         'month': timezone.datetime.today().month,
         'year': timezone.datetime.today().year
     }
     self._ensure_table_has_not_been_created(data)
예제 #2
0
 def test_all_users_unpaid_reservations_are_deleted(self):
     self.client.login(**self.login_data)
     ReservationFactory.create_batch(3, user=self.user)
     self.client.post(self.remove_all_url,
                      HTTP_X_REQUESTED_WITH="XMLHttpRequest")
     self.assertEqual(Reservation.objects.all().count(), 0,
                      _("Not all unpaid reservations are deleted"))
예제 #3
0
 def test_user_can_see_multiple_unpaid_reservations(self):
     ReservationFactory.create_batch(3, user=self.user)
     self.client.login(**self.login_data)
     response = self.client.get(ReservationFactory.get_reservation_list_url(),
                                {'start': timezone.now().date(), 'end': timezone.now().date()})
     reservations = [reserv for reserv in response.context_data['table'].data]
     self.assertEqual(len(reservations), 3, _("All three reservations are shown"))
예제 #4
0
 def test_user_does_not_get_other_user_reservations(self):
     ReservationFactory.create_batch(3, paid=True)
     data = {
         'month': timezone.datetime.today().month,
         'year': timezone.datetime.today().year
     }
     self._ensure_table_has_not_been_created(data)
예제 #5
0
 def test_user_cannot_update_other_user_reservation(self):
     self.client.login(username=self.user.email, password='******')
     other_reservation = ReservationFactory(paid=True)
     response = self.client.get(
         ReservationFactory.get_reservation_detail_url(
             other_reservation.id))
     self.assertEqual(response.status_code, http_client.NOT_FOUND)
예제 #6
0
 def test_user_cannot_update_reservation_in_past(self):
     self.client.login(username=self.user.email, password='******')
     reservation = ReservationFactory(
         start=timezone.now() - timedelta(minutes=15),
         end=timezone.now() - timedelta(hours=1, minutes=15),
         user=self.user,
         paid=True)
     response = self.client.get(
         ReservationFactory.get_reservation_detail_url(reservation.id))
     self.assertEqual(response.status_code, http_client.NOT_FOUND)
예제 #7
0
    def test_user_can_delete_future_paid_reservations(self):
        self.client.login(username=self.user.email, password='******')
        reservation = ReservationFactory(paid=True, user=self.user)
        response = self.client.post(ReservationFactory.get_remove_url(),
                                    {'id': reservation.id},
                                    HTTP_X_REQUESTED_WITH="XMLHttpRequest")

        self.assertEqual(response.status_code, http_client.OK)
        self.assertFalse(
            Reservation.objects.filter(id=reservation.id).exists())
        self.assertEqual(
            User.objects.get(id=self.user.id).budget, reservation.price)
예제 #8
0
 def test_user_can_see_multiple_unpaid_reservations(self):
     ReservationFactory.create_batch(3, user=self.user)
     self.client.login(**self.login_data)
     response = self.client.get(
         ReservationFactory.get_reservation_list_url(), {
             'start': timezone.now().date(),
             'end': timezone.now().date()
         })
     reservations = [
         reserv for reserv in response.context_data['table'].data
     ]
     self.assertEqual(len(reservations), 3,
                      _("All three reservations are shown"))
예제 #9
0
 def test_user_cannot_delete_paid_reservations_in_past(self):
     self.client.login(username=self.user.email, password='******')
     reservation = ReservationFactory(
         start=timezone.now() - timedelta(hours=1, minutes=15),
         end=timezone.now() - timedelta(minutes=15),
         user=self.user,
         paid=True)
     response = self.client.post(ReservationFactory.get_remove_url(),
                                 {'id': reservation.id},
                                 HTTP_X_REQUESTED_WITH="XMLHttpRequest")
     self.assertEqual(response.status_code, http_client.BAD_REQUEST)
     self.assertEqual(response.content.decode('utf-8'),
                      "Cannot delete the reservation.")
     self.assertTrue(Reservation.objects.filter(id=reservation.id).exists())
     self.assertNotEqual(
         User.objects.get(id=self.user.id).budget, reservation.price)
예제 #10
0
 def test_user_cannot_update_reservation_in_past(self):
     self.client.login(username=self.user.email, password='******')
     reservation = ReservationFactory(start=timezone.now() - timedelta(minutes=15),
                                      end=timezone.now() - timedelta(hours=1, minutes=15),
                                      user=self.user, paid=True)
     response = self.client.get(ReservationFactory.get_reservation_detail_url(reservation.id))
     self.assertEqual(response.status_code, http_client.NOT_FOUND)
예제 #11
0
 def test_one_unpaid_reservation_can_be_deleted(self):
     self.client.login(**self.login_data)
     start, end = self.get_valid_datetime(10, 1)
     res_to_del = ReservationFactory(start=start, end=end, user=self.user)
     self.client.post(self.remove_url, {'id': str(res_to_del.id)},
                      HTTP_X_REQUESTED_WITH="XMLHttpRequest")
     self.assertEqual(Reservation.objects.all().count(), 0,
                      _("Unpaid Resevation is not deleted."))
예제 #12
0
    def test_user_can_delete_future_paid_reservations(self):
        self.client.login(username=self.user.email, password='******')
        reservation = ReservationFactory(paid=True, user=self.user)
        response = self.client.post(ReservationFactory.get_remove_url(), {'id': reservation.id},
                                    HTTP_X_REQUESTED_WITH="XMLHttpRequest")

        self.assertEqual(response.status_code, http_client.OK)
        self.assertFalse(Reservation.objects.filter(id=reservation.id).exists())
        self.assertEqual(User.objects.get(id=self.user.id).budget, reservation.price)
예제 #13
0
 def test_user_cannot_delete_paid_reservations_in_past(self):
     self.client.login(username=self.user.email, password='******')
     reservation = ReservationFactory(start=timezone.now() - timedelta(hours=1, minutes=15),
                                      end=timezone.now() - timedelta(minutes=15),
                                      user=self.user, paid=True)
     response = self.client.post(ReservationFactory.get_remove_url(), {'id': reservation.id},
                                 HTTP_X_REQUESTED_WITH="XMLHttpRequest")
     self.assertEqual(response.status_code, http_client.BAD_REQUEST)
     self.assertEqual(response.content.decode('utf-8'), "Cannot delete the reservation.")
     self.assertTrue(Reservation.objects.filter(id=reservation.id).exists())
     self.assertNotEqual(User.objects.get(id=self.user.id).budget, reservation.price)
예제 #14
0
    def test_user_can_update_reservation_with_valid_data(self):
        self.reservation.paid = True
        self.reservation.save()
        self.client.login(username=self.user.email, password='******')

        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, ReservationFactory.get_reservation_history_url())
예제 #15
0
 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()
예제 #16
0
    def test_user_can_update_reservation_with_valid_data(self):
        self.reservation.paid = True
        self.reservation.save()
        self.client.login(username=self.user.email, password='******')

        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,
                             ReservationFactory.get_reservation_history_url())
예제 #17
0
 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(
     )
예제 #18
0
 def test_user_cannot_update_other_user_reservation(self):
     self.client.login(username=self.user.email, password='******')
     other_reservation = ReservationFactory(paid=True)
     response = self.client.get(ReservationFactory.get_reservation_detail_url(other_reservation.id))
     self.assertEqual(response.status_code, http_client.NOT_FOUND)
예제 #19
0
class ReservationUpdateTest(TransactionTestCase):
    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_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_user_can_update_future_paid_reservation(self):
        self.reservation.paid = True
        self.reservation.save()
        self.client.login(username=self.user.email, password='******')
        response = self.client.get(self.detail_url)
        self.assertEqual(response.status_code, http_client.OK)

    def test_user_cannot_update_future_unpaid_reservation(self):
        self.client.login(username=self.user.email, password='******')
        response = self.client.get(self.detail_url)
        self.assertEqual(response.status_code, http_client.NOT_FOUND)

    def test_user_cannot_update_other_user_reservation(self):
        self.client.login(username=self.user.email, password='******')
        other_reservation = ReservationFactory(paid=True)
        response = self.client.get(ReservationFactory.get_reservation_detail_url(other_reservation.id))
        self.assertEqual(response.status_code, http_client.NOT_FOUND)

    def test_user_cannot_update_reservation_in_past(self):
        self.client.login(username=self.user.email, password='******')
        reservation = ReservationFactory(start=timezone.now() - timedelta(minutes=15),
                                         end=timezone.now() - timedelta(hours=1, minutes=15),
                                         user=self.user, paid=True)
        response = self.client.get(ReservationFactory.get_reservation_detail_url(reservation.id))
        self.assertEqual(response.status_code, http_client.NOT_FOUND)

    def test_user_cannot_update_reservation_with_invalid_field_id(self):
        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': 5
        }
        self._ensure_user_cannot_update_reservation(data)

    def test_user_cannot_update_reservation_with_invalid_field_name(self):
        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': 'asad'
        }
        self._ensure_user_cannot_update_reservation(data)

    def test_user_cannot_update_reservation_with_invalid_start_date(self):
        start = self.reservation.start + timedelta(hours=1)
        end = self.reservation.end + timedelta(hours=1)
        data = {
            'start': start.strftime('%Y-%m-%d'),
            'end': end.strftime('%Y-%m-%d %H'),
            'field': self.reservation.field.id
        }
        self._ensure_user_cannot_update_reservation(data)

    def test_user_cannot_update_reservation_with_invalid_end_date(self):
        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'),
            'field': self.reservation.field.id
        }
        self._ensure_user_cannot_update_reservation(data)

    def test_user_can_update_reservation_with_valid_data(self):
        self.reservation.paid = True
        self.reservation.save()
        self.client.login(username=self.user.email, password='******')

        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, ReservationFactory.get_reservation_history_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_user_cannot_make_get_request_to_confirmation_page(self):
        self.client.login(username=self.user.email, password='******')
        response = self.client.get(self.detail_url + 'confirm/')
        self.assertEqual(response.status_code, http_client.METHOD_NOT_ALLOWED)

    # Helper methods
    def _ensure_user_cannot_update_reservation(self, data):
        self.reservation.paid = True
        self.reservation.save()
        self.client.login(username=self.user.email, password='******')

        response = self.client.post(self.detail_url + 'confirm/', data)
        self.assertEqual(response.status_code, http_client.BAD_REQUEST)
예제 #20
0
 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)
예제 #21
0
 def test_all_users_unpaid_reservations_are_deleted(self):
     self.client.login(**self.login_data)
     ReservationFactory.create_batch(3, user=self.user)
     self.client.post(self.remove_all_url, HTTP_X_REQUESTED_WITH="XMLHttpRequest")
     self.assertEqual(Reservation.objects.all().count(), 0,
                      _("Not all unpaid reservations are deleted"))
예제 #22
0
 def setUp(self):
     self.user = UserFactory(is_active=True)
     self.history_url = ReservationFactory.get_reservation_history_url()
예제 #23
0
class ReservationUpdateTest(TransactionTestCase):
    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_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_user_can_update_future_paid_reservation(self):
        self.reservation.paid = True
        self.reservation.save()
        self.client.login(username=self.user.email, password='******')
        response = self.client.get(self.detail_url)
        self.assertEqual(response.status_code, http_client.OK)

    def test_user_cannot_update_future_unpaid_reservation(self):
        self.client.login(username=self.user.email, password='******')
        response = self.client.get(self.detail_url)
        self.assertEqual(response.status_code, http_client.NOT_FOUND)

    def test_user_cannot_update_other_user_reservation(self):
        self.client.login(username=self.user.email, password='******')
        other_reservation = ReservationFactory(paid=True)
        response = self.client.get(
            ReservationFactory.get_reservation_detail_url(
                other_reservation.id))
        self.assertEqual(response.status_code, http_client.NOT_FOUND)

    def test_user_cannot_update_reservation_in_past(self):
        self.client.login(username=self.user.email, password='******')
        reservation = ReservationFactory(
            start=timezone.now() - timedelta(minutes=15),
            end=timezone.now() - timedelta(hours=1, minutes=15),
            user=self.user,
            paid=True)
        response = self.client.get(
            ReservationFactory.get_reservation_detail_url(reservation.id))
        self.assertEqual(response.status_code, http_client.NOT_FOUND)

    def test_user_cannot_update_reservation_with_invalid_field_id(self):
        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': 5
        }
        self._ensure_user_cannot_update_reservation(data)

    def test_user_cannot_update_reservation_with_invalid_field_name(self):
        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': 'asad'
        }
        self._ensure_user_cannot_update_reservation(data)

    def test_user_cannot_update_reservation_with_invalid_start_date(self):
        start = self.reservation.start + timedelta(hours=1)
        end = self.reservation.end + timedelta(hours=1)
        data = {
            'start': start.strftime('%Y-%m-%d'),
            'end': end.strftime('%Y-%m-%d %H'),
            'field': self.reservation.field.id
        }
        self._ensure_user_cannot_update_reservation(data)

    def test_user_cannot_update_reservation_with_invalid_end_date(self):
        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'),
            'field': self.reservation.field.id
        }
        self._ensure_user_cannot_update_reservation(data)

    def test_user_can_update_reservation_with_valid_data(self):
        self.reservation.paid = True
        self.reservation.save()
        self.client.login(username=self.user.email, password='******')

        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,
                             ReservationFactory.get_reservation_history_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_user_cannot_make_get_request_to_confirmation_page(self):
        self.client.login(username=self.user.email, password='******')
        response = self.client.get(self.detail_url + 'confirm/')
        self.assertEqual(response.status_code, http_client.METHOD_NOT_ALLOWED)

    # Helper methods
    def _ensure_user_cannot_update_reservation(self, data):
        self.reservation.paid = True
        self.reservation.save()
        self.client.login(username=self.user.email, password='******')

        response = self.client.post(self.detail_url + 'confirm/', data)
        self.assertEqual(response.status_code, http_client.BAD_REQUEST)
예제 #24
0
 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)
예제 #25
0
 def setUp(self):
     self.user = UserFactory(is_active=True)
     self.history_url = ReservationFactory.get_reservation_history_url()