Repository: CodeYellowBV/high-templar (language: python)

Issue:
GitHub actions setup



Discussion / hints:

Fix patch:
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..08e5fdb
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,24 @@
+[flake8]
+extend-ignore = W191,E501,E301,E302,E303,E265,E201,E202,E713,E126,E128,E226,E221,E266,E127,E251,E305,E241,E272,E261,W504,E117
+
+# For some reason the imports here trigger a linting error even though they are actually used
+exclude = high_templar/backend_adapter/__init__.py
+
+# W191            indentation uses tabs
+# E501            line too long
+# E301,E302,E303  wrong number of blank lines
+# E265            block comment should start with '# '
+# E201,E202       whitespace inside parentheses
+# E713            test for membership should be 'not in'
+# E126,E128       continuation line under/over-indented
+# E226            missing whitespace around arithmetic operator
+# E221            multiple spaces before operator
+# E266            too many leading '#' for block comment
+# E127            continuation line over-indented for visual indent
+# E251            unexpected spaces around keyword / parameter equals
+# E305            expected 2 blank lines after class or function definition, found 3
+# E241            multiple spaces after ':'
+# E272            multiple spaces before keyword
+# E261            at least two spaces before inline comment
+# W504            line break after binary operator
+# E117            over-indented (does not work with tabs)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..951a9af
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,38 @@
+name: Continuous Integration
+
+on: push
+
+jobs:
+  test:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v2
+
+      - name: Run tests with pytest
+        run: docker-compose run --rm tester
+
+      - name: Stop containers
+        if: always()
+        run: docker-compose stop
+
+  lint:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v2
+
+      - name: Setup python
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.7
+
+      - name: Install requirements
+        run: |
+          python -m venv .venv
+          .venv/bin/pip install flake8
+
+      - name: Run linting
+        run: .venv/bin/flake8 high_templar
diff --git a/docker-compose.yml b/docker-compose.yml
index 680de76..bf4ddca 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -9,6 +9,11 @@ services:
     environment:
       RABBITMQ_DEFAULT_USER: rabbitmq
       RABBITMQ_DEFAULT_PASS: rabbitmq
+    healthcheck:
+      test: ['CMD', 'rabbitmq-diagnostics', '-q', 'is_running']
+      interval: 30s
+      timeout: 30s
+      retries: 3
 
   backend:
     build:
@@ -39,3 +44,12 @@ services:
       dockerfile: docker/tester/Dockerfile
     volumes:
       - ./:/code
+    depends_on:
+      rabbitmq:
+        condition: service_healthy
+      backend:
+        condition: service_started
+      wiremock:
+        condition: service_started
+      nginx:
+        condition: service_started
diff --git a/docker/backend/Dockerfile b/docker/backend/Dockerfile
index d41be12..f2f338a 100644
--- a/docker/backend/Dockerfile
+++ b/docker/backend/Dockerfile
@@ -2,7 +2,7 @@ FROM debian:10
 
 # install dependencies
 RUN apt-get update -qq && \
-    apt-get install -y git libjpeg-dev libpq-dev gettext python3 python3-pip
+    apt-get install -y git libjpeg-dev libpq-dev gettext python3 python3-pip libffi-dev
 
 
 # build app
diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf
index 8c9623f..1919b6e 100644
--- a/docker/nginx/nginx.conf
+++ b/docker/nginx/nginx.conf
@@ -71,7 +71,7 @@ http {
 
         location /api/bootstrap/ {
             default_type text/plain;
-            return 200 '{"data": [{"name": "Klantenservice", "member_count": 9, "contact_count": 2, "id": 1}, {"name": "Test", "member_count": 0, "contact_count": 0, "id": 4}, {"name": "Test 2", "member_count": 0, "contact_count": 0, "id": 5}, {"name": "Test 3", "member_count": 0, "contact_count": 0, "id": 6}, {"name": "Test 4", "member_count": 0, "contact_count": 0, "id": 7}, {"name": "Test 5", "member_count": 0, "contact_count": 0, "id": 8}], "with": {}, "with_mapping": {}, "with_related_name_mapping": {}, "meta": {"total_records": 6}, "debug": {"request_id": ""}}';
+            return 200 '{}';
         }
 
          location @start-backend-service {
@@ -80,4 +80,4 @@ http {
         }
 
     }
-}
\ No newline at end of file
+}
diff --git a/high_templar/asgi.py b/high_templar/asgi.py
index d17b4aa..912d9c6 100644
--- a/high_templar/asgi.py
+++ b/high_templar/asgi.py
@@ -1,10 +1,8 @@
-import os, logging
+import os
+import logging
 from high_templar.main import create_app
 
 
