Exemplo n.º 1
0
    def test_user_cannot_lock_room_without_joining(self):
        self.client.force_authenticate(user=self.normal_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)

        data = {"user": self.normal_1.pk}
        response = self.client.post(self.url_1, data)
        self.room_1.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemplo n.º 2
0
    def test_user_cannot_leave_nonexisting_room(self):
        self.client.force_authenticate(user=self.normal_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)

        url = reverse("rooms_api_leave", kwargs={"version": "v1", "pk": 0})
        data = {"user": self.normal_1.pk}
        response = self.client.post(url, data)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Exemplo n.º 3
0
    def test_staff_can_add_user_to_hidden_room(self):
        self.client.force_authenticate(user=self.staff_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)

        data = {"user": self.normal_1.pk}
        response = self.client.post(self.url_3, data)
        self.room_3.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        room_assertions.assertJoined(self.normal_1, self.room_3)
Exemplo n.º 4
0
    def test_user_cannot_join_before_rooming_starts(self):
        self.client.force_authenticate(user=self.normal_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)
        self.zosia.rooming_start = timedelta_since_now(days=7)
        self.zosia.save()

        data = {"user": self.normal_1.pk}
        response = self.client.post(self.url_1, data)
        self.room_1.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemplo n.º 5
0
    def test_staff_can_add_user_to_room_after_rooming_ends(self):
        self.client.force_authenticate(user=self.staff_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)
        self.zosia.rooming_end = timedelta_since_now(days=-7)
        self.zosia.save()

        data = {"user": self.normal_1.pk}
        response = self.client.post(self.url_1, data)
        self.room_1.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        room_assertions.assertJoined(self.normal_1, self.room_1)
Exemplo n.º 6
0
    def test_user_can_join_room_when_available_place(self):
        self.client.force_authenticate(user=self.normal_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)
        self.room_2.join(self.normal_2)

        data = {"user": self.normal_1.pk}
        response = self.client.post(self.url_2, data)
        self.room_2.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        room_assertions.assertJoined(self.normal_2, self.room_2)
        room_assertions.assertJoined(self.normal_1, self.room_2)
Exemplo n.º 7
0
    def test_user_cannot_remove_other_user_from_room(self):
        self.client.force_authenticate(user=self.normal_1)
        create_user_preferences(self.normal_2,
                                self.zosia,
                                payment_accepted=True)

        self.room_2.join(self.normal_1)
        self.room_2.join(self.normal_2)

        data = {"user": self.normal_2.pk}
        response = self.client.post(self.url_2, data)
        self.room_2.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemplo n.º 8
0
    def test_user_can_leave_joined_room(self):
        self.client.force_authenticate(user=self.normal_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)

        self.room_1.join(self.normal_1)

        data = {"user": self.normal_1.pk}
        response = self.client.post(self.url_1, data)
        self.room_1.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        room_assertions.assertEmpty(self.room_1)
Exemplo n.º 9
0
    def test_staff_can_unlock_room(self):
        self.client.force_authenticate(user=self.staff_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)

        self.room_1.join(self.normal_1)
        self.room_1.set_lock(self.normal_1)

        response = self.client.post(self.url_1, {})
        self.room_1.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertFalse(self.room_1.is_locked)
Exemplo n.º 10
0
    def test_user_cannot_unlock_not_owned_room(self):
        self.client.force_authenticate(user=self.normal_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)

        self.room_2.join(self.normal_2)
        self.room_2.set_lock(self.normal_2)
        self.room_2.join(self.normal_1, password=self.room_2.lock.password)

        response = self.client.post(self.url_2, {})
        self.room_2.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        room_assertions.assertLocked(self.room_2, self.normal_2)
Exemplo n.º 11
0
    def test_owner_can_leave_locked_room_then_unlocks(self):
        self.client.force_authenticate(user=self.normal_2)
        create_user_preferences(self.normal_2,
                                self.zosia,
                                payment_accepted=True)

        self.room_2.join(self.normal_2)
        self.room_2.set_lock(self.normal_2)

        data = {"user": self.normal_2.pk}
        response = self.client.post(self.url_2, data)
        self.room_2.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        room_assertions.assertEmpty(self.room_2)
        room_assertions.assertUnlocked(self.room_2)
Exemplo n.º 12
0
 def setUp(self):
     super().setUp()
     self.user_prefs = create_user_preferences(self.normal,
                                               self.zosia,
                                               contact='foo')
     self.url = reverse('user_preferences_edit',
                        kwargs={'pk': self.user_prefs.pk})
Exemplo n.º 13
0
    def test_user_can_lock_room_after_joining(self):
        self.client.force_authenticate(user=self.normal_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)

        self.room_1.join(self.normal_1)

        data = {"user": self.normal_1.pk}
        response = self.client.post(self.url_1, data)
        self.room_1.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        room_assertions.assertLocked(self.room_1, self.normal_1)
        self.assertEqual(response.data["lock"]["user"]["last_name"], "lennon")
        self.assertIsNotNone(response.data["lock"]["password"])
Exemplo n.º 14
0
    def test_staff_can_lock_room_with_expiration_date(self):
        self.client.force_authenticate(user=self.staff_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)

        self.room_1.join(self.normal_1)

        expiration_date = timedelta_since_now(days=1)
        data = {"user": self.normal_1.pk, "expiration_date": expiration_date}
        response = self.client.post(self.url_1, data)
        self.room_1.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        room_assertions.assertLocked(self.room_1, self.normal_1)
        self.assertEqual(self.room_1.lock.expiration_date, expiration_date)
