예제 #1
0
    def test_cannot_get_reservation_expe_not_manager(self):
        """
        Shouldn't be able to get a reservation expe if not manager of canteen
        """
        canteen = CanteenFactory.create()
        ReservationExpeFactory.create(canteen=canteen)

        response = self.client.get(reverse("canteen_reservation_expe", kwargs={"canteen_pk": canteen.id}))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
예제 #2
0
    def test_get_reservation_expe(self):
        """
        Test that we can get a reservation experiment for a canteen
        """
        canteen = CanteenFactory.create()
        canteen.managers.add(authenticate.user)
        ReservationExpeFactory.create(canteen=canteen, leader_email="*****@*****.**")

        response = self.client.get(reverse("canteen_reservation_expe", kwargs={"canteen_pk": canteen.id}))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        body = response.json()
        self.assertEqual(body["leaderEmail"], "*****@*****.**")
예제 #3
0
 def test_cannot_update_reservation_expe_not_manager(self):
     """
     Shouldn't be able to update a reservation expe if not manager of the canteen
     """
     canteen = CanteenFactory.create()
     reservation_expe = ReservationExpeFactory.create(canteen=canteen, leader_email="*****@*****.**")
     payload = {"leader_email": "*****@*****.**"}
     response = self.client.patch(reverse("canteen_reservation_expe", kwargs={"canteen_pk": canteen.id}), payload)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
     reservation_expe.refresh_from_db()
     self.assertEqual(reservation_expe.leader_email, "*****@*****.**")
예제 #4
0
 def test_cannot_update_canteen_for_reservation_expe(self):
     """
     Check that cannot update canteen on a reservation expe
     """
     canteen = CanteenFactory.create()
     canteen.managers.add(authenticate.user)
     reservation_expe = ReservationExpeFactory.create(canteen=canteen)
     payload = {"canteen": CanteenFactory.create().id}
     response = self.client.patch(reverse("canteen_reservation_expe", kwargs={"canteen_pk": canteen.id}), payload)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     reservation_expe.refresh_from_db()
     self.assertEqual(reservation_expe.canteen, canteen)
예제 #5
0
    def test_cannot_create_duplicate_reservation_expe(self):
        """
        Shouldn't be able to create more than one reservation expe for a canteen
        """
        canteen = CanteenFactory.create()
        canteen.managers.add(authenticate.user)
        reservation_expe = ReservationExpeFactory.create(canteen=canteen, satisfaction=5)

        response = self.client.post(
            reverse("canteen_reservation_expe", kwargs={"canteen_pk": canteen.id}), {"satisfaction": 0}
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        reservation_expe.refresh_from_db()
        self.assertEqual(reservation_expe.satisfaction, 5)
        self.assertEqual(ReservationExpe.objects.count(), 1)
예제 #6
0
 def test_update_reservation_expe(self):
     """
     Test that we can update a reservation experiment for a canteen
     """
     canteen = CanteenFactory.create()
     canteen.managers.add(authenticate.user)
     reservation_expe = ReservationExpeFactory.create(
         canteen=canteen, leader_email="*****@*****.**", satisfaction=1
     )
     payload = {"leader_email": "*****@*****.**", "satisfaction": 3}
     response = self.client.patch(reverse("canteen_reservation_expe", kwargs={"canteen_pk": canteen.id}), payload)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     reservation_expe.refresh_from_db()
     self.assertEqual(reservation_expe.leader_email, "*****@*****.**")
     self.assertEqual(reservation_expe.satisfaction, 3)
예제 #7
0
    def test_updates_bad_data(self):
        """
        Check that updates with bad data are rejected
        """
        canteen = CanteenFactory.create()
        canteen.managers.add(authenticate.user)
        reservation_expe = ReservationExpeFactory.create(canteen=canteen, satisfaction=3, avg_weight_not_served_t2=70)

        response = self.client.patch(
            reverse("canteen_reservation_expe", kwargs={"canteen_pk": canteen.id}),
            {"satisfaction": 6},
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        reservation_expe.refresh_from_db()
        self.assertEqual(reservation_expe.satisfaction, 3)

        response = self.client.patch(
            reverse("canteen_reservation_expe", kwargs={"canteen_pk": canteen.id}),
            {"avgWeightNotServedT2": -90},
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        reservation_expe.refresh_from_db()
        self.assertEqual(reservation_expe.avg_weight_not_served_t2, 70)