diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9478c5b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: CI Build +on: + push: + branches: + - master + paths-ignore: + - 'README.md' + - '.vscode/**' + + pull_request: + branches: + - master + paths-ignore: + - 'README.md' + - '.vscode/**' + +jobs: + build: + runs-on: ubuntu-latest + container: python:3.11-slim + + # Required services + services: + postgres: + image: postgres:15-alpine + env: + POSTGRES_PASSWORD: pgs3cr3t + POSTGRES_DB: testdb + ports: + - 5432:5432 + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + # Steps for the build + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + python -m pip install -U pip poetry + poetry config virtualenvs.create false + poetry install + + - name: Linting + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 service tests --count --select=E9,F63,F7,F82 --show-source --statistics + # check for complexity. The GitHub editor is 127 chars wide + flake8 service tests --count --max-complexity=10 --max-line-length=127 --statistics + # Run pylint on the service + pylint service tests --max-line-length=127 + + - name: Run unit tests with green + run: | + export FLASK_APP=service:app + pytest --pspec --cov=service --cov-fail-under=95 --disable-warnings + env: + DATABASE_URI: "postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/testdb" + + - name: Upload code coverage + uses: codecov/codecov-action@v3.1.4 \ No newline at end of file diff --git a/service/models/shop_cart.py b/service/models/shop_cart.py index 5dc7eda..5a4b2e5 100644 --- a/service/models/shop_cart.py +++ b/service/models/shop_cart.py @@ -75,6 +75,7 @@ def deserialize(self, data): item = ShopCartItem() item.deserialize(json_item) self.items.append(item) + # pylint: disable=duplicate-code except AttributeError as error: raise DataValidationError("Invalid attribute: " + error.args[0]) from error except KeyError as error: diff --git a/service/models/shop_cart_item.py b/service/models/shop_cart_item.py index 84854ef..822a2f3 100644 --- a/service/models/shop_cart_item.py +++ b/service/models/shop_cart_item.py @@ -54,6 +54,7 @@ def deserialize(self, data): self.product_id = data["product_id"] self.quantity = data["quantity"] self.price = data["price"] + # pylint: disable=duplicate-code except AttributeError as error: raise DataValidationError("Invalid attribute: " + error.args[0]) from error except KeyError as error: diff --git a/tests/test_routes.py b/tests/test_routes.py index ebac58c..61adad2 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -26,6 +26,7 @@ class TestShopCartService(TestCase): """REST API Server Tests""" + # pylint: disable=duplicate-code @classmethod def setUpClass(cls): """Run once before all tests""" diff --git a/tests/test_shop_cart_item.py b/tests/test_shop_cart_item.py index bee0158..30bd84f 100644 --- a/tests/test_shop_cart_item.py +++ b/tests/test_shop_cart_item.py @@ -27,6 +27,7 @@ class TestShopCartItem(TestCase): """Shop Cart Item Model CRUD Tests""" + # pylint: disable=duplicate-code @classmethod def setUpClass(cls): """This runs once before the entire test suite"""