Skip to content

Commit

Permalink
new fixture file & pr template
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 29, 2024
1 parent e168d7d commit 4e6761a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 5 additions & 3 deletions pull_request_template.md
Original file line number Diff line number Diff line change
@@ -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?
53 changes: 25 additions & 28 deletions tests/test_public_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 4e6761a

Please sign in to comment.