Skip to content

Commit

Permalink
Added an endpoint for reloading a course and added the course reloadi…
Browse files Browse the repository at this point in the history
…ng to the API test data verification.
  • Loading branch information
eriq-augustine committed Nov 22, 2023
1 parent 44b508d commit 57e309a
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 3 deletions.
15 changes: 13 additions & 2 deletions .ci/verify_test_api_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
import sys
import traceback

import autograder.api.config

THIS_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
ROOT_DIR = os.path.join(THIS_DIR, '..')
TEST_DATA_DIR = os.path.join(ROOT_DIR, 'tests', 'api', 'data')

# Add in the tests path.
sys.path.append(ROOT_DIR)

import autograder.api.config
import autograder.api.admin.coursereload
import tests.api.test_api

def verify_test_case(cli_arguments, path):
Expand All @@ -48,6 +48,14 @@ def verify_test_case(cli_arguments, path):

return 0

def reset_course(cli_arguments):
arguments = tests.api.test_api.BASE_ARGUMENTS.copy()
for key, value in vars(cli_arguments).items():
if ((value is not None) or (value)):
arguments[key] = value

autograder.api.admin.coursereload.send(arguments)

def run(arguments):
error_count = 0

Expand All @@ -59,6 +67,9 @@ def run(arguments):
print("Error verifying test '%s'." % (path))
traceback.print_exception(ex)

# Reset the DB after every test.
reset_course(arguments)

if (error_count > 0):
print("Found %d API test case issues." % (error_count))
else:
Expand Down
Empty file.
21 changes: 21 additions & 0 deletions autograder/api/admin/coursereload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import autograder.api.common
import autograder.api.config

API_ENDPOINT = 'admin/course/reload'
API_PARAMS = [
autograder.api.config.PARAM_COURSE_ID,
autograder.api.config.PARAM_USER_EMAIL,
autograder.api.config.PARAM_USER_PASS,
]

DESCRIPTION = 'Reload a course from its config.'

def send(arguments, **kwargs):
return autograder.api.common.handle_api_request(arguments, API_PARAMS, API_ENDPOINT, **kwargs)

def _get_parser():
parser = autograder.api.config.get_argument_parser(
description = DESCRIPTION,
params = API_PARAMS)

return parser
Empty file.
21 changes: 21 additions & 0 deletions autograder/cli/admin/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Commands for administering an autograder course/server.
"""

import os
import sys

import autograder.util.cli

THIS_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))

def run():
print(__doc__.strip())
autograder.util.cli.list_dir(THIS_DIR, 'autograder.cli.admin')
return 0

def main():
return run()

if (__name__ == '__main__'):
sys.exit(main())
17 changes: 17 additions & 0 deletions autograder/cli/admin/course-reload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys

import autograder.api.admin.coursereload

def run(arguments):
autograder.api.admin.coursereload.send(arguments, exit_on_error = True)
print("Course reloaded.")
return 0

def main():
return run(_get_parser().parse_args())

def _get_parser():
return autograder.api.admin.coursereload._get_parser()

if (__name__ == '__main__'):
sys.exit(main())
5 changes: 5 additions & 0 deletions tests/api/data/test_admin_course_reload_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"endpoint": "admin/course/reload",
"arguments": {},
"output": {}
}
6 changes: 5 additions & 1 deletion tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def get_api_test_info(path):
with open(path, 'r') as file:
data = json.load(file)

import_module_name = '.'.join(['autograder', 'api'] + data['endpoint'].split('/'))
parts = data['endpoint'].split('/')
prefix = parts[0]
suffix = ''.join(parts[1:])

import_module_name = '.'.join(['autograder', 'api', prefix, suffix])
expected = data['output']

arguments = BASE_ARGUMENTS.copy()
Expand Down

0 comments on commit 57e309a

Please sign in to comment.