From 4e6761af1709f45bb540a8c395265ca3dda64062 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Thu, 29 Feb 2024 16:31:45 +0530 Subject: [PATCH] new fixture file & pr template --- README.md | 3 ++ conftest.py | 2 +- pull_request_template.md | 8 +++-- tests/test_public_endpoints.py | 53 ++++++++++++++++------------------ 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index a2fbe6a7a..322e83718 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,9 @@ pg_restore --no-privileges --no-owner -d $PGDATABASE $fname cid=$(docker ps | grep gooey-api-prod | cut -d " " -f 1 | head -1) # exec the script to create the fixture docker exec -it $cid poetry run ./manage.py runscript create_fixture +``` + +```bash # copy the fixture outside container docker cp $cid:/app/fixture.json . # print the absolute path diff --git a/conftest.py b/conftest.py index 8eeb53b20..212b6a7c1 100644 --- a/conftest.py +++ b/conftest.py @@ -45,7 +45,7 @@ def _mock_gui_runner( @pytest.fixture -def threadpool_subtest(subtests, max_workers: int = 64): +def threadpool_subtest(subtests, max_workers: int = 128): ts = [] def submit(fn, *args, msg=None, **kwargs): diff --git a/pull_request_template.md b/pull_request_template.md index a41f54e12..38cff8c3d 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -1,10 +1,12 @@ ### Q/A checklist -- [ ] Do a code review of the changes -- [ ] Add any new dependencies to poetry & export to requirementst.txt (`poetry export -o requirements.txt`) +- [ ] Run tests after placing [fixutre.json](https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/ca0f13b8-d6ed-11ee-870b-8e93953183bb/fixture.json) in your project root +```bash +ulimit -n unlimited && pytest +``` +- [ ] Do a self code review of the changes - [ ] Carefully think about the stuff that might break because of this change - [ ] The relevant pages still run when you press submit -- [ ] If you added new settings / knobs, the values get saved if you save it on the UI - [ ] The API for those pages still work (API tab) - [ ] The public API interface doesn't change if you didn't want it to (check API tab > docs page) - [ ] Do your UI changes (if applicable) look acceptable on mobile? diff --git a/tests/test_public_endpoints.py b/tests/test_public_endpoints.py index be18647d8..31d4abea2 100644 --- a/tests/test_public_endpoints.py +++ b/tests/test_public_endpoints.py @@ -2,7 +2,7 @@ from starlette.routing import Route from starlette.testclient import TestClient -from bots.models import SavedRun +from bots.models import PublishedRun, Workflow from daras_ai_v2.all_pages import all_api_pages from daras_ai_v2.tabs_widget import MenuTabs from routers import facebook_api @@ -31,39 +31,36 @@ @pytest.mark.django_db -@pytest.mark.parametrize("path", route_paths) -def test_all_get(path): +def test_all_get(threadpool_subtest): + for path in route_paths: + threadpool_subtest(_test_get_path, path) + + +def _test_get_path(path): r = client.get(path, allow_redirects=False) assert r.ok -page_slugs = [slug for page_cls in all_api_pages for slug in page_cls.slug_versions] -tabs = list(MenuTabs.paths.values()) +@pytest.mark.django_db +def test_all_slugs(threadpool_subtest): + for page_cls in all_api_pages: + for slug in page_cls.slug_versions: + for tab in MenuTabs.paths.values(): + url = f"/{slug}/{tab}" + threadpool_subtest(_test_post_path, url) @pytest.mark.django_db -@pytest.mark.parametrize("slug", page_slugs) -@pytest.mark.parametrize("tab", tabs) -def test_page_slugs(slug, tab): - r = client.post( - f"/{slug}/{tab}", - json={}, - allow_redirects=True, - ) - assert r.status_code == 200 +def test_all_examples(threadpool_subtest): + qs = PublishedRun.objects.exclude( + is_approved_example=False, published_run_id="" + ).order_by("workflow") + for pr in qs: + slug = Workflow(pr.workflow).page_cls.slug_versions[-1] + url = f"/{slug}?example_id={pr.published_run_id}" + threadpool_subtest(_test_post_path, url) -@pytest.mark.django_db -def test_example_slugs(subtests): - for page_cls in all_api_pages: - for tab in tabs: - for example_id in SavedRun.objects.filter( - workflow=page_cls.workflow, - hidden=False, - example_id__isnull=False, - ).values_list("example_id", flat=True): - slug = page_cls.slug_versions[0] - url = f"/{slug}/{tab}?example_id={example_id}" - with subtests.test(msg=url): - r = client.post(url, json={}, allow_redirects=True) - assert r.status_code == 200 +def _test_post_path(url): + r = client.post(url, json={}, allow_redirects=True) + assert r.status_code == 200