Exemple #1
0
 def test_create_by_signature(self):
     # Non existant config
     non_existant = {
         "setting1": "created",
     }
     signature = CommunityMock.get_signature_from_input(
         "test", **non_existant)
     community = CommunityMock.objects.create_by_signature(
         signature, **non_existant)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertEqual(community.config.setting1, "created")
     # Static config should create duplicate
     constant_config = {
         "setting1": "const",
     }
     signature = CommunityMock.get_signature_from_input(
         "test", **constant_config)
     community = CommunityMock.objects.create_by_signature(
         signature, **constant_config)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertEqual(community.config.setting1, "const")
     self.assertEqual(
         CommunityMock.objects.filter(signature=signature).count(), 2)
Exemple #2
0
 def test_get_signature_from_input(self):
     # Legal and illegal config mixed
     signature = CommunityMock.get_signature_from_input("test",
                                                        setting1="const",
                                                        illegal="please")
     self.assertEqual(signature, "setting1=const&test")
     # With variable config
     signature = CommunityMock.get_signature_from_input(
         "test", **{"$setting2": "variable"})
     self.assertEqual(signature, "test")
Exemple #3
0
 def test_configuration_from_input(self):
     # Legal and illegal config mixed
     configuration = CommunityMock.get_configuration_from_input(
         "test", setting1="const", illegal="please")
     self.assertIsInstance(configuration, dict)
     self.assertEqual(configuration["setting1"], "const")
     self.assertNotIn("illegal", configuration)
     # With variable config
     configuration = CommunityMock.get_configuration_from_input(
         "test", **{"$setting2": "variable"})
     self.assertIsInstance(configuration, dict)
     self.assertEqual(configuration["$setting2"], "variable")
Exemple #4
0
 def test_get_latest_or_create_by_signature(self):
     # Static config with an illegal key
     constant_config = {"setting1": "const", "illegal": "please"}
     signature = CommunityMock.get_signature_from_input(
         "test", **constant_config)
     community, created = CommunityMock.objects.get_latest_or_create_by_signature(
         signature, **constant_config)
     self.assertIsInstance(community, CommunityMock)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertFalse(created)
     self.assertEqual(community.config.setting1, "const")
     self.assertFalse(hasattr(community.config, "illegal"))
     # Variable config
     variable_config = {"$setting2": "variable"}
     signature = CommunityMock.get_signature_from_input(
         "test", **variable_config)
     community, created = CommunityMock.objects.get_latest_or_create_by_signature(
         signature, **variable_config)
     self.assertIsInstance(community, CommunityMock)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertFalse(created)
     self.assertTrue(hasattr(community.config, "$setting2"))
     # Non existant config
     non_existant = {
         "setting1": "created",
     }
     signature = CommunityMock.get_signature_from_input(
         "test", **non_existant)
     community, created = CommunityMock.objects.get_latest_or_create_by_signature(
         signature, **non_existant)
     self.assertIsInstance(community, CommunityMock)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertTrue(created)
     self.assertEqual(community.config.setting1, "created")
     # Multiple instances with signature
     variable_config = {"$setting2": "variable"}
     signature = CommunityMock.get_signature_from_input(
         "test-multiple", **variable_config)
     community, created = CommunityMock.objects.get_latest_or_create_by_signature(
         signature, **variable_config)
     self.assertIsInstance(community, CommunityMock)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertFalse(created)
     self.assertTrue(hasattr(community.config, "$setting2"))
     self.assertEqual(format_datetime(community.created_at),
                      "20150605161754000000")
Exemple #5
0
 def test_create_by_signature(self):
     # Non existant config
     non_existant = {
         "setting1": "created",
     }
     signature = CommunityMock.get_signature_from_input("test", **non_existant)
     community = CommunityMock.objects.create_by_signature(signature, **non_existant)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertEqual(community.config.setting1, "created")
     # Static config should create duplicate
     constant_config = {
         "setting1": "const",
     }
     signature = CommunityMock.get_signature_from_input("test", **constant_config)
     community = CommunityMock.objects.create_by_signature(signature, **constant_config)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertEqual(community.config.setting1, "const")
     self.assertEqual(CommunityMock.objects.filter(signature=signature).count(), 2)
Exemple #6
0
 def test_get_signature_from_input(self):
     input_configuration = {
         "setting0": "possible?!",
         "$setting2": "variable",
         "setting1": "const",
         "illegal": "please",
         "setting3": "growth",
         "$setting4": "input"
     }
     signature = CommunityMock.get_signature_from_input("test", **input_configuration)
     self.assertEqual(signature, "setting1=const&test")
