Skip to content

Commit ed079a7

Browse files
committed
fix some tests
1 parent b03b698 commit ed079a7

File tree

4 files changed

+8
-53
lines changed

4 files changed

+8
-53
lines changed

core/tests/test_files.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,6 @@
1919
from sith import settings
2020

2121

22-
@pytest.mark.django_db
23-
class TestImageAccess:
24-
@pytest.mark.parametrize(
25-
"user_factory",
26-
[
27-
lambda: baker.make(User, is_superuser=True),
28-
lambda: baker.make(
29-
User, groups=[Group.objects.get(pk=settings.SITH_GROUP_SAS_ADMIN_ID)]
30-
),
31-
lambda: baker.make(
32-
User, groups=[Group.objects.get(pk=settings.SITH_GROUP_COM_ADMIN_ID)]
33-
),
34-
],
35-
)
36-
def test_sas_image_access(self, user_factory: Callable[[], User]):
37-
"""Test that only authorized users can access the sas image."""
38-
user = user_factory()
39-
picture: SithFile = baker.make(
40-
Picture, parent=SithFile.objects.get(pk=settings.SITH_SAS_ROOT_DIR_ID)
41-
)
42-
assert picture.is_owned_by(user)
43-
44-
def test_sas_image_access_owner(self):
45-
"""Test that the owner of the image can access it."""
46-
user = baker.make(User)
47-
picture: Picture = baker.make(Picture, owner=user)
48-
assert picture.is_owned_by(user)
49-
50-
@pytest.mark.parametrize(
51-
"user_factory",
52-
[
53-
lambda: baker.make(User),
54-
subscriber_user.make,
55-
old_subscriber_user.make,
56-
board_user.make,
57-
],
58-
)
59-
def test_sas_image_access_forbidden(self, user_factory: Callable[[], User]):
60-
cache.clear()
61-
user = user_factory()
62-
owner = baker.make(User)
63-
picture: Picture = baker.make(Picture, owner=owner)
64-
assert not picture.is_owned_by(user)
65-
66-
6722
@pytest.mark.django_db
6823
class TestUserPicture:
6924
def test_anonymous_user_unauthorized(self, client):

core/tests/test_user.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
from core.models import Group, User
2020
from counter.models import Counter, Refilling, Selling
2121
from eboutic.models import Invoice, InvoiceItem
22+
from sas.models import Picture
2223

2324

2425
class TestSearchUsers(TestCase):
2526
@classmethod
2627
def setUpTestData(cls):
2728
# News.author has on_delete=PROTECT, so news must be deleted beforehand
2829
News.objects.all().delete()
30+
Picture.objects.all().delete() # same for pictures
2931
User.objects.all().delete()
3032
user_recipe = Recipe(
3133
User,

sas/tests/test_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_filter_by_album(self):
5858
self.client.force_login(self.user_b)
5959
res = self.client.get(self.url + f"?album_id={self.album_a.id}")
6060
assert res.status_code == 200
61-
expected = list(self.album_a.children_pictures.values_list("id", flat=True))
61+
expected = list(self.album_a.pictures.values_list("id", flat=True))
6262
assert [i["id"] for i in res.json()["results"]] == expected
6363

6464
def test_filter_by_user(self):
@@ -67,7 +67,7 @@ def test_filter_by_user(self):
6767
assert res.status_code == 200
6868
expected = list(
6969
self.user_a.pictures.order_by(
70-
"-picture__parent__date", "picture__date"
70+
"-picture__parent__event_date", "picture__created_at"
7171
).values_list("picture_id", flat=True)
7272
)
7373
assert [i["id"] for i in res.json()["results"]] == expected
@@ -81,7 +81,7 @@ def test_filter_by_multiple_user(self):
8181
assert res.status_code == 200
8282
expected = list(
8383
self.user_a.pictures.union(self.user_b.pictures.all())
84-
.order_by("-picture__parent__date", "picture__date")
84+
.order_by("-picture__parent__event_date", "picture__created_at")
8585
.values_list("picture_id", flat=True)
8686
)
8787
assert [i["id"] for i in res.json()["results"]] == expected
@@ -94,7 +94,7 @@ def test_not_subscribed_user(self):
9494
assert res.status_code == 200
9595
expected = list(
9696
self.user_a.pictures.order_by(
97-
"-picture__parent__date", "picture__date"
97+
"-picture__parent__event_date", "picture__created_at"
9898
).values_list("picture_id", flat=True)
9999
)
100100
assert [i["id"] for i in res.json()["results"]] == expected
@@ -120,7 +120,7 @@ def test_not_subscribed_user(self):
120120
assert res.status_code == 200
121121
expected = list(
122122
self.user_b.pictures.intersection(self.user_a.pictures.all())
123-
.order_by("-picture__parent__date", "picture__date")
123+
.order_by("-picture__parent__event_date", "picture__created_at")
124124
.values_list("picture_id", flat=True)
125125
)
126126
assert [i["id"] for i in res.json()["results"]] == expected

sas/tests/test_views.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ def test_album_access_non_subscriber(client: Client):
7070
class TestSasModeration(TestCase):
7171
@classmethod
7272
def setUpTestData(cls):
73-
album = baker.make(
74-
Album, parent_id=settings.SITH_SAS_ROOT_DIR_ID, is_moderated=True
75-
)
73+
album = baker.make(Album)
7674
cls.pictures = picture_recipe.make(
7775
parent=album, _quantity=10, _bulk_create=True
7876
)

0 commit comments

Comments
 (0)