forked from saleor/saleor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_collection.py
56 lines (42 loc) · 1.96 KB
/
test_collection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import date, timedelta
from django.urls import reverse
from .utils import get_redirect_location
def test_collection_index(client, collection):
url_kwargs = {"pk": collection.id, "slug": collection.slug}
url = reverse("product:collection", kwargs=url_kwargs)
response = client.get(url)
assert response.status_code == 200
def test_collection_incorrect_slug(client, collection):
"""When entered on the collection with proper PK but incorrect slug,
one should be permanently(301) redirected to the proper url.
"""
url_kwargs = {"pk": collection.id, "slug": "incorrect-slug"}
url = reverse("product:collection", kwargs=url_kwargs)
response = client.get(url)
# User should be redirected to the proper url
assert response.status_code == 301
redirected_url = get_redirect_location(response)
proper_kwargs = {"pk": collection.id, "slug": collection.slug}
proper_url = reverse("product:collection", kwargs=proper_kwargs)
assert redirected_url == proper_url
def test_collection_not_exists(client):
url_kwargs = {"pk": 123456, "slug": "incorrect-slug"}
url = reverse("product:collection", kwargs=url_kwargs)
response = client.get(url)
assert response.status_code == 404
def test_collection_not_yet_published_returns_404(
admin_client, client, draft_collection
):
url_kwargs = {"pk": draft_collection.pk, "slug": draft_collection.slug}
url = reverse("product:collection", kwargs=url_kwargs)
response = client.get(url)
assert response.status_code == 404
draft_collection.is_published = True
draft_collection.publication_date = date.today() + timedelta(days=1)
draft_collection.save()
# A non staff user should not have access to collections yet to be published
response = client.get(url)
assert response.status_code == 404
# A staff user should have access to collections yet to be published
response = admin_client.get(url)
assert response.status_code == 200