Created
August 16, 2020 16:41
-
-
Save fredkingham/551e85818063dd853715b1d8ea4aca6b to your computer and use it in GitHub Desktop.
A quick script to check the api end points for the last 100 patients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from django.test.client import RequestFactory | |
from rest_framework.test import force_authenticate | |
from django.contrib.auth.models import User | |
from rest_framework.reverse import reverse | |
from opal.models import Patient | |
from elcid.api import InfectionServiceTestSummaryApi, LabTestResultsView | |
from plugins.covid.api import CovidServiceTestSummaryAPI | |
def time_get(view_cls, url_name, patient): | |
view = view_cls.as_view({'get': 'retrieve'}) | |
request = get_request() | |
response = view_cls().retrieve(request, patient.id) | |
if not response.status_code == 200: | |
import ipdb; ipdb.set_trace() | |
raise ValueError('fail') | |
def get_request(url="/"): | |
request = RequestFactory().get(url) | |
request.user = User.objects.last() | |
return request | |
def test_patients(view_cls, url_name): | |
patients = Patient.objects.exclude( | |
lab_tests=None | |
).order_by("-id")[:100] | |
start_time = time.time() | |
for patient in patients: | |
time_get(view_cls, url_name, patient) | |
end_time = time.time() | |
diff = end_time - start_time | |
print("%s %s (%.02f seconds)" % (view_cls, url_name, diff,)) | |
return diff | |
def test_infection_service_test_summary_api(): | |
view_cls = InfectionServiceTestSummaryApi | |
url_name = "infection_service_summary_api-detail" | |
return test_patients(view_cls, url_name) | |
def test_lab_test_results_view(): | |
view_cls = LabTestResultsView | |
url_name = "lab_test_results_view-detail" | |
return test_patients(view_cls, url_name) | |
def test_covid_service_test_summary_view(): | |
view_cls = CovidServiceTestSummaryAPI | |
url_name = "covid_service_summary_api-detail" | |
return test_patients(view_cls, url_name) | |
def run_test(): | |
test_infection_service_test_summary_api() | |
test_lab_test_results_view() | |
test_covid_service_test_summary_view() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment