Skip to content

Commit

Permalink
Merge branch 'dev' into LTD-remove-unsupported-hmrcquery
Browse files Browse the repository at this point in the history
  • Loading branch information
saruniitr committed Feb 5, 2024
2 parents 112760b + 023169a commit a2d30dd
Show file tree
Hide file tree
Showing 59 changed files with 657 additions and 767 deletions.
114 changes: 64 additions & 50 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,24 @@ commands:
key: dependencies-v1-{{ .Branch }}-{{ checksum "Pipfile.lock" }}

upload_code_coverage:
parameters:
alias:
type: string
steps:
- run:
name: Upload code coverage
command: ./codecov
name: Rename coverage file
command: mkdir coverage-output && cp .coverage coverage-output/.coverage.<<parameters.alias>>.$(cat /proc/sys/kernel/random/uuid)
- persist_to_workspace:
root: coverage-output
paths:
- .coverage.*
- run:
name: Code coverage report
command: |
pipenv run coverage xml
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov
jobs:
tests:
Expand All @@ -109,17 +123,12 @@ jobs:
parallelism: 10
steps:
- setup
- run:
name: Create report directories
command: |
mkdir test_results
- run:
name: Run tests
command: |
pipenv run pytest --circleci-parallelize --cov=. --cov-report xml --cov-config=.coveragerc --ignore lite_routing -k "not seeding and not elasticsearch and not performance and not migration" --junitxml=test_results/output.xml
- upload_code_coverage
- store_test_results:
path: test_results
pipenv run pytest --circleci-parallelize --cov=. --cov-report xml --cov-config=.coveragerc --ignore lite_routing -k "not seeding and not elasticsearch and not performance and not migration"
- upload_code_coverage:
alias: tests

seeding_tests:
docker:
Expand All @@ -132,17 +141,12 @@ jobs:
LITE_API_ENABLE_ES: True
steps:
- setup
- run:
name: Create report directories
command: |
mkdir test_results
- run:
name: Run seeding tests
command: |
pipenv run pytest --cov=. --cov-report xml --cov-config=.coveragerc -k seeding --junitxml=test_results/output.xml
- upload_code_coverage
- store_test_results:
path: test_results
pipenv run pytest --cov=. --cov-report xml --cov-config=.coveragerc -k seeding
- upload_code_coverage:
alias: seeding_tests

migration_tests:
docker:
Expand All @@ -156,17 +160,12 @@ jobs:
LITE_API_ENABLE_ES: True
steps:
- setup
- run:
name: Create report directories
command: |
mkdir test_results
- run:
name: Run migration tests
command: |
pipenv run pytest --circleci-parallelize --cov=. --cov-report xml --cov-config=.coveragerc -k migration --junitxml=test_results/output.xml
- upload_code_coverage
- store_test_results:
path: test_results
pipenv run pytest --circleci-parallelize --cov=. --cov-report xml --cov-config=.coveragerc -k migration
- upload_code_coverage:
alias: migration_tests

lite_routing_tests:
docker:
Expand All @@ -181,17 +180,12 @@ jobs:
parallelism: 5
steps:
- setup
- run:
name: Create report directories
command: |
mkdir test_results
- run:
name: Run lite_routing tests
command: |
pipenv run pytest --circleci-parallelize --cov=. --cov-report xml --cov-config=.coveragerc -k "not migration" --ignore lite_routing/routing_rules_internal/tests/bdd lite_routing --junitxml=test_results/output.xml
- upload_code_coverage
- store_test_results:
path: test_results
pipenv run pytest --circleci-parallelize --cov=. --cov-report xml --cov-config=.coveragerc -k "not migration" --ignore lite_routing/routing_rules_internal/tests/bdd lite_routing
- upload_code_coverage:
alias: lite_routing_tests

lite_routing_bdd_tests:
docker:
Expand All @@ -212,19 +206,14 @@ jobs:
- run:
name: Create report directories
command: |
mkdir test_results
mkdir cucumber_results
mkdir cucumber_html
- run:
name: Run lite_routing tests
command: pipenv run pytest --circleci-parallelize --gherkin-terminal-reporter -vv lite_routing/routing_rules_internal/tests/bdd --junitxml=test_results/output.xml --cucumberjson=cucumber_results/cuc.json
command: pipenv run pytest --circleci-parallelize --gherkin-terminal-reporter -vv lite_routing/routing_rules_internal/tests/bdd --cucumberjson=cucumber_results/cuc.json
- run:
name: Generate html cucumber report
command: node generate_cucumber_report.js
when: always
- upload_code_coverage
- store_test_results:
path: test_results
- store_artifacts:
path: cucumber_html

