-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathtest_duplicate_pages.py
65 lines (55 loc) · 2.24 KB
/
test_duplicate_pages.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
import pytest
from django.core.management.base import CommandError
from integreat_cms.cms.models import Page, PageTranslation
from ..utils import get_command_output
def test_duplicate_pages_prod():
"""
Ensure that this command does not work in production mode
"""
with pytest.raises(CommandError) as exc_info:
assert not any(get_command_output("duplicate_pages", "region_slug"))
assert str(exc_info.value) == "This command can only be used in DEBUG mode."
def test_duplicate_pages_missing_region_slug(settings):
"""
Ensure that a missing region slug throws an error
"""
settings.DEBUG = True
with pytest.raises(CommandError) as exc_info:
assert not any(get_command_output("duplicate_pages"))
assert (
str(exc_info.value)
== "Error: the following arguments are required: region_slug"
)
@pytest.mark.django_db
def test_duplicate_pages_non_existing_region(settings):
"""
Ensure that a non existing region slug throws an error
"""
settings.DEBUG = True
with pytest.raises(CommandError) as exc_info:
assert not any(get_command_output("duplicate_pages", "non-existing"))
assert str(exc_info.value) == 'Region with slug "non-existing" does not exist.'
@pytest.mark.django_db
def test_duplicate_pages(settings, load_test_data):
"""
Ensure that pages are really duplicated
"""
settings.DEBUG = True
region_slug = "augsburg"
page_count_before = Page.objects.filter(region__slug=region_slug).count()
translations_count_before = PageTranslation.objects.filter(
page__region__slug=region_slug
).count()
out, err = get_command_output("duplicate_pages", "augsburg")
assert '✔ Successfully duplicated pages for region "Stadt Augsburg".' in out
assert not err
page_count_after = Page.objects.filter(region__slug=region_slug).count()
translations_count_after = PageTranslation.objects.filter(
page__region__slug=region_slug
).count()
assert (
page_count_after == 2 * page_count_before
), "The count of pages should have doubled after the command"
assert (
translations_count_after == 2 * translations_count_before
), "The count of page translations should have doubled after the command"