def test_delete_an_existing_group(self): ''' If a group exists, I should be able to delete it and not get it back ''' groups.save(self.valid) groups.delete(self.valid['name']) group = groups.find_one(self.valid['name']) self.assertEquals(group, None)
def test_save_updates_existing_group(self): '''saving a group that exists, will update its members''' groups.save(self.valid) group = groups.find_one(self.valid['name']) self.assertEquals(group, self.valid) groups.save(self.updated_valid) group = groups.find_one(self.valid['name']) self.assertEquals(group, self.updated_valid)
def post(self, group_name): """ Create a new Group, must provide only Name """ args = request.json data, errors = self.validate(args) if errors: logger.error(errors) return errors, 400 logger.error(data) groups.save(data) return args, 201
def post(self, group_name): """ Create a new Group, must provide only Name """ args = request.json data, errors = self.validate(args) if errors: logger.error(errors) return errors, 400 logger.error(data) groups.save(data) return args, 201
def setUp(self): self.existing_user = {"username": "******", "first_name": "Gunea", "last_name": "Pig", "email": ["*****@*****.**"], "password": "******", "hosts": ['babbage.ug.eie.wits.ac.za'], "yos": "3"} self.existing_user2 = {"username": "******", "first_name": "John", "last_name": "Doe", "email": ["*****@*****.**"], "password": "******", "hosts": ['dummy'], "gid_number": "4000", "uid_number": "4001", "login_shell": "/bin/bash", "home_directory": "/home/ug/johnd", "yos": "4"} users.delete(self.existing_user['username']) users.delete(self.existing_user2['username']) users.add(self.existing_user) users.add(self.existing_user2) self.existing_group = {"name": "natsuki", "gid_number": "1000", "description": "Natsuki, like the summer", "members": [self.existing_user['username']]} groups.save(self.existing_group) self.non_existing_user = "******" groups.save(self.existing_group) self.new_member = {"username": "******", "first_name": "John", "last_name": "Doe", "email": ["*****@*****.**"], "password": "******", "hosts": ['dummy'], "yos": "4"}
def test_find_using_valid_group(self): groups.save(self.valid) group = groups.find_one(group=self.valid) self.assertEquals(group, self.valid)
def test_cant_save_group_with_empty_members(self): ''' Because LDAP does not allow creating a group without members, I don't allow it either''' with self.assertRaises(ValueError): groups.save(self.empty_members)
def test_save_with_user_not_in_directory(self): '''cannot save a group which has a member who is not in the LDAP dir''' with self.assertRaises(ValueError): invalid = {"name": "invalid", "members": ["not_there"]} groups.save(invalid)
def test_save_and_find_one(self): '''simple save of a valid group''' groups.save(self.valid) group = groups.find(self.valid['name']) self.assertEquals(group, self.valid)
def test_find_can_specify_wrong_name_and_correct_group(self): '''will return one group if attributes are valid''' groups.save(self.valid) group = groups.find_one(name='aslkajsa', group=self.valid) self.assertEquals(group, self.valid)
def test_find_can_specify_both_name_and_group(self): '''should use names if both name and group are given''' groups.save(self.valid) group = groups.find_one(name=self.valid['name'], group=self.no_members) self.assertEquals(group, self.valid)