Commit efcc154a by Calen Pennington

Make SiteConfigurationFactory more useable

parent f79e9da0
......@@ -62,15 +62,25 @@ class TestSAMLCommand(TestCase):
# We are creating SAMLConfiguration instance here so that there is always at-least one
# disabled saml configuration instance, this is done to verify that disabled configurations are
# not processed.
SAMLConfigurationFactory.create(enabled=False)
SAMLProviderConfigFactory.create()
SAMLConfigurationFactory.create(enabled=False, site__domain='testserver.fake', site__name='testserver.fake')
SAMLProviderConfigFactory.create(site__domain='testserver.fake', site__name='testserver.fake')
def __create_saml_configurations__(self, saml_config=None, saml_provider_config=None):
"""
Helper method to create SAMLConfiguration and AMLProviderConfig.
"""
SAMLConfigurationFactory.create(enabled=True, **(saml_config or {}))
SAMLProviderConfigFactory.create(enabled=True, **(saml_provider_config or {}))
SAMLConfigurationFactory.create(enabled=True, **(
saml_config or {
'site__domain': 'testserver.fake',
'site__name': 'testserver.fake'
}
))
SAMLProviderConfigFactory.create(enabled=True, **(
saml_provider_config or {
'site__domain': 'testserver.fake',
'site__name': 'testserver.fake'
}
))
def test_raises_command_error_for_invalid_arguments(self):
"""
......@@ -137,9 +147,11 @@ class TestSAMLCommand(TestCase):
self.__create_saml_configurations__(
saml_config={
"site__domain": "second.testserver.fake",
"site__name": "testserver.fake",
},
saml_provider_config={
"site__domain": "second.testserver.fake",
"site__name": "testserver.fake",
"idp_slug": "second-test-shib",
"entity_id": "https://idp.testshib.org/idp/another-shibboleth",
"metadata_source": "https://www.testshib.org/metadata/another-testshib-providers.xml",
......@@ -150,9 +162,11 @@ class TestSAMLCommand(TestCase):
self.__create_saml_configurations__(
saml_config={
"site__domain": "third.testserver.fake",
"site__name": "testserver.fake",
},
saml_provider_config={
"site__domain": "third.testserver.fake",
"site__name": "testserver.fake",
"idp_slug": "third-test-shib",
# Note: This entity id will not be present in returned response and will cause failed update.
"entity_id": "https://idp.testshib.org/idp/non-existent-shibboleth",
......@@ -169,9 +183,11 @@ class TestSAMLCommand(TestCase):
self.__create_saml_configurations__(
saml_config={
"site__domain": "fourth.testserver.fake",
"site__name": "testserver.fake",
},
saml_provider_config={
"site__domain": "fourth.testserver.fake",
"site__name": "testserver.fake",
"idp_slug": "fourth-test-shib",
"automatic_refresh_enabled": False,
# Note: This invalid entity id will not be present in the refresh set
......
......@@ -3,30 +3,30 @@ Model factories for unit testing views or models.
"""
from django.contrib.sites.models import Site
from factory.django import DjangoModelFactory
from factory import SubFactory, Sequence, SelfAttribute
from openedx.core.djangoapps.site_configuration.models import SiteConfiguration
class SiteConfigurationFactory(DjangoModelFactory):
class SiteFactory(DjangoModelFactory):
"""
Factory class for SiteConfiguration model
Factory class for Site model
"""
class Meta(object):
model = SiteConfiguration
model = Site
django_get_or_create = ('domain',)
values = {}
enabled = True
domain = Sequence('testserver.fake.{}'.format)
name = SelfAttribute('domain')
class SiteFactory(DjangoModelFactory):
class SiteConfigurationFactory(DjangoModelFactory):
"""
Factory class for Site model
Factory class for SiteConfiguration model
"""
class Meta(object):
model = Site
django_get_or_create = ('domain',)
model = SiteConfiguration
# TODO These should be generated. Otherwise, code that creates multiple Site
# objects will only end up with a single Site since domain has a unique constraint.
domain = 'testserver.fake'
name = 'testserver.fake'
values = {}
enabled = True
site = SubFactory(SiteFactory)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment