def setUp(self): self.users = Users() self.envs = Environments() self.values = Values()
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)