Exemple #7
0
 def test_get_latest_or_create_by_signature(self):
     # Static config with an illegal key
     constant_config = {
         "setting0": "possible?!",
         "setting1": "const",
         "illegal": "please",
         "$setting2": "variable"
     }
     signature = CommunityMock.get_signature_from_input("test", **constant_config)
     community, created = CommunityMock.objects.get_latest_or_create_by_signature(signature, **constant_config)
     self.assertIsInstance(community, CommunityMock)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertFalse(created)
     self.assertEqual(community.config.setting1, "const")
     self.assertFalse(hasattr(community.config, "illegal"))
     self.assertFalse(hasattr(community.config, "setting0"))
     self.assertFalse(hasattr(community.config, "$setting2"))
     # Non existent config
     non_existent = {
         "setting1": "created",
     }
     signature = CommunityMock.get_signature_from_input("test", **non_existent)
     community, created = CommunityMock.objects.get_latest_or_create_by_signature(signature, **non_existent)
     self.assertIsInstance(community, CommunityMock)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertTrue(created)
     self.assertEqual(community.config.setting1, "created")
     # Multiple instances with signature
     constant_config = {
         "setting1": "const",
     }
     signature = CommunityMock.get_signature_from_input("test-multiple", **constant_config)
     community, created = CommunityMock.objects.get_latest_or_create_by_signature(signature, **constant_config)
     self.assertIsInstance(community, CommunityMock)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertFalse(created)
     self.assertTrue(hasattr(community.config, "setting1"))
     self.assertEqual(format_datetime(community.created_at), "20150605161754000000")
Exemple #8
0
 def test_get_signature_from_input(self):
     input_configuration = {
         "setting0": "possible?!",
         "$setting2": "variable",
         "setting1": "const",
         "illegal": "please",
         "setting3": "growth",
         "$setting4": "input"
     }
     signature = CommunityMock.get_signature_from_input(
         "test", **input_configuration)
     self.assertEqual(signature, "setting1=const&test")
Exemple #9
0
 def test_get_latest_by_signature(self):
     # Static config with an illegal key
     constant_config = {
         "setting0": "possible?!",
         "setting1": "const",
         "illegal": "please",
         "$setting2": "variable"
     }
     signature = CommunityMock.get_signature_from_input("test", **constant_config)
     community = CommunityMock.objects.get_latest_by_signature(signature, **constant_config)
     self.assertIsInstance(community, CommunityMock)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertEqual(community.config.setting1, "const")
     self.assertFalse(hasattr(community.config, "illegal"))
     self.assertFalse(hasattr(community.config, "$setting2"))
     # Non existent config
     non_existent = {
         "setting1": "variable",
     }
     signature = CommunityMock.get_signature_from_input("test", **non_existent)
     try:
         CommunityMock.objects.get_latest_by_signature(signature, **non_existent)
         self.fail("CommunityManager.get_latest_by_signature did not raise with non-existant community")
     except CommunityMock.DoesNotExist:
         pass
     # Multiple instances with signature
     constant_config = {
         "setting1": "const"
     }
     signature = CommunityMock.get_signature_from_input("test-multiple", **constant_config)
     community = CommunityMock.objects.get_latest_by_signature(signature, **constant_config)
     self.assertIsInstance(community, CommunityMock)
     self.assertIsNotNone(community)
     self.assertIsNotNone(community.id)
     self.assertTrue(hasattr(community.config, "setting1"))
     self.assertEqual(format_datetime(community.created_at), "20150605161754000000")
Exemple #10
0
 def test_filter_scope_configuration(self):
     CommunityMock.PUBLIC_CONFIG = {  # TODO: public config is obsolete
         "setting3": "public",
         "$setting4": "public 2"
     }
     input_configuration = {
         "setting0": "possible?!",
         "$setting2": "variable",
         "setting1": "const",
         "illegal": "please",
         "setting3": "growth",
         "$setting4": "input"
     }
     configuration = CommunityMock.filter_scope_configuration("test", **input_configuration)
     self.assertIsInstance(configuration, dict)
     self.assertEqual(configuration["$setting2"], "variable")
     self.assertEqual(configuration["$setting4"], "input")
     self.assertNotIn("setting1", configuration)
     self.assertNotIn("setting3", configuration)
     self.assertNotIn("setting0", configuration)
     self.assertNotIn("illegal", configuration)
     CommunityMock.PUBLIC_CONFIG = None
Exemple #11
0
 def test_filter_scope_configuration(self):
     CommunityMock.PUBLIC_CONFIG = {  # TODO: public config is obsolete
         "setting3": "public",
         "$setting4": "public 2"
     }
     input_configuration = {
         "setting0": "possible?!",
         "$setting2": "variable",
         "setting1": "const",
         "illegal": "please",
         "setting3": "growth",
         "$setting4": "input"
     }
     configuration = CommunityMock.filter_scope_configuration(
         "test", **input_configuration)
     self.assertIsInstance(configuration, dict)
     self.assertEqual(configuration["$setting2"], "variable")
     self.assertEqual(configuration["$setting4"], "input")
     self.assertNotIn("setting1", configuration)
     self.assertNotIn("setting3", configuration)
     self.assertNotIn("setting0", configuration)
     self.assertNotIn("illegal", configuration)
     CommunityMock.PUBLIC_CONFIG = None