Repository: openfisca/country-template (language: python)

Issue:
Smoke test the Web API
There was a production incident last week on OpenFisca France, where an inadequate config key prevented the Web API from starting altogether. This would have been caught if the CI had a small test for the web API.

I thus suggest to add a smoke test to the web API, which will check:

1. The API starts with `openfisca serve`.
2. Accessing the `swagger` endpoint returns an HTTP 200 code.
3. The result of the `swagger` endpoint is valid JSON.

This test result should appear as a dedicated step in each PR, along with `check_version_and_changelog` or `lint_yaml_files`.


Discussion / hints:

Fix patch:
diff --git a/.circleci/config.yml b/.circleci/config.yml
index f0e7fc23..4051e4dc 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -51,6 +51,24 @@ jobs:
             git fetch
             .circleci/is-version-number-acceptable.sh
 
+  test_api:
+    docker:
+      - image: python:3.7
+
+    steps:
+      - checkout
+
+      - restore_cache:
+          key: v1-py3-deps-{{ checksum "setup.py" }}
+
+      - run:
+          name: Activate virtualenv
+          command: echo "source /tmp/venv/country_template/bin/activate" >> $BASH_ENV
+
+      - run:
+          name: Test the Web API
+          command: .circleci/test-api.sh
+
   deploy:
     docker:
       - image: python:3.7
@@ -86,6 +104,9 @@ workflows:
   build_and_deploy:
     jobs:
       - build
+      - test_api:
+          requires:
+            - build
       - check_version
       - deploy:
           requires:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 614abdbe..6982d5cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
 # Changelog
 
+### 3.12.9 - [#113](https://github.com/openfisca/country-template/pull/113)
+
+* Technical improvement.
+* Details:
+  - Add a Web API smoke test to the CI.
+
 ### 3.12.8 - [#105](https://github.com/openfisca/country-template/pull/105)
 
 * Minor change.
diff --git a/setup.py b/setup.py
index 72c66aeb..bb42cfe6 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@
 
 setup(
     name = "OpenFisca-Country-Template",
-    version = "3.12.8",
+    version = "3.12.9",
     author = "OpenFisca Team",
     author_email = "contact@openfisca.org",
     classifiers = [


Test patch:
diff --git a/.circleci/test-api.sh b/.circleci/test-api.sh
new file mode 100755
index 00000000..40edecfd
--- /dev/null
+++ b/.circleci/test-api.sh
@@ -0,0 +1,14 @@
+#! /usr/bin/env bash
+
+PORT=5000
+ENDPOINT=spec
+
+openfisca serve --country-package openfisca_country_template --port $PORT &
+server_pid=$!
+
+curl --retry-connrefused --retry 10 --retry-delay 5 --fail http://127.0.0.1:$PORT/$ENDPOINT | python -m json.tool > /dev/null
+result=$?
+
+kill $server_pid
+
+exit $?