Skip to content

Commit

Permalink
chore: fix test CI (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 authored Sep 2, 2024
1 parent b79b052 commit 982c9d1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
2 changes: 0 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# set project name to have a short one
COMPOSE_PROJECT_NAME=open_prices
# unify separator with windows style
COMPOSE_PATH_SEPARATOR=;
# dev is default target
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ jobs:
- name: Launch tests
run: |
make build
make tests
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#!/usr/bin/make

ifneq (,$(wildcard ./.env))
-include .env
-include .envrc
export
endif

MOUNT_POINT ?= /mnt
DOCKER_LOCAL_DATA ?= /srv/off/docker_data
ENV_FILE ?= .env
Expand All @@ -8,11 +16,8 @@ export USER_UID:=${UID}
# prefer to use docker buildkit
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
# we need COMPOSE_PROJECT_NAME for some commands
# take it form env, or from env file
COMPOSE_PROJECT_NAME ?= $(shell grep COMPOSE_PROJECT_NAME ${ENV_FILE} | cut -d '=' -f 2)
DOCKER_COMPOSE=docker compose --env-file=${ENV_FILE}
DOCKER_COMPOSE_TEST=COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}_test docker compose --env-file=${ENV_FILE}
DOCKER_COMPOSE_TEST=COMPOSE_PROJECT_NAME=open_prices_test docker compose --env-file=${ENV_FILE}

# avoid target corresponding to file names, to depends on them
.PHONY: *
Expand All @@ -33,7 +38,7 @@ guard-%: # guard clause for targets that require an environment variable (usuall
#------------#

test:
echo ${ENV_FILE} ${COMPOSE_PROJECT_NAME}
echo ${ENV_FILE}

livecheck:
@echo "🥫 livecheck services…" ; \
Expand Down
6 changes: 3 additions & 3 deletions docker/dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# this file setup various thinks that are for dev environment

x-api-base: &api-base
image: openfoodfacts/open-prices/api:dev
build:
context: .
target: runtime-dev
Expand All @@ -9,16 +10,15 @@ x-api-base: &api-base
USER_GID: ${USER_GID:-1000}
volumes:
# mount code dynamically
- "./app:/opt/open-prices/app"
- "./open_prices:/opt/open-prices/open_prices"
- "./config:/opt/open-prices/config"
- ./pyproject.toml:/opt/open-prices/pyproject.toml
# make doc generation available
- ./mkdocs.yml:/opt/open-prices/mkdocs.yml
- ./build_mkdocs.sh:/opt/open-prices/build_mkdocs.sh
- ./README.md:/opt/open-prices/README.md
- ./docs:/opt/open-prices/docs
- ./gh_pages:/opt/open-prices/gh_pages
# make migrations available so that we can run them easily
- ./alembic:/opt/open-prices/alembic
# mount tests
- ./tests:/opt/open-prices/tests
- ./manage.py:/opt/open-prices/manage.py
Expand Down
15 changes: 13 additions & 2 deletions open_prices/api/proofs/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from io import BytesIO

from django.db.models import signals
from django.test import TestCase
from django.urls import reverse
from PIL import Image

from open_prices.locations import constants as location_constants
from open_prices.locations.models import (
Expand All @@ -15,6 +18,14 @@
PROOF = {"type": proof_constants.TYPE_RECEIPT, "currency": "EUR", "date": "2024-01-01"}


def create_fake_image() -> bytes:
fp = BytesIO()
image = Image.new("RGB", (100, 100))
image.save(fp, format="WEBP")
fp.seek(0)
return fp


class ProofListApiTest(TestCase):
@classmethod
def setUpTestData(cls):
Expand Down Expand Up @@ -151,7 +162,7 @@ def setUpTestData(cls):
}

def test_proof_create(self):
self.data["file"] = open("filename.webp", "rb")
self.data["file"] = create_fake_image()
# anonymous
response = self.client.post(self.url, self.data)
self.assertEqual(response.status_code, 403)
Expand All @@ -177,7 +188,7 @@ def test_proof_create(self):
self.assertEqual(p.source, "API") # default value

def test_proof_create_with_app_name(self):
self.data["file"] = open("filename.webp", "rb")
self.data["file"] = create_fake_image()
for app_name in ["", "test app"]:
# with empty app_name
response = self.client.post(
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ profile = "black"
strict = true
disable_error_code = ["no-untyped-call", "no-any-return"]
python_version = "3.11"
exclude = [
'alembic/',
]
plugins = [
"sqlalchemy.ext.mypy.plugin",
"pydantic.mypy"
Expand Down

0 comments on commit 982c9d1

Please sign in to comment.