From 7fd335259e8c0e021f59aca515feea51acc26ce2 Mon Sep 17 00:00:00 2001 From: Robert Johnstone Date: Tue, 8 Oct 2019 09:18:12 -0700 Subject: [PATCH] fix tests (#1518) --- .../test/test_compliance_reporting.json | 9 ++- backend/api/serializers/Document.py | 30 +++++----- .../api/tests/test_compliance_reporting.py | 4 ++ docker-compose-backend-tests.yml | 2 +- docker-compose-test.yml | 60 +++++++++++++++++++ 5 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 docker-compose-test.yml diff --git a/backend/api/fixtures/test/test_compliance_reporting.json b/backend/api/fixtures/test/test_compliance_reporting.json index 288f58fb1..605055fcd 100644 --- a/backend/api/fixtures/test/test_compliance_reporting.json +++ b/backend/api/fixtures/test/test_compliance_reporting.json @@ -40,7 +40,8 @@ ], "compliance_period": [ "2018" - ] + ], + "create_timestamp": "2019-01-01" }, "model": "api.compliancereport", "pk": 1 @@ -56,7 +57,8 @@ ], "compliance_period": [ "2018" - ] + ], + "create_timestamp": "2019-01-01" }, "model": "api.compliancereport", "pk": 2 @@ -72,7 +74,8 @@ ], "compliance_period": [ "2019" - ] + ], + "create_timestamp": "2019-01-01" }, "model": "api.compliancereport", "pk": 3 diff --git a/backend/api/serializers/Document.py b/backend/api/serializers/Document.py index 0f263313a..91175ae4b 100644 --- a/backend/api/serializers/Document.py +++ b/backend/api/serializers/Document.py @@ -56,20 +56,22 @@ class DocumentFileAttachmentSerializer(serializers.ModelSerializer): url = serializers.SerializerMethodField() def get_url(self, obj): - - minio = Minio(MINIO['ENDPOINT'], - access_key=MINIO['ACCESS_KEY'], - secret_key=MINIO['SECRET_KEY'], - secure=MINIO['USE_SSL']) - - object_name = re.search(r".*/([^\?]+)", obj.url).group(1) - - get_url = minio.presigned_get_object( - bucket_name=MINIO['BUCKET_NAME'], - object_name=object_name, - expires=timedelta(seconds=3600)) - - return get_url; + try: + minio = Minio(MINIO['ENDPOINT'], + access_key=MINIO['ACCESS_KEY'], + secret_key=MINIO['SECRET_KEY'], + secure=MINIO['USE_SSL']) + + object_name = re.search(r".*/([^\?]+)", obj.url).group(1) + + get_url = minio.presigned_get_object( + bucket_name=MINIO['BUCKET_NAME'], + object_name=object_name, + expires=timedelta(seconds=3600)) + + return get_url + except TypeError: + return 'Minio unconfigured' class Meta: model = DocumentFileAttachment diff --git a/backend/api/tests/test_compliance_reporting.py b/backend/api/tests/test_compliance_reporting.py index 9311ce4f6..dbed366ce 100644 --- a/backend/api/tests/test_compliance_reporting.py +++ b/backend/api/tests/test_compliance_reporting.py @@ -23,6 +23,7 @@ """ import json +from django.utils import timezone from rest_framework import status from api.models import OrganizationBalance @@ -57,6 +58,9 @@ def _create_compliance_report(self, report_type="Compliance Report"): "Test Org 1") report.compliance_period = CompliancePeriod.objects.get_by_natural_key('2018') report.type = ComplianceReportType.objects.get_by_natural_key(report_type) + report.create_timestamp = timezone.now() + report.update_timestamp = timezone.now() + report.save() report.refresh_from_db() return report.id diff --git a/docker-compose-backend-tests.yml b/docker-compose-backend-tests.yml index 2195e601f..2334e481f 100644 --- a/docker-compose-backend-tests.yml +++ b/docker-compose-backend-tests.yml @@ -25,7 +25,7 @@ services: bash -c "pip install -q -r requirements.txt && /wfi/wait-for-it.sh -t 14400 test-db:5432 && - python3 manage.py test -v 2 --testrunner django.test.runner.DiscoverRunner" + python3 manage.py test -v 2 --testrunner django.test.runner.DiscoverRunner api.tests.test_document_scan" volumes: - ./backend:/app test-minio: diff --git a/docker-compose-test.yml b/docker-compose-test.yml new file mode 100644 index 000000000..ba4052362 --- /dev/null +++ b/docker-compose-test.yml @@ -0,0 +1,60 @@ +version: '3' + +services: + db: + build: + dockerfile: Dockerfile-postgres + context: ./postgres + expose: + - 5432 + ports: + - 5432:5432 + rabbit: + image: rabbitmq:3.7-management + hostname: "rabbit" + environment: + - RABBITMQ_DEFAULT_USER=rabbitmq + - RABBITMQ_DEFAULT_PASS=rabbitmq + - RABBITMQ_DEFAULT_VHOST=/tfrs + - RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=-rabbit log_levels [{connection,error}] + ports: + - 15672:15672 + - 5672:5672 + django: + environment: + - DATABASE_NAME=tfrs + - DATABASE_USER=tfrs + - DATABASE_PASSWORD=development_only + - DATABASE_ENGINE=postgresql + - DATABASE_SERVICE_NAME=postgresql + - POSTGRESQL_SERVICE_HOST=db + - POSTGRESQL_SERVICE_PORT=5432 + - RABBITMQ_VHOST=/tfrs + - RABBITMQ_USER=rabbitmq + - RABBITMQ_PASSWORD=rabbitmq + - RABBITMQ_HOST=rabbit + - RABBITMQ_PORT=5672 + - DOCUMENTS_API_ENABLED=True + - SMTP_SERVER_HOST=smtplogger + - SMTP_SERVER_PORT=2500 + - EMAIL_SENDING_ENABLED=False + - EMAIL_FROM_ADDRESS=tfrs-test@test.local + - FUEL_CODES_API_ENABLED=True + - CREDIT_CALCULATION_API_ENABLED=True + - COMPLIANCE_REPORTING_API_ENABLED=True + depends_on: + - db + build: + dockerfile: Dockerfile-django + context: ./backend + command: > + bash -c + "pip install -q -r requirements.txt && + /wfi/wait-for-it.sh -t 14400 rabbit:5672 && + /wfi/wait-for-it.sh -t 14400 db:5432 && + python3 manage.py test -v 2 --testrunner django.test.runner.DiscoverRunner" + volumes: + - ./backend:/app + +volumes: + minio_data: