mirror of
https://github.com/ae-utbm/sith.git
synced 2025-02-23 16:07:22 +00:00
fix some tests
This commit is contained in:
parent
b03b69814d
commit
ed079a7c9d
@ -19,51 +19,6 @@ from sas.models import Picture
|
||||
from sith import settings
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestImageAccess:
|
||||
@pytest.mark.parametrize(
|
||||
"user_factory",
|
||||
[
|
||||
lambda: baker.make(User, is_superuser=True),
|
||||
lambda: baker.make(
|
||||
User, groups=[Group.objects.get(pk=settings.SITH_GROUP_SAS_ADMIN_ID)]
|
||||
),
|
||||
lambda: baker.make(
|
||||
User, groups=[Group.objects.get(pk=settings.SITH_GROUP_COM_ADMIN_ID)]
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_sas_image_access(self, user_factory: Callable[[], User]):
|
||||
"""Test that only authorized users can access the sas image."""
|
||||
user = user_factory()
|
||||
picture: SithFile = baker.make(
|
||||
Picture, parent=SithFile.objects.get(pk=settings.SITH_SAS_ROOT_DIR_ID)
|
||||
)
|
||||
assert picture.is_owned_by(user)
|
||||
|
||||
def test_sas_image_access_owner(self):
|
||||
"""Test that the owner of the image can access it."""
|
||||
user = baker.make(User)
|
||||
picture: Picture = baker.make(Picture, owner=user)
|
||||
assert picture.is_owned_by(user)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"user_factory",
|
||||
[
|
||||
lambda: baker.make(User),
|
||||
subscriber_user.make,
|
||||
old_subscriber_user.make,
|
||||
board_user.make,
|
||||
],
|
||||
)
|
||||
def test_sas_image_access_forbidden(self, user_factory: Callable[[], User]):
|
||||
cache.clear()
|
||||
user = user_factory()
|
||||
owner = baker.make(User)
|
||||
picture: Picture = baker.make(Picture, owner=owner)
|
||||
assert not picture.is_owned_by(user)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestUserPicture:
|
||||
def test_anonymous_user_unauthorized(self, client):
|
||||
|
@ -19,6 +19,7 @@ from core.baker_recipes import (
|
||||
from core.models import Group, User
|
||||
from counter.models import Counter, Refilling, Selling
|
||||
from eboutic.models import Invoice, InvoiceItem
|
||||
from sas.models import Picture
|
||||
|
||||
|
||||
class TestSearchUsers(TestCase):
|
||||
@ -26,6 +27,7 @@ class TestSearchUsers(TestCase):
|
||||
def setUpTestData(cls):
|
||||
# News.author has on_delete=PROTECT, so news must be deleted beforehand
|
||||
News.objects.all().delete()
|
||||
Picture.objects.all().delete() # same for pictures
|
||||
User.objects.all().delete()
|
||||
user_recipe = Recipe(
|
||||
User,
|
||||
|
@ -58,7 +58,7 @@ class TestPictureSearch(TestSas):
|
||||
self.client.force_login(self.user_b)
|
||||
res = self.client.get(self.url + f"?album_id={self.album_a.id}")
|
||||
assert res.status_code == 200
|
||||
expected = list(self.album_a.children_pictures.values_list("id", flat=True))
|
||||
expected = list(self.album_a.pictures.values_list("id", flat=True))
|
||||
assert [i["id"] for i in res.json()["results"]] == expected
|
||||
|
||||
def test_filter_by_user(self):
|
||||
@ -67,7 +67,7 @@ class TestPictureSearch(TestSas):
|
||||
assert res.status_code == 200
|
||||
expected = list(
|
||||
self.user_a.pictures.order_by(
|
||||
"-picture__parent__date", "picture__date"
|
||||
"-picture__parent__event_date", "picture__created_at"
|
||||
).values_list("picture_id", flat=True)
|
||||
)
|
||||
assert [i["id"] for i in res.json()["results"]] == expected
|
||||
@ -81,7 +81,7 @@ class TestPictureSearch(TestSas):
|
||||
assert res.status_code == 200
|
||||
expected = list(
|
||||
self.user_a.pictures.union(self.user_b.pictures.all())
|
||||
.order_by("-picture__parent__date", "picture__date")
|
||||
.order_by("-picture__parent__event_date", "picture__created_at")
|
||||
.values_list("picture_id", flat=True)
|
||||
)
|
||||
assert [i["id"] for i in res.json()["results"]] == expected
|
||||
@ -94,7 +94,7 @@ class TestPictureSearch(TestSas):
|
||||
assert res.status_code == 200
|
||||
expected = list(
|
||||
self.user_a.pictures.order_by(
|
||||
"-picture__parent__date", "picture__date"
|
||||
"-picture__parent__event_date", "picture__created_at"
|
||||
).values_list("picture_id", flat=True)
|
||||
)
|
||||
assert [i["id"] for i in res.json()["results"]] == expected
|
||||
@ -120,7 +120,7 @@ class TestPictureSearch(TestSas):
|
||||
assert res.status_code == 200
|
||||
expected = list(
|
||||
self.user_b.pictures.intersection(self.user_a.pictures.all())
|
||||
.order_by("-picture__parent__date", "picture__date")
|
||||
.order_by("-picture__parent__event_date", "picture__created_at")
|
||||
.values_list("picture_id", flat=True)
|
||||
)
|
||||
assert [i["id"] for i in res.json()["results"]] == expected
|
||||
|
@ -70,9 +70,7 @@ def test_album_access_non_subscriber(client: Client):
|
||||
class TestSasModeration(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
album = baker.make(
|
||||
Album, parent_id=settings.SITH_SAS_ROOT_DIR_ID, is_moderated=True
|
||||
)
|
||||
album = baker.make(Album)
|
||||
cls.pictures = picture_recipe.make(
|
||||
parent=album, _quantity=10, _bulk_create=True
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user