def test_init(self): """ Test that a UsersController can be built without error. """ controller = controllers.UsersController() self.assertEqual(controller.mapping, {})
def test_update_with_none(self): """ Test that UsersController data can be updated with an empty data set. """ controller = controllers.UsersController() self.assertEqual(controller.mapping, {}) controller.update(user_group_mapping=None) self.assertEqual(controller.mapping, {})
def test_index_user_group_groups(self): """ Test that a UsersController can process an index query with user, groups, and group arguments. """ controller = controllers.UsersController() controller.update(user_group_mapping=[( 'Adam', 'Male'), ('Eve', 'Female'), ('Adam', 'Human'), ('Eve', 'Human')]) kwargs = {'user': '******', 'groups': True, 'group': 'invalid'} self.assertRaisesRegex(cherrypy.HTTPError, "Group not found.", controller.index, **kwargs) controller.index(user='******', groups=True, group='Human')
def test_index_user(self): """ Test that a UsersController can process an index query with a user argument. """ controller = controllers.UsersController() kwargs = {'user': '******'} self.assertRaisesRegex(cherrypy.HTTPError, "User not found.", controller.index, **kwargs) controller.update(user_group_mapping=[( 'Adam', 'Male'), ('Eve', 'Female'), ('Adam', 'Human'), ('Eve', 'Human')]) controller.index(user='******')
def test_index_user_group(self): """ Test that a UsersController can process an index query with user and groups arguments. """ controller = controllers.UsersController() controller.update(user_group_mapping=[( 'Adam', 'Male'), ('Eve', 'Female'), ('Adam', 'Human'), ('Eve', 'Human')]) result = controller.index(user='******', groups=True) self.assertIsInstance(result, dict) self.assertEqual(1, len(result.keys())) self.assertIn('groups', result.keys()) self.assertEqual(2, len(result.get('groups'))) self.assertIn('Male', result.get('groups')) self.assertIn('Human', result.get('groups'))
def test_list(self): """ Test that UsersController data can be accessed via list. """ controller = controllers.UsersController() result = controller.list() self.assertEqual(result, []) controller.update(user_group_mapping=[( 'Adam', 'Male'), ('Eve', 'Female'), ('Adam', 'Human'), ('Eve', 'Human')]) result = controller.list() self.assertEqual(2, len(result)) self.assertIn('Adam', result) self.assertIn('Eve', result)
def test_update_with_data(self): """ Test that UsersController data can be updated with a new data set. """ controller = controllers.UsersController() self.assertEqual(controller.mapping, {}) controller.update(user_group_mapping=[( 'Adam', 'Male'), ('Eve', 'Female'), ('Adam', 'Human'), ('Eve', 'Human')]) self.assertEqual(2, len(controller.mapping.keys())) self.assertIn('Adam', controller.mapping.keys()) self.assertIn('Eve', controller.mapping.keys()) self.assertEqual(2, len(controller.mapping.get('Adam'))) self.assertIn('Male', controller.mapping.get('Adam')) self.assertIn('Human', controller.mapping.get('Adam')) self.assertEqual(2, len(controller.mapping.get('Eve'))) self.assertIn('Female', controller.mapping.get('Eve')) self.assertIn('Human', controller.mapping.get('Eve'))