Make SiteConfigurationFactory more useable
This commit is contained in:
@@ -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,10 +3,23 @@ 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 SiteFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory class for Site model
|
||||
"""
|
||||
class Meta(object):
|
||||
model = Site
|
||||
django_get_or_create = ('domain',)
|
||||
|
||||
domain = Sequence('testserver.fake.{}'.format)
|
||||
name = SelfAttribute('domain')
|
||||
|
||||
|
||||
class SiteConfigurationFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory class for SiteConfiguration model
|
||||
@@ -16,17 +29,4 @@ class SiteConfigurationFactory(DjangoModelFactory):
|
||||
|
||||
values = {}
|
||||
enabled = True
|
||||
|
||||
|
||||
class SiteFactory(DjangoModelFactory):
|
||||
"""
|
||||
Factory class for Site model
|
||||
"""
|
||||
class Meta(object):
|
||||
model = Site
|
||||
django_get_or_create = ('domain',)
|
||||
|
||||
# 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'
|
||||
site = SubFactory(SiteFactory)
|
||||
|
||||
Reference in New Issue
Block a user