Example #1
0
class TestEnvironments(TestCase):
    def setUp(self):
        self.envs = Environments()

    def test_create_root(self):
        root_id = self.envs.create_root('cityhall', 'test_root')
        entry = Value.objects.get(
            author='cityhall', parent=-1, name='test_root', active=True
        )
        self.assertGreater(entry.id, 0)
        self.assertEqual('', entry.override)
        self.assertIsNotNone(entry.datetime)
        self.assertEqual('', entry.entry)
        self.assertFalse(entry.protect)
        self.assertTrue(entry.first_last)
        self.assertEqual(root_id, entry.id)

    def test_get_env_root(self):
        self.envs.create_root('cityhall', 'test_root')
        entry = Value.objects.get(
            author='cityhall', parent=-1, name='test_root', active=True
        )
        env_root = self.envs.get_env_root('test_root')
        self.assertEqual(entry.id, env_root)

    def test_cannot_create_same_env_twice(self):
        id1 = self.envs.create_root('cityhall', 'test_root')
        id2 = self.envs.create_root('cityhall', 'test_root')
        self.assertTrue(id1)
        self.assertFalse(id2)