-import asyncio
-
-
 class Settings:
     API_URL = os.environ.get('CY_BINDER_INTERNAL', 'http://wiremock:8080/api/')
     USER_ID_PATH = ['user', 'data', 'id']
diff --git a/high_templar/backend_adapter/__init__.py b/high_templar/backend_adapter/__init__.py
index 5312a2c..0f26c76 100644
--- a/high_templar/backend_adapter/__init__.py
+++ b/high_templar/backend_adapter/__init__.py
@@ -1,2 +1,2 @@
 from .binder import BinderAdapter
-from .header import Header
\ No newline at end of file
+from .header import Header
diff --git a/high_templar/backend_adapter/binder.py b/high_templar/backend_adapter/binder.py
index cc93c84..c139401 100644
--- a/high_templar/backend_adapter/binder.py
+++ b/high_templar/backend_adapter/binder.py
@@ -3,7 +3,7 @@
 from .interface import NoBackendConnectionException, BackendAdapter, UnparsableBackendPermissionsException
 from high_templar.authentication import Authentication, Permission
 from . import header
-from werkzeug.datastructures import Headers
+# from werkzeug.datastructures import Headers
 
 DEFAULT_HEADERS = {
     'cookie': header.Key('Cookie'),
diff --git a/high_templar/backend_adapter/header.py b/high_templar/backend_adapter/header.py
index 0c49c81..1942183 100644
--- a/high_templar/backend_adapter/header.py
+++ b/high_templar/backend_adapter/header.py
@@ -1,6 +1,6 @@
 from abc import ABC, abstractmethod
 
-from werkzeug.datastructures import Headers
+# from werkzeug.datastructures import Headers
 from werkzeug.http import parse_cookie
 
 
diff --git a/high_templar/backend_adapter/interface.py b/high_templar/backend_adapter/interface.py
index 1041368..b80c9d7 100644
--- a/high_templar/backend_adapter/interface.py
+++ b/high_templar/backend_adapter/interface.py
@@ -1,6 +1,3 @@
-import json
-from typing import List
-
 from high_templar.authentication import Authentication
 
 
diff --git a/high_templar/client_actions/__init__.py b/high_templar/client_actions/__init__.py
index 2787dd9..f4965cc 100644
--- a/high_templar/client_actions/__init__.py
+++ b/high_templar/client_actions/__init__.py
@@ -33,7 +33,8 @@ async def handle_message(connection, message: str):
     action = message_content.get('type', None)
 
     if action not in ACTIONS:
-        connection.app.logger.debug("{}: Unsupported action".format(connection.ID, action))
+        # connection.app.logger.debug("{}: Unsupported action".format(connection.ID, action))
+        connection.app.logger.debug("{}: Unsupported action".format(connection.ID))
         return await connection.send({
             'requestId': connection.ID,
             'code': 'error',
diff --git a/high_templar/client_actions/status.py b/high_templar/client_actions/status.py
index 394f7cb..900a8a9 100644
--- a/high_templar/client_actions/status.py
+++ b/high_templar/client_actions/status.py
@@ -1,4 +1,4 @@
 async def status(connection, message):
     return await connection.send(
         connection.app.hub.status()
-    )
\ No newline at end of file
+    )
diff --git a/high_templar/connection/connection.py b/high_templar/connection/connection.py
new file mode 100644
index 0000000..e69de29
diff --git a/high_templar/main.py b/high_templar/main.py
index 59e88fa..3c9dffb 100644
--- a/high_templar/main.py
+++ b/high_templar/main.py
@@ -1,7 +1,6 @@
 import asyncio
 
-from quart import Quart, request, make_response, websocket
-import json
+from quart import Quart, websocket
 
 from high_templar.connection import Connection
 from high_templar.backend_adapter import BinderAdapter


Test patch:
diff --git a/docker/tester/Dockerfile b/docker/tester/Dockerfile
index ff541e2..319e5fe 100644
--- a/docker/tester/Dockerfile
+++ b/docker/tester/Dockerfile
@@ -9,8 +9,9 @@ RUN apt-get update -qq && \
 		python3-pip \
 		python3-setuptools \
 		python3-wheel \
+		libffi-dev \
 	> /dev/null && \
-    rm -rf /var/cache/apk/*
+	rm -rf /var/cache/apk/*
 
 # build app
 RUN mkdir code