def test_task_result_overview_serializer(user_client): from schedule.models import ScheduleEntry create_task_results(1, user_client) entry = ScheduleEntry.objects.get() context = {'request': None} r = TaskResultsOverviewSerializer(entry, context=context).data # TODO: complete assertions assert r
def test_task_result_serializer(user_client): create_task_results(1, user_client) tr = TaskResult.objects.get() context = {'request': None} r = TaskResultSerializer(tr, context=context).data assert r['task_id'] == 1 assert r['url'] == '/api/v1/results/test/1/' assert r['detail'] == '' assert r['result'] == 'success' assert r['duration'] == '00:00:00.000001'
def test_cannot_delete_result_details(user_client): """Results are read-only.""" entry_name = create_task_results(1, user_client) url = reverse_result_detail(entry_name, 1) response = user_client.delete(url, **HTTPS_KWARG) validate_response(response, status.HTTP_405_METHOD_NOT_ALLOWED)
def test_single_result_response(user_client): entry_name = create_task_results(1, user_client) result, = get_result_list(user_client, entry_name) task_id = 1 expected_url = reverse_result_detail(entry_name, task_id) assert result['url'] == expected_url assert result['task_id'] == task_id
def test_multiple_result_response(user_client, test_scheduler): entry_name = create_task_results(3, user_client) results = get_result_list(user_client, entry_name) assert len(results) == 3 for i, acq in enumerate(results, start=1): expected_url = reverse_result_detail(entry_name, i) assert acq['url'] == expected_url assert acq['task_id'] == i
def test_delete_list(user_client): # If result doesn't exist, expect 405 url = reverse_result_list('doesntexist') response = user_client.delete(url, **HTTPS_KWARG) validate_response(response, status.HTTP_405_METHOD_NOT_ALLOWED) # If result does exist, expect 405 entry_name = create_task_results(1, user_client) url = reverse_result_list(entry_name) response = user_client.delete(url, **HTTPS_KWARG) validate_response(response, status.HTTP_405_METHOD_NOT_ALLOWED)
def test_max_results(user_client): """TaskResults are not managed by user, so oldest should be deleted.""" create_task_results(TEST_MAX_TASK_RESULTS + 10, user_client) assert TaskResult.objects.count() == TEST_MAX_TASK_RESULTS
def test_str(user_client): create_task_results(1, user_client) str(TaskResult.objects.get())
def test_can_view_own_result_details(user_client): """A user should be able to view results they create.""" entry_name = create_task_results(1, user_client) url = reverse_result_detail(entry_name, 1) response = user_client.get(url, **HTTPS_KWARG) validate_response(response, status.HTTP_200_OK)
def test_admin_get_overview(admin_client): create_task_results(2, admin_client) overview, = get_results_overview(admin_client) assert overview['results_available'] == 2 assert overview['results'] # is non-empty string assert overview['schedule_entry'] # is non-empty string