def test_user_cannot_lock_room_without_joining(self): self.client.force_authenticate(user=self.normal_1) create_user_preferences(user=self.normal_1, zosia=self.zosia, payment_accepted=True) data = {"user": self.normal_1.pk} response = self.client.post(self.url_1, data, format="json") self.room_1.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_user_can_join_free_room(self): self.client.force_authenticate(user=self.normal_1) create_user_preferences(user=self.normal_1, zosia=self.zosia, payment_accepted=True) data = {"user": self.normal_1.pk} response = self.client.post(self.url_2, data, format="json") self.room_2.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) room_assertions.assertJoined(self.normal_1, self.room_2)
def test_staff_cannot_add_user_to_full_room(self): self.room_2.join(self.normal_2) self.client.force_authenticate(user=self.staff_2) create_user_preferences(user=self.normal_1, zosia=self.zosia, payment_accepted=True) data = {"user": self.normal_1.pk} response = self.client.post(self.url_2, data, format="json") self.room_2.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_staff_can_unlock_room(self): self.client.force_authenticate(user=self.staff_1) create_user_preferences(user=self.normal_1, zosia=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, {}, format="json") self.room_1.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertFalse(self.room_1.is_locked)
def test_staff_can_lock_hidden_room(self): self.client.force_authenticate(user=self.staff_2) create_user_preferences(user=self.normal_2, zosia=self.zosia, payment_accepted=True) self.room_3.join(self.normal_2, self.staff_2) data = {"user": self.normal_2.pk} response = self.client.post(self.url_3, data, format="json") self.room_3.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) room_assertions.assertLocked(self.room_3, self.normal_2)
def test_user_cannot_join_before_rooming_starts(self): self.client.force_authenticate(user=self.normal_1) create_user_preferences(user=self.normal_1, zosia=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, format="json") self.room_1.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_user_cannot_unlock_not_owned_room(self): self.client.force_authenticate(user=self.normal_1) create_user_preferences(user=self.normal_1, zosia=self.zosia, payment_accepted=True) self.room_1.join(self.normal_2) self.room_1.set_lock(self.normal_2) self.room_1.join(self.normal_1, password=self.room_1.lock.password) response = self.client.post(self.url_1, {}, format="json") self.room_1.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) room_assertions.assertLocked(self.room_1, self.normal_2)
def test_staff_can_add_user_to_room_before_rooming_starts(self): self.client.force_authenticate(user=self.staff_2) create_user_preferences(user=self.normal_1, zosia=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, format="json") self.room_1.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) room_assertions.assertJoined(self.normal_1, self.room_1)
def test_staff_can_lock_room_with_expiration_date(self): self.client.force_authenticate(user=self.staff_1) create_user_preferences(user=self.normal_1, zosia=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, format="json") 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)
def test_owner_can_leave_locked_room_then_unlocks(self): self.client.force_authenticate(user=self.normal_2) create_user_preferences(user=self.normal_2, zosia=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, format="json") 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)
def test_staff_can_unlock_after_rooming_ends(self): self.client.force_authenticate(user=self.staff_2) create_user_preferences(user=self.normal_2, zosia=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, {}, format="json") self.room_2.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) room_assertions.assertUnlocked(self.room_2)
def test_not_owner_can_leave_locked_room_then_lock_remains(self): self.client.force_authenticate(user=self.normal_1) create_user_preferences(user=self.normal_1, zosia=self.zosia, payment_accepted=True) self.room_1.join(self.normal_2) self.room_1.join(self.normal_2) self.room_1.set_lock(self.normal_2) data = {"user": self.normal_1.pk} response = self.client.post(self.url_1, data, format="json") self.room_1.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(self.room_1.members_count, 1) room_assertions.assertLocked(self.room_1, self.normal_2)
def test_user_can_join_locked_room_with_password(self): self.room_1.join(self.normal_2) self.room_1.set_lock(self.normal_2) self.client.force_authenticate(user=self.normal_1) create_user_preferences(user=self.normal_1, zosia=self.zosia, payment_accepted=True) data = { "user": self.normal_1.pk, "password": self.room_1.lock.password } response = self.client.post(self.url_1, data, format="json") self.room_1.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) room_assertions.assertJoined(self.normal_1, self.room_1) room_assertions.assertJoined(self.normal_2, self.room_1)
def register(self, **kwargs): return create_user_preferences(user=self.normal_1, zosia=self.zosia, **kwargs)