Expand All @@ -239,17 +228,12 @@ jobs:
LITE_API_ENABLE_ES: True
steps:
- setup
- run:
name: Create report directories
command: |
mkdir test_results
- run:
name: Run elasticsearch tests
command: |
pipenv run pytest --cov=. --cov-report xml --cov-config=.coveragerc -k elasticsearch --junitxml=test_results/output.xml
- upload_code_coverage
- store_test_results:
path: test_results
pipenv run pytest --cov=. --cov-report xml --cov-config=.coveragerc -k elasticsearch
- upload_code_coverage:
alias: elastic_search_tests

check_migrations:
docker:
Expand All @@ -266,6 +250,29 @@ jobs:
name: Check migrations are made
command: pipenv run ./manage.py makemigrations --check

check_coverage:
working_directory: ~/lite-api
docker:
- <<: *image_python
steps:
- checkout
- run: git submodule sync --recursive && git submodule update --recursive --init
- attach_workspace:
at: ~/lite-api/tmp
- run: pip install coverage diff_cover
- run: coverage combine tmp
- run: coverage xml
- run: coverage html
- store_artifacts:
path: htmlcov
- run: diff-cover coverage.xml --compare-branch=origin/dev --html-report coverage-report.html
- store_artifacts:
path: coverage-report.html
- run: zip -r coverage.zip htmlcov coverage-report.html
- store_artifacts:
path: coverage.zip
- run: diff-cover coverage.xml --compare-branch=origin/dev --fail-under=100

linting:
docker:
- <<: *image_python
Expand Down Expand Up @@ -362,15 +369,22 @@ jobs:
fi
workflows:
test:
tests:
jobs:
- linting
- tests
- seeding_tests
- lite_routing_tests
- lite_routing_bdd_tests
- elastic_search_tests
- migration_tests
- check_migrations
- linting
- check_coverage:
requires:
- tests
- seeding_tests
- elastic_search_tests
- migration_tests
- lite_routing_tests
- check-lite-routing-sha
- e2e_tests
3 changes: 0 additions & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ omit =
./lite_routing/management/commands/generate_rules_docs.py

branch = True

plugins =
django_coverage_plugin
3 changes: 2 additions & 1 deletion api/applications/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class StandardApplicationFactory(factory.django.DjangoModelFactory):
name = "Application Test Name"
export_type = ApplicationExportType.PERMANENT
case_type_id = CaseTypeEnum.SIEL.id
have_you_been_informed = (ApplicationExportLicenceOfficialType.YES,)
have_you_been_informed = ApplicationExportLicenceOfficialType.YES
reference_number_on_information_form = ""
activity = "Trade"
usage = "Trade"
Expand All @@ -73,6 +73,7 @@ class StandardApplicationFactory(factory.django.DjangoModelFactory):
intended_end_use = "this is our intended end use"
is_shipped_waybill_or_lading = True
non_waybill_or_lading_route_details = None
is_mod_security_approved = False
submitted_by = factory.SubFactory(ExporterUserFactory)

class Meta:
Expand Down
18 changes: 9 additions & 9 deletions api/applications/tests/test_adding_goods.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from api.audit_trail.models import Audit
from api.cases.enums import CaseTypeEnum
from api.goods.enums import ItemType
from lite_content.lite_api import strings
from api.staticdata.missing_document_reasons.enums import GoodMissingDocumentReasons
from api.goods.tests.factories import GoodFactory
from api.staticdata.units.enums import Units
from lite_content.lite_api import strings
from test_helpers.clients import DataTestClient
from test_helpers.decorators import none_param_tester

Expand All @@ -19,7 +19,7 @@ class AddingGoodsOnApplicationTests(DataTestClient):
def setUp(self):
super().setUp()
self.draft = self.create_draft_standard_application(self.organisation)
self.good = self.create_good("A good", self.organisation)
self.good = GoodFactory(name="A good", organisation=self.organisation)

