def test_init_parse_url(self): api_key = '' url = 'https://markus.com/api/users?id=1' obj = Markus(api_key, url) assert obj.parsed_url.scheme == 'https' assert obj.parsed_url.netloc == 'markus.com' assert obj.parsed_url.path == '/api/users' assert obj.parsed_url.query == 'id=1'
def run_test(markus_address, server_api_key, test_scripts, hooks_script, files_path, assignment_id, group_id, group_repo_name, submission_id, run_id, enqueue_time): """ Run autotesting tests using the tests in test_scripts on the files in files_path. This function should be used by an rq worker. """ results = [] error = None time_to_service = int(round(time.time() - enqueue_time, 3) * 1000) test_script_path = test_script_directory(markus_address, assignment_id) hooks_script_path = os.path.join(test_script_path, hooks_script) if hooks_script else None hooks_module, all_hooks_error = load_hooks(hooks_script_path) if hooks_script_path else (None, '') api = Markus(server_api_key, markus_address) try: job = rq.get_current_job() update_pop_interval_stat(job.origin) with tester_user() as user_data: test_username = user_data.get('username') tests_path = user_data['worker_dir'] hooks_kwargs = {'api': api, 'tests_path': tests_path, 'assignment_id': assignment_id, 'group_id': group_id, 'group_repo_name' : group_repo_name} try: setup_files(files_path, tests_path, test_scripts, hooks_script, markus_address, assignment_id) all_hooks_error += run_hooks(hooks_module, HOOK_NAMES['before_all'], kwargs=hooks_kwargs) cmd = test_run_command(test_username=test_username) results = run_test_scripts(cmd, test_scripts, tests_path, test_username, hooks_module, hook_kwargs=hooks_kwargs) finally: stop_tester_processes(test_username) all_hooks_error += run_hooks(hooks_module, HOOK_NAMES['after_all'], kwargs=hooks_kwargs) clear_working_directory(tests_path, test_username) except Exception as e: error = str(e) finally: results_data = finalize_results_data(results, error, all_hooks_error, time_to_service) store_results(results_data, markus_address, assignment_id, group_id, submission_id) report(results_data, api, assignment_id, group_id, run_id)
Criteria titles need to be properly formatted, as they appear in the assignment's marking scheme (punctuation included). Marks need to be valid numerics, or 'nil'. If the criterion is a Rubric, the mark just needs to be the rubric level, and will be multiplied by the weight automatically. """ d = {'My Criterion 1.': 1.0, 'My Criterion 2.': 'nil'} return d """ --------Ideally, nothing below need be touched-------- """ if __name__ == '__main__': # Initialize an instance of the API class api = Markus(API_KEY, ROOT_URL) print('Initialized Markus object successfully.') groups = api.get_groups(ASSIGNMENT_ID) for group in groups: group_name = group['group_name'] group_id = group['id'] try: with open(os.path.join(ROOT_DIR, group_name, FILE_NAME)) as open_file: file_contents = open_file.read() # Upload the feedback file try: response = api.upload_feedback_file( ASSIGNMENT_ID, group_id, FILE_NAME, file_contents) print(
def dummy_markus(scheme='http'): return Markus('', f'{scheme}://localhost:8080')
def run_test( markus_address, server_api_key, test_categories, files_path, assignment_id, group_id, group_repo_name, submission_id, run_id, enqueue_time, ): """ Run autotesting tests using the tests in the test_specs json file on the files in files_path. This function should be used by an rq worker. """ results = [] error = None hooks_error = None time_to_service = int(round(time.time() - enqueue_time, 3) * 1000) test_script_path = test_script_directory(markus_address, assignment_id) hooks_script_path = os.path.join(test_script_path, HOOKS_FILENAME) test_specs_path = os.path.join(test_script_path, SETTINGS_FILENAME) api = Markus(server_api_key, markus_address) with open(test_specs_path) as f: test_specs = json.load(f) try: job = rq.get_current_job() update_pop_interval_stat(job.origin) test_username, tests_path = tester_user() hooks_kwargs = { "api": api, "assignment_id": assignment_id, "group_id": group_id, } testers = { settings["tester_type"] for settings in test_specs["testers"] } hooks = Hooks(hooks_script_path, testers, cwd=tests_path, kwargs=hooks_kwargs) try: setup_files(files_path, tests_path, markus_address, assignment_id) cmd = run_test_command(test_username=test_username) results, hooks_error = run_test_specs(cmd, test_specs, test_categories, tests_path, test_username, hooks) finally: stop_tester_processes(test_username) clear_working_directory(tests_path, test_username) except Exception as e: error = str(e) finally: results_data = finalize_results_data(results, error, hooks_error, time_to_service) store_results(results_data, markus_address, assignment_id, group_id, submission_id) report(results_data, api, assignment_id, group_id, run_id)