def test_create_inject_check(self): self.login_user('admin', 'admin') query_data = { "id": "FileSystemSetUp", "description": "Checking if the filesystem was set up on time.", "machine": "Apache", "class_name": "SampleInjectCheck", "inject_number": "66", "time_to_check": convert_datetime_to_timestamp(datetime.now()) } expected_result = [{ "description": "Checking if the filesystem was set up on time.", "machine": "Apache", "class_name": "SampleInjectCheck", "inject_number": "66", "time_to_check": query_data['time_to_check'] }] post = self.app.post('/checks/injects', data=json.dumps(query_data), follow_redirects=True) assert post.status_code == 201 assert post.headers['Location'] == 'http://localhost/checks/injects/FileSystemSetUp' result = self.app.get('/checks/injects/FileSystemSetUp') rest_result = json.loads(result.data) show_difference_between_dicts(rest_result[0], expected_result[0]) assert result.status_code == 200 assert rest_result == expected_result
def test_create_manual_check_for_team_missing_param(self): self.login_user('admin', 'admin') query_data = { "description": "Teams had to make a network policy", "comments": "They did okay on this, but forgot about video sharing sites.", "inject_number": "109", "score": 25, "timestamp": convert_datetime_to_timestamp(datetime.now()) } post_data = { "type": "IllegalParameter", "reason": "Required parameter 'id' is not specified." } expected_data = [obj for obj in self.data['completed_checks'] if obj['type'] == 'manual' and obj['team_id'] == '6'] for i in expected_data: del i['team_id'], i['type'] i['timestamp'] = convert_datetime_to_timestamp(i['timestamp']) post = self.app.post('/checks/manual/teams/6', data=json.dumps(query_data), follow_redirects=True) assert post.status_code == 403 assert json.loads(post.data) == post_data result = self.app.get('/checks/manual/teams/6') assert result.status_code == 200 result_data = json.loads(result.data) assert len(result_data) == len(expected_data) for i, j in zip(result_data, expected_data): show_difference_between_dicts(i, j) assert result_data == expected_data
def test_get_score_for_specific_team(self): self.login_user('admin', 'admin') rest_result = self.app.get('/teams/6/score') assert rest_result.status_code == 200 json_result = json.loads(rest_result.data) expected_result = [obj for obj in self.data['team_scores'] if obj['team_id'] == '6'][0] del expected_result['team_id'] expected_result['timestamp'] = convert_datetime_to_timestamp(expected_result['timestamp']) show_difference_between_dicts(json_result, expected_result) assert json_result == expected_result
def test_get_scores_for_all_teams(self): self.login_user('admin', 'admin') rest_result = self.app.get('/teams/scores') assert rest_result.status_code == 200 expected_result = [obj for obj in self.data['team_scores']] print rest_result.data json_result = json.loads(rest_result.data) assert len(json_result) == len(expected_result) for i in range(0, len(json_result)): expected_result[i]['timestamp'] = convert_datetime_to_timestamp(expected_result[i]['timestamp']) show_difference_between_dicts(json_result[i], expected_result[i]) assert json_result == expected_result
def test_get_all_users_with_role(self): self.login_user('admin', 'admin') result = self.app.get('/users/roles/administrator') result_data = [obj for obj in self.data['users'] if obj['role'] == 'administrator'] for i in result_data: del i['role'], i['password'] assert result.status_code == 200 json_result = json.loads(result.data) assert len(json_result) == len(result_data) for i, j in zip(json_result, result_data): show_difference_between_dicts(i, j) assert json_result == result_data
def test_get_specific_manual_check_for_specific_team(self): self.login_user('admin', 'admin') rest_result = self.app.get('/checks/manual/BoardPresentation/teams/1') print rest_result.status_code, rest_result.data assert rest_result.status_code == 200 expected_result = [obj for obj in self.data['completed_checks'] if obj['type'] == 'manual' and obj['team_id'] == '1' and obj['id'] == 'BoardPresentation'] json_result = json.loads(rest_result.data) assert len(json_result) == len(expected_result) for i, j in zip(expected_result, json_result): del i['team_id'], i['type'], i['id'] convert_all_datetime_to_timestamp(i, ['timestamp', 'time_to_check']) show_difference_between_dicts(i, j) assert json_result == expected_result
def test_stop_current_scoring_session(self): self.db_wrapper.start_current_scoring_session() end_time = datetime.now() self.db_wrapper.stop_current_scoring_session() wrapper_result = list(self.db.session.find({}, {'_id': 0})) expected_result = [{ 'start_time': wrapper_result[0]['start_time'], 'end_time': end_time, 'state': 'stopped' }] assert len(wrapper_result) == len(expected_result) for i in range(0, len(wrapper_result)): self.correct_imprecise_time(wrapper_result[i], expected_result[i], 'start_time') self.correct_imprecise_time(wrapper_result[i], expected_result[i], 'end_time') show_difference_between_dicts(wrapper_result[i], expected_result[i]) assert wrapper_result == expected_result