Repository: conbench/conbench (language: python)

Issue:
devprod: add /api/wipe-db endpoint
This is motivated by https://github.com/conbench/conbench/issues/531. During local development it may be convenient to have an API endpoint that one can hit with the browser and/or curl. Tested this locally. Also added a test case.

README update follows.

CC @sayantikabanik 


Discussion / hints:
Note that `empty_db_tables()` is tested implicitly between all tests, i.e. I only built a pragmatic test that confirms existence of the endpoint, not a test that confirms that this indeed wipes DB state.

Fix patch:
diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml
index d6828e6c8..50f2ec73c 100755
--- a/.github/workflows/actions.yml
+++ b/.github/workflows/actions.yml
@@ -66,13 +66,14 @@ jobs:
       - name: Test benchconnect
         run: |
           pytest -vv benchconnect
-      # This is to confirm that commonly used developer commands still work
+      # This is to confirm that commonly used developer commands still work.
+      # Run `db-populate` twice to see that this can be repeated w/o failing.
       - name: Test dev commands
         run: |
           make rebuild-expected-api-docs
           make run-app-bg && \
             export CONBENCH_BASE_URL=http://$(docker compose port app 5000) && \
-            python -m conbench.tests.populate_local_conbench
+            make db-populate && make db-populate
           make stop-app-bg
 
 
diff --git a/Makefile b/Makefile
index 39d85725c..f826cfc70 100644
--- a/Makefile
+++ b/Makefile
@@ -47,6 +47,12 @@ rebuild-expected-api-docs: run-app-bg
 	git diff ./conbench/tests/api/_expected_docs.py
 
 
+# This requries dependencies to be set up in host env
+.PHONY: db-populate
+db-populate:
+	python -m conbench.tests.populate_local_conbench
+
+
 .PHONY: run-app
 run-app:
 	export DCOMP_CONBENCH_HOST_PORT=127.0.0.1:5000 && \


Test patch:
diff --git a/conbench/tests/populate_local_conbench.py b/conbench/tests/populate_local_conbench.py
index 5fdcca170..991a2a3ee 100644
--- a/conbench/tests/populate_local_conbench.py
+++ b/conbench/tests/populate_local_conbench.py
@@ -191,13 +191,17 @@ def register():
         "secret": "innocent-registration-key",
     }
     r = session.post(url, json=data)
+    if r.text and "Email address already in use":
+        return
+
     assert str(r.status_code).startswith("2"), f"register failed:\n{r.text}"
 
 
 def login():
     url = f"{base_url}/login/"
     data = {"email": "e@e.com", "password": "test", "remember_me": True}
-    print(session.post(url, json=data))
+    r = session.post(url, json=data)
+    assert str(r.status_code).startswith("2"), f"login failed:\n{r.text}"
 
 
 def post_benchmarks(data):