def test_external_domain_already_registered(self, new_domain, registered_domain): """ Validate that the user cannot register a subdomain for an already registered domain. """ instance_factory(sub_domain=registered_domain.split(".")[0], external_lms_domain=registered_domain) with self.assertRaises(ValidationError) as exc: validate_available_external_domain(new_domain) self.assertEqual(exc.exception.message, 'This domain is already taken.') self.assertEqual(exc.exception.code, 'unique')
def test_subdomain_is_taken_by_instance(self, mock_gandi_api): """ Validate that a taken subdomain raises validation error. """ subdomain = "mysubdomain" mock_gandi_api.filter_dns_records.return_value = [] instance_factory(sub_domain=subdomain) with self.assertRaises(ValidationError) as exc: validate_available_subdomain(subdomain) self.assertEqual(exc.exception.message, 'This domain is already taken.') self.assertEqual(exc.exception.code, 'unique') self.assertFalse(mock_gandi_api.filter_dns_records.called)
def test_instance_factory(self): """ Test that factory function for creating instances produces expected results """ # Create instance without changing defaults sub_domain = "sandbox-with-defaults" instance = instance_factory(sub_domain=sub_domain) instance = OpenEdXInstance.objects.get(pk=instance.pk) self._assert_field_values(instance, sub_domain) # Create instance with custom field values sub_domain = "sandbox-customized" custom_instance = instance_factory(sub_domain=sub_domain, **self.PRODUCTION_DEFAULTS) custom_instance = OpenEdXInstance.objects.get(pk=custom_instance.pk) self._assert_field_values(custom_instance, sub_domain, **self.PRODUCTION_DEFAULTS) # Calling factory without specifying "sub_domain" should result in an error with self.assertRaises(AssertionError): instance_factory()