Commit efcc154a by Calen Pennington

Make SiteConfigurationFactory more useable

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