Exemplo n.º 15
0
 def test_post_user_already_registered(self):
     create_user_preferences(self.normal, self.zosia)
     self.assertEqual(
         UserPreferences.objects.filter(user=self.normal).count(), 1)
     self.client.login(email="*****@*****.**",
                       password="******")
     response = self.client.post(self.url,
                                 data={
                                     'contact': 'fb: me',
                                     'shirt_size': 'S',
                                     'shirt_type': 'f',
                                     'terms_accepted': True
                                 },
                                 follow=True)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         UserPreferences.objects.filter(user=self.normal).count(), 1)
Exemplo n.º 16
0
    def test_user_can_unlock_after_rooming_ends(self):
        self.client.force_authenticate(user=self.normal_2)
        create_user_preferences(self.normal_2,
                                self.zosia,
                                payment_accepted=True)

        self.room_2.join(self.normal_2)
        self.room_2.set_lock(self.normal_2)

        self.zosia.rooming_end = timedelta_since_now(days=-7)
        self.zosia.save()

        response = self.client.post(self.url_2, {})
        self.room_2.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        room_assertions.assertLocked(self.room_2, self.normal_2)
Exemplo n.º 17
0
    def test_user_can_join_locked_room_with_password(self):
        self.room_2.join(self.normal_2)
        self.room_2.set_lock(self.normal_2)
        self.client.force_authenticate(user=self.normal_1)
        create_user_preferences(self.normal_1,
                                self.zosia,
                                payment_accepted=True)

        data = {
            "user": self.normal_1.pk,
            "password": self.room_2.lock.password
        }
        response = self.client.post(self.url_2, data)
        self.room_2.refresh_from_db()

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        room_assertions.assertJoined(self.normal_1, self.room_2)
        room_assertions.assertJoined(self.normal_2, self.room_2)
Exemplo n.º 18
0
    def test_can_user_choose_room_when_at_user_start_time(self):
        self.active.rooming_start = now()
        self.active.save()
        user_prefs = create_user_preferences(self.normal,
                                             self.active,
                                             payment_accepted=True,
                                             bonus_minutes=0)

        result = self.active.can_user_choose_room(user_prefs)

        self.assertTrue(result)
Exemplo n.º 19
0
    def test_can_user_choose_room_when_after_user_start_time(self):
        self.active.rooming_start = time_point(2016, 12, 23, 0, 0)
        self.active.save()
        user_prefs = create_user_preferences(self.normal,
                                             self.active,
                                             payment_accepted=True,
                                             bonus_minutes=3)

        result = self.active.can_user_choose_room(user_prefs,
                                                  time=time_point(
                                                      2016, 12, 22, 23, 58))
        self.assertTrue(result)
Exemplo n.º 20
0
    def test_get_regular_user_already_registered(self):
        self.client.login(email="*****@*****.**",
                          password="******")
        org = create_organization(name='ksi', accepted=True)
        user_prefs = create_user_preferences(self.normal,
                                             self.zosia,
                                             organization=org)
        response = self.client.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)

        context = response.context[-1]
        self.assertEqual(context['form'].__class__, UserPreferencesForm)
        self.assertEqual(context['object'], user_prefs)
Exemplo n.º 21
0
 def test_user_cannot_change_accommodation_after_paid(self):
     create_user_preferences(self.normal,
                             self.zosia,
                             accommodation_day_1=False,
                             shirt_size='M',
                             payment_accepted=True)
     self.assertEqual(
         UserPreferences.objects.filter(user=self.normal).count(), 1)
     self.client.login(email="*****@*****.**",
                       password="******")
     response = self.client.post(self.url,
                                 data={
                                     'accommodation_day_1': True,
                                     'shirt_size': 'M',
                                     'shirt_type': 'f',
                                     'contact': 'fb: me',
                                     'terms_accepted': True
                                 },
                                 follow=True)
     self.assertEqual(response.status_code, 200)
     prefs = UserPreferences.objects.filter(user=self.normal).first()
     self.assertFalse(prefs.accommodation_day_1)
     # Sanity check ;)
     self.assertEqual(prefs.shirt_size, 'M')
Exemplo n.º 22
0
 def test_index_get_staff_user_multiple_zosias(self):
     another_zosia = create_zosia()
     create_user_preferences(self.normal, another_zosia)
     create_user_preferences(self.normal, self.zosia)
     create_user_preferences(self.staff, self.zosia)
     self.client.login(email="*****@*****.**",
                       password='******')
     response = self.client.get(self.url, follow=True)
     self.assertEqual(response.status_code, 200)
     context = response.context[-1]
     self.assertEqual(
         list(context['objects']),
         list(UserPreferences.objects.filter(zosia=self.zosia).all()))
Exemplo n.º 23
0
 def test_find_available_when_passenger_and_bus_chosen_and_not_full(self):
     user_prefs = create_user_preferences(self.normal,
                                          self.zosia,
                                          bus=self.bus3)
     buses = Bus.objects.find_available(self.zosia, passenger=user_prefs)
     self.assertEqual(buses.count(), 2)
Exemplo n.º 24
0
 def test_find_buses_with_free_places_when_bus_chosen_and_not_full(self):
     create_user_preferences(self.normal, self.zosia, bus=self.bus3)
     buses = Bus.objects.find_with_free_places(self.zosia)
     self.assertEqual(buses.count(), 2)
Exemplo n.º 25
0
 def test_find_available_when_bus_chosen_and_full(self):
     create_user_preferences(self.normal, self.zosia, bus=self.bus2)
     buses = Bus.objects.find_available(self.zosia)
     self.assertEqual(buses.count(), 1)
Exemplo n.º 26
0
 def setUp(self):
     super().setUp()
     self.user_prefs = create_user_preferences(self.normal, self.zosia)
     self.url = reverse('user_preferences_admin_edit')