Ejemplo n.º 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)
Ejemplo n.º 2
0
 def setUp(self):
     self.users = Users()
     self.envs = Environments()
     self.values = Values()
Ejemplo n.º 3
0
class TestUsers(TestCase):
    def setUp(self):
        self.users = Users()
        self.envs = Environments()
        self.values = Values()

    def test_create_user(self):
        users_root = self.envs.get_env_root('users')
        user_root = self.values.create('cityhall', users_root, 'test', '')
        self.users.create_user('cityhall', 'test', '', user_root)
        created = User.objects.get(
            active=True,
            name='test',
            author='cityhall',
            password='',
            user_root=user_root,
        )
        self.assertIsNotNone(created.datetime)

    def test_delete_user(self):
        users_root = self.envs.get_env_root('users')
        user_root = self.values.create('cityhall', users_root, 'test', '')
        self.users.create_user('cityhall', 'test', '', user_root)
        self.users.delete_user('cityhall', 'test')

        user_entries = User.objects.filter(name='test')
        self.assertEqual(2, len(user_entries))

    def test_deleted_user_is_invalid(self):
        users_root = self.envs.get_env_root('users')
        user_root = self.values.create('cityhall', users_root, 'test', '')
        self.users.create_user('cityhall', 'test', '', user_root)
        self.users.delete_user('cityhall', 'test')
        self.assertFalse(User.objects.is_valid('test', ''))

    def test_get_users(self):
        users_root = self.envs.get_env_root('users')
        user_root = self.values.create('cityhall', users_root, 'test', '')
        self.users.create_user('cityhall', 'test', '', user_root)

        users_before = self.users.get_users('auto')
        self.assertNotIn('test', users_before)

        self.values.create('cityhall', user_root, 'auto', '1')
        users_after = self.users.get_users('auto')
        self.assertIn('test', users_after)
        self.assertEqual(1, int(users_after['test']))

    def test_update_user(self):
        users_root = self.envs.get_env_root('users')
        user_root = self.values.create('cityhall', users_root, 'test', '')
        self.users.create_user('cityhall', 'test', '', user_root)

        before = User.objects.count()
        self.users.update_user('cityhall', 'test', 'password')
        after = User.objects.count()

        entries = list(User.objects.filter(name='test'))

        self.assertEqual(before+1, after)
        self.assertEqual(2, len(entries))
        self.assertFalse(entries[0].active)
        self.assertTrue(entries[1].active)
        self.assertEqual('password', entries[1].password)
Ejemplo n.º 4
0
 def setUp(self):
     self.envs = Environments()