-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maykinmedia/objects-api#481] Fix old tests
- Loading branch information
1 parent
bae8e82
commit 952b2b2
Showing
12 changed files
with
204 additions
and
169 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/objecttypes/setup_configuration/tests/files/sites/invalid_setup.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
objecttypes_site_config_enable: true | ||
objecttypes_sites: | ||
items: |
8 changes: 8 additions & 0 deletions
8
src/objecttypes/setup_configuration/tests/files/sites/valid_setup.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
objecttypes_site_config_enable: true | ||
objecttypes_sites: | ||
items: | ||
- domain: example-1.com | ||
name: example-1 | ||
|
||
- domain: example-2.com | ||
name: example-2 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
93 changes: 93 additions & 0 deletions
93
src/objecttypes/setup_configuration/tests/test_site_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from pathlib import Path | ||
|
||
from django.contrib.sites.models import Site | ||
from django.test import TestCase | ||
|
||
from django_setup_configuration.exceptions import ( | ||
ConfigurationRunFailed, | ||
PrerequisiteFailed, | ||
) | ||
from django_setup_configuration.test_utils import build_step_config_from_sources | ||
|
||
from objecttypes.setup_configuration.steps import SitesConfigurationStep | ||
|
||
DIR_FILES = (Path(__file__).parent / "files/sites").resolve() | ||
|
||
|
||
class SitesConfigurationStepTests(TestCase): | ||
def test_valid_setup_default(self): | ||
sites = Site.objects.order_by("pk") | ||
site = sites[0] | ||
self.assertEqual(sites.count(), 1) | ||
self.assertEqual(site.domain, "example.com") | ||
self.assertEqual(site.name, "example.com") | ||
|
||
setup_config = build_step_config_from_sources( | ||
SitesConfigurationStep, | ||
str(DIR_FILES / "valid_setup.yaml"), | ||
) | ||
step = SitesConfigurationStep() | ||
step.execute(setup_config) | ||
|
||
sites = Site.objects.order_by("pk") | ||
self.assertEqual(sites.count(), 3) | ||
|
||
site = sites[1] | ||
self.assertEqual(site.domain, "example-1.com") | ||
self.assertEqual(site.name, "example-1") | ||
|
||
site = sites[2] | ||
self.assertEqual(site.domain, "example-2.com") | ||
self.assertEqual(site.name, "example-2") | ||
|
||
def test_valid_update_existing_sites(self): | ||
sites = Site.objects.order_by("pk") | ||
site = sites[0] | ||
self.assertEqual(sites.count(), 1) | ||
self.assertEqual(site.domain, "example.com") | ||
self.assertEqual(site.name, "example.com") | ||
|
||
Site.objects.create(domain="example-2.com", name="example-3") | ||
sites = Site.objects.order_by("pk") | ||
self.assertEqual(sites.count(), 2) | ||
|
||
setup_config = build_step_config_from_sources( | ||
SitesConfigurationStep, | ||
str(DIR_FILES / "valid_setup.yaml"), | ||
) | ||
step = SitesConfigurationStep() | ||
step.execute(setup_config) | ||
|
||
sites = Site.objects.order_by("pk") | ||
self.assertEqual(sites.count(), 3) | ||
|
||
site = sites[1] | ||
self.assertEqual(site.domain, "example-2.com") | ||
self.assertEqual(site.name, "example-2") | ||
|
||
site = sites[2] | ||
self.assertEqual(site.domain, "example-1.com") | ||
self.assertEqual(site.name, "example-1") | ||
|
||
def test_invalid_setup_empty(self): | ||
sites = Site.objects.order_by("pk") | ||
site = sites[0] | ||
self.assertEqual(sites.count(), 1) | ||
self.assertEqual(site.domain, "example.com") | ||
self.assertEqual(site.name, "example.com") | ||
|
||
with self.assertRaises(PrerequisiteFailed) as command_error: | ||
setup_config = build_step_config_from_sources( | ||
SitesConfigurationStep, | ||
str(DIR_FILES / "invalid_setup.yaml"), | ||
) | ||
step = SitesConfigurationStep() | ||
step.execute(setup_config) | ||
|
||
self.assertTrue("Input should be a valid list" in str(command_error.exception)) | ||
|
||
sites = Site.objects.order_by("pk") | ||
site = sites[0] | ||
self.assertEqual(sites.count(), 1) | ||
self.assertEqual(site.domain, "example.com") | ||
self.assertEqual(site.name, "example.com") |
Oops, something went wrong.