Exemplo n.º 1
0
 def test_get_error_message_non_event(self):
     view = self.get_view()
     form = self.create_form(1, 2)
     self.assertTrue(form.is_valid())
     reservation = ReservationSewing(
         user=self.user,
         start_time=form.cleaned_data["start_time"],
         end_time=form.cleaned_data["end_time"],
         machine=self.machine)
     self.assertEqual(view.get_error_message(form, reservation),
                      "Tidspunktet er ikke lengre tilgjengelig")
Exemplo n.º 2
0
 def test_get_error_message_too_far_in_the_future(self):
     view = self.get_view()
     form = self.create_form(24 * 7, 24 * 7 + 1)
     self.assertTrue(form.is_valid())
     reservation = ReservationSewing(
         user=self.user,
         start_time=form.cleaned_data["start_time"],
         end_time=form.cleaned_data["end_time"],
         machine=self.machine)
     self.assertEqual(view.get_error_message(form, reservation),
                      "Reservasjoner kan bare lages 7 dager frem i tid")
Exemplo n.º 3
0
    def test_user_can_reserve_sewing_machine(self):
        sewing_machine = SewingMachine.objects.get(name="C1")
        user = User.objects.get(username="******")

        user_quota = user.quotasewing
        user_quota.max_number_of_reservations = 2
        user_quota.save()

        reservation = ReservationSewing(user=user, machine=sewing_machine, start_time=timezone.now(),
                                        end_time=timezone.now() + timedelta(hours=2), event=None)

        self.check_reservation_valid(reservation, "Users should be able to reserve sewing machines")
Exemplo n.º 4
0
 def test_validate_and_save_valid_reservation(self):
     view = self.get_view()
     form = self.create_form(1, 2)
     self.assertTrue(form.is_valid())
     reservation = ReservationSewing(
         user=self.user,
         start_time=form.cleaned_data["start_time"],
         end_time=form.cleaned_data["end_time"],
         machine=self.machine)
     response = view.validate_and_save(reservation, form)
     self.assertEqual(1, ReservationSewing.objects.count())
     self.assertEqual(302, response.status_code)
Exemplo n.º 5
0
 def test_get_error_message_event(self):
     view = self.get_view()
     form = self.create_form(1, 2, event=self.event)
     self.assertTrue(form.is_valid())
     reservation = ReservationSewing(
         user=self.user,
         start_time=form.cleaned_data["start_time"],
         end_time=form.cleaned_data["end_time"],
         machine=self.machine)
     self.user.user_permissions.add(
         Permission.objects.get(name="Can create event reservation"))
     self.assertEqual(
         view.get_error_message(form, reservation),
         "Tidspunktet eller eventen, er ikke lengre tilgjengelig")
Exemplo n.º 6
0
 def test_get_error_message_maximum_reached(self):
     ReservationSewing.percentage_of_machines_at_the_same_time = 0
     view = self.get_view()
     form = self.create_form(1, 2)
     self.assertTrue(form.is_valid())
     reservation = ReservationSewing(
         user=self.user,
         start_time=form.cleaned_data["start_time"],
         end_time=form.cleaned_data["end_time"],
         machine=self.machine)
     self.assertEqual(
         view.get_error_message(form, reservation),
         "Du har booket maksimalt antall reservasjoner for denne tidsperioden, prøv et annet tidspunkt"
     )
Exemplo n.º 7
0
    def test_validate_and_save_non_valid_reservation(self):
        view = self.get_view()
        # Set values to allow for context to be created
        view.new_reservation = False
        view.sub_class = SewingMachine

        form = self.create_form(1, 2)
        self.assertTrue(form.is_valid())
        # Test with collision
        ReservationSewing.objects.create(
            user=self.user,
            start_time=form.cleaned_data["start_time"],
            end_time=form.cleaned_data["end_time"],
            machine=self.machine)
        reservation = ReservationSewing(
            user=self.user,
            start_time=form.cleaned_data["start_time"],
            end_time=form.cleaned_data["end_time"],
            machine=self.machine)
        response = view.validate_and_save(reservation, form)
        # Second reservation should not be saved
        self.assertEqual(1, ReservationSewing.objects.count())
        # 200 to re render the form
        self.assertEqual(200, response.status_code)