def test_update_user_no_name(self): user_data = { 'first_name': 'first', 'last_name': 'user', 'userid': 'foobar', 'groups': [] } response = put(TEST_HOST, TEST_PORT, USERS_URL, '', user_data) self.assertEqual(response.status, 405)
def test_update_user(self): response = get_user(self.user_id) response_string = response.read().decode() response_json = json.loads(response_string) self.assertEqual(response.status, 200) self.assertEqual(response_json, self.old_user_data) response = put(TEST_HOST, TEST_PORT, USERS_URL, self.user_id, self.new_user_data) self.assertEqual(response.status, 200) response = get_user(self.new_user_id) response_string = response.read().decode() response_json = json.loads(response_string) self.assertEqual(response.status, 200) self.assertEqual(response_json, self.new_user_data)
def test_update_group(self): response = get_group(self.group_name) response_string = response.read().decode() response_json = json.loads(response_string) self.assertEqual(response.status, 200) users = response_json['userids'] self.assertTrue(self.user_1_name in users) self.assertTrue(self.user_2_name not in users) new_members = {'userids': [self.user_2_name]} response = put(TEST_HOST, TEST_PORT, GROUPS_URL, self.group_name, new_members) self.assertEqual(response.status, 200) response = get_group(self.group_name) response_string = response.read().decode() response_json = json.loads(response_string) self.assertEqual(response.status, 200) users = response_json['userids'] self.assertTrue(self.user_2_name in users) self.assertTrue(self.user_1_name not in users)
def test_update_user_missing_data(self): response = put(TEST_HOST, TEST_PORT, USERS_URL, self.user_id, {}) self.assertEqual(response.status, 400)
def test_update_group_no_name(self): members = {'userids': []} response = put(TEST_HOST, TEST_PORT, GROUPS_URL, '', members) self.assertEqual(response.status, 405)
def test_update_nonexistent_group(self): members = {'userids': []} response = put(TEST_HOST, TEST_PORT, GROUPS_URL, 'foobar', members) self.assertEqual(response.status, 404)
def test_update_group_missing_members(self): response = put(TEST_HOST, TEST_PORT, GROUPS_URL, self.group_name, {}) self.assertEqual(response.status, 400)