forked from saleor/saleor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_seo_schema.py
66 lines (50 loc) · 1.87 KB
/
test_seo_schema.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
57
58
59
60
61
62
63
64
65
66
import json
import pytest
from saleor.seo.schema.email import (
get_order_confirmation_markup,
get_organization,
get_product_data,
)
def test_get_organization(site_settings):
example_name = "Saleor Brand Name"
site = site_settings.site
site.name = example_name
site.save()
result = get_organization()
assert result["name"] == example_name
def test_get_product_data_without_image(order_with_lines):
"""Tested OrderLine Product has no image assigned."""
line = order_with_lines.lines.first()
organization = get_organization()
result = get_product_data(line, organization)
assert "image" not in result["itemOffered"]
def test_get_product_data_with_image(order_with_lines, product_with_image):
line = order_with_lines.lines.first()
variant = product_with_image.variants.first()
line.variant = variant
line.product_name = str(variant.product)
line.variant_name = str(variant)
line.save()
organization = get_organization()
result = get_product_data(line, organization)
assert "image" in result["itemOffered"]
assert result["itemOffered"]["name"] == variant.display_product()
def test_get_product_data_without_line_variant(order_with_lines):
"""Tested OrderLine Product has no image assigned."""
line = order_with_lines.lines.first()
organization = get_organization()
line.variant = None
line.save()
assert not line.variant
result = get_product_data(line, organization)
assert result == {}
def test_get_order_confirmation_markup(order_with_lines):
try:
result = get_order_confirmation_markup(order_with_lines)
except TypeError:
pytest.fail("Function output is not JSON serializable")
try:
# Response should be returned as a valid json
json.loads(result)
except ValueError:
pytest.fail("Response is not a valid json")