def test_add_a_good_to_a_draft(self):
self.create_good_document(
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_add_a_good_to_a_draft(self):
def test_user_cannot_add_another_organisations_good_to_a_draft(self):
good_name = "A good"
organisation_2, _ = self.create_organisation_with_exporter_user()
good = self.create_good(good_name, organisation_2)
good = GoodFactory(name=good_name, organisation=organisation_2)
self.create_good_document(
good,
user=self.exporter_user,
Expand Down Expand Up @@ -242,7 +242,7 @@ def test_adding_good_validate_only(self, data):
self.assertEqual(response.status_code, data["response"])

def test_adding_good_without_document_or_reason_success(self):
good = self.create_good("A good", self.organisation)
good = GoodFactory(organisation=self.organisation)
good.is_document_available = False
good.save()
data = {
Expand All @@ -259,7 +259,7 @@ def test_adding_good_without_document_or_reason_success(self):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

def test_adding_good_with_reason_official_sensitive_success(self):
good = self.create_good("A good", self.organisation)
good = GoodFactory(organisation=self.organisation)
good.is_document_sensitive = True
good.save()
data = {
Expand All @@ -281,7 +281,7 @@ def test_add_a_good_to_a_draft_failure(self, quantity, unit, value, is_good_inco
Ensure all params have to be sent otherwise fail
"""
self.create_draft_standard_application(self.organisation)
self.create_good("A good", self.organisation)
GoodFactory(organisation=self.organisation)
self.create_good_document(
self.good,
user=self.exporter_user,
Expand All @@ -308,7 +308,7 @@ class AddingGoodsOnApplicationFirearmsTests(DataTestClient):
def setUp(self):
super().setUp()
self.draft = self.create_draft_standard_application(self.organisation)
self.good = self.create_good("A good", self.organisation, create_firearm_details=True)
self.good = GoodFactory(organisation=self.organisation)

@parameterized.expand(
[
Expand Down Expand Up @@ -410,7 +410,7 @@ class AddingGoodsOnApplicationExhibitionTests(DataTestClient):
def setUp(self):
super().setUp()
self.draft = self.create_mod_clearance_application(self.organisation, CaseTypeEnum.EXHIBITION)
self.good = self.create_good("A good", self.organisation)
self.good = GoodFactory(organisation=self.organisation)

def test_add_a_good_to_a_exhibition_draft_choice(self):
self.create_good_document(
Expand Down
9 changes: 5 additions & 4 deletions api/applications/tests/test_application_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from api.core.constants import GovPermissions
from api.cases.models import CaseAssignment
from api.licences.enums import LicenceStatus
from api.licences.tests.factories import StandardLicenceFactory
from api.teams.models import Team
from api.users.models import UserOrganisationRelationship, Permission
from api.staticdata.statuses.enums import CaseStatusEnum
Expand Down Expand Up @@ -102,7 +103,7 @@ def test_gov_user_set_application_to_terminal_status_removes_case_from_queues_us
)
if case_status == CaseStatusEnum.REVOKED:
self.standard_application.licences.add(
self.create_licence(self.standard_application, status=LicenceStatus.ISSUED)
StandardLicenceFactory(case=self.standard_application, status=LicenceStatus.ISSUED)
)

data = {"status": case_status}
Expand Down Expand Up @@ -134,7 +135,7 @@ def test_gov_user_set_application_to_terminal_status_removes_case_from_queues_us
]
)
def test_certain_case_statuses_changes_licence_status(self, case_status, licence_status):
licence = self.create_licence(self.standard_application, status=LicenceStatus.ISSUED)
licence = StandardLicenceFactory(case=self.standard_application, status=LicenceStatus.ISSUED)

data = {"status": case_status}
response = self.client.put(self.url, data=data, **self.gov_headers)
Expand Down Expand Up @@ -195,7 +196,7 @@ def test_exporter_set_application_status_failure(self, new_status):
def test_exporter_set_application_status_surrendered_success(self):
self.standard_application.status = get_case_status_by_status(CaseStatusEnum.FINALISED)
self.standard_application.save()
self.create_licence(self.standard_application, status=LicenceStatus.ISSUED)
StandardLicenceFactory(case=self.standard_application, status=LicenceStatus.ISSUED)
surrendered_status = get_case_status_by_status("surrendered")

data = {"status": CaseStatusEnum.SURRENDERED}
Expand Down Expand Up @@ -285,7 +286,7 @@ def test_gov_set_status_to_applicant_editing_failure(self):
def test_gov_set_status_for_all_except_applicant_editing_and_finalised_success(self, case_status):
if case_status == CaseStatusEnum.REVOKED:
self.standard_application.licences.add(
self.create_licence(self.standard_application, status=LicenceStatus.ISSUED)
StandardLicenceFactory(case=self.standard_application, status=LicenceStatus.ISSUED)
)

data = {"status": case_status}
Expand Down
2 changes: 0 additions & 2 deletions api/applications/tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.urls import reverse

from api.applications.serializers import good as serializers
from api.audit_trail.enums import AuditType
from api.audit_trail.models import Audit
from test_helpers.clients import DataTestClient
Expand All @@ -15,7 +14,6 @@ class ApplicationDocumentViewTests(DataTestClient):
def test_audit_trail_create(self, upload_bytes_func, mock_virus_scan, mock_s3_operations_get_object):
mock_virus_scan.return_value = False
application = self.create_draft_standard_application(organisation=self.organisation, user=self.exporter_user)
good = self.create_good("A good", self.organisation)

url = reverse("applications:application_documents", kwargs={"pk": application.pk})

Expand Down
Loading

0 comments on commit a2d30dd

Please sign in to comment.