Skip to content

Commit

Permalink
Revert "LTD-1368 - Page 1 (Exporter)"
Browse files Browse the repository at this point in the history
  • Loading branch information
alixedi authored Nov 23, 2021
1 parent 17e9698 commit 89bd7c8
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 230 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ local_settings.py

.env
db.sqlite3
*.sql

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- repo: https://github.com/psf/black
rev: 19.10b0
rev: 19.3b0
hooks:
- id: black
24 changes: 7 additions & 17 deletions api/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,12 @@ class Meta:
ordering = ["created_at"]


# Licence Applications
class StandardApplication(BaseApplication):
"""
Application for any of below licences:
- SIEL (Standard Individual Export Licence)
- SITCL (Standard Individual Trade Control Licence)
"""

export_type = models.CharField(choices=ApplicationExportType.choices, default=None, max_length=50)
reference_number_on_information_form = models.CharField(blank=True, null=True, max_length=255)
have_you_been_informed = models.CharField(
choices=ApplicationExportLicenceOfficialType.choices, blank=True, null=True, default=None, max_length=50
choices=ApplicationExportLicenceOfficialType.choices, blank=True, null=True, default=None, max_length=50,
)
is_shipped_waybill_or_lading = models.BooleanField(blank=True, default=None, null=True)
non_waybill_or_lading_route_details = models.TextField(default=None, blank=True, null=True, max_length=2000)
Expand All @@ -205,13 +200,6 @@ class StandardApplication(BaseApplication):


class OpenApplication(BaseApplication):
"""
Application for any of below licences:
- OGEL (Open General Export Licence)
- OIEL (Open Individual Export Licence)
- OITCL (Open Individual Trade Control Licence)
"""

export_type = models.CharField(choices=ApplicationExportType.choices, default=None, max_length=50)
is_shipped_waybill_or_lading = models.BooleanField(blank=True, default=None, null=True)
non_waybill_or_lading_route_details = models.TextField(default=None, blank=True, null=True, max_length=2000)
Expand Down Expand Up @@ -290,18 +278,20 @@ class SiteOnApplication(models.Model):

class ApplicationDenialReason(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
application = models.ForeignKey(BaseApplication, related_name="application_denial_reason", on_delete=models.CASCADE)
application = models.ForeignKey(
BaseApplication, related_name="application_denial_reason", on_delete=models.CASCADE,
)
reasons = models.ManyToManyField(DenialReason)
reason_details = models.TextField(default=None, blank=True, null=True, max_length=2200)


class ExternalLocationOnApplication(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
external_location = models.ForeignKey(
ExternalLocation, related_name="external_locations_on_application", on_delete=models.CASCADE
ExternalLocation, related_name="external_locations_on_application", on_delete=models.CASCADE,
)
application = models.ForeignKey(
BaseApplication, related_name="external_application_sites", on_delete=models.CASCADE
BaseApplication, related_name="external_application_sites", on_delete=models.CASCADE,
)


Expand Down
37 changes: 2 additions & 35 deletions api/applications/tests/test_end_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,6 @@
from test_helpers.clients import DataTestClient


class TestEndUserDocument:
@mock.patch("api.documents.tasks.scan_document_for_viruses.now")
def test_requires_extra_fields_for_end_user(
self, scan_document_for_viruses_function, end_user, exporter_client_with_standard_application
):
"""
For end-user we require to know if the content is in English and
if company letterhead is there (LTD-1368)
"""
client, app = exporter_client_with_standard_application
app.add_party(end_user.party)
url = reverse("applications:party_document", kwargs={"pk": app.id, "party_pk": end_user.party.id})

# Missing required fields for end-user
response = client.post(url, {"name": "document_name.pdf", "s3_key": "s3_keykey.pdf", "size": 123456})
assert response.status_code == status.HTTP_400_BAD_REQUEST

# With required fields for end-user
response = client.post(
url,
{
"name": "document_name.pdf",
"s3_key": "s3_keykey.pdf",
"size": 123456,
"is_content_english": True,
"includes_company_letterhead": False,
},
)
assert response.status_code == status.HTTP_201_CREATED


class EndUserOnDraftTests(DataTestClient):
def setUp(self):
super().setUp()
Expand All @@ -67,8 +36,6 @@ def setUp(self):
"name": "document_name.pdf",
"s3_key": "s3_keykey.pdf",
"size": 123456,
"is_content_english": True,
"includes_company_letterhead": False,
}

@parameterized.expand([SubType.GOVERNMENT, SubType.COMMERCIAL, SubType.OTHER])
Expand All @@ -89,7 +56,7 @@ def test_set_end_user_on_draft_standard_application_successful(self, data_type):
response = self.client.post(self.url, data, **self.exporter_headers)

party_on_application = PartyOnApplication.objects.get(
application=self.draft, party__type=PartyType.END_USER, deleted_at__isnull=True
application=self.draft, party__type=PartyType.END_USER, deleted_at__isnull=True,
)

self.draft.refresh_from_db()
Expand Down Expand Up @@ -151,7 +118,7 @@ def test_set_end_user_on_draft_standard_application_failure(self, data):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
PartyOnApplication.objects.filter(
party__type=PartyType.END_USER, application=self.draft, deleted_at__isnull=True
party__type=PartyType.END_USER, application=self.draft, deleted_at__isnull=True,
).count(),
1,
)
Expand Down
19 changes: 11 additions & 8 deletions api/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@
"django_audit_log_middleware",
]


if DEBUG:
INSTALLED_APPS += ["django_extensions"]


MIDDLEWARE = [
"allow_cidr.middleware.AllowCIDRMiddleware",
"django.middleware.security.SecurityMiddleware",
Expand Down Expand Up @@ -293,7 +288,9 @@
# Elasticsearch configuration
LITE_API_ENABLE_ES = env.bool("LITE_API_ENABLE_ES", False)
if LITE_API_ENABLE_ES:
ELASTICSEARCH_DSL = {"default": {"hosts": env.str("ELASTICSEARCH_HOST")}}
ELASTICSEARCH_DSL = {
"default": {"hosts": env.str("ELASTICSEARCH_HOST")},
}

ENABLE_SPIRE_SEARCH = env.bool("ENABLE_SPIRE_SEARCH", False)

Expand All @@ -306,7 +303,10 @@
ELASTICSEARCH_APPLICATION_INDEXES["SPIRE"] = SPIRE_APPLICATION_INDEX_NAME
ELASTICSEARCH_PRODUCT_INDEXES["SPIRE"] = SPIRE_PRODUCT_INDEX_NAME

INSTALLED_APPS += ["django_elasticsearch_dsl", "django_elasticsearch_dsl_drf"]
INSTALLED_APPS += [
"django_elasticsearch_dsl",
"django_elasticsearch_dsl_drf",
]


if "test" not in sys.argv:
Expand Down Expand Up @@ -389,7 +389,10 @@
if DEBUG and "django_extensions" in sys.modules:
INSTALLED_APPS.append("django_extensions")

GRAPH_MODELS = {"all_applications": False, "group_models": True}
GRAPH_MODELS = {
"all_applications": False,
"group_models": True,
}


# SSO config
Expand Down
110 changes: 0 additions & 110 deletions api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

import pytest # noqa
from django.conf import settings
from rest_framework.test import APIClient

from api.users.models import ExporterUser, GovUser, UserOrganisationRelationship
from api.users.libraries.user_to_token import user_to_token


def camelcase_to_underscore(string):
Expand Down Expand Up @@ -66,109 +62,3 @@ def {fixture_name}(db):
if settings.DEBUG:
for fixture_name in sorted(fixture_names):
print(f"pytest.fixture: {fixture_name}")


# -------------------------- Clients ----------------------------


class LiteClient(APIClient):
"""
APIClient from rest_framework with appropriate headers when we login()
"""

def __init__(self, *args, **kwargs):
self.headers = {}
super().__init__(*args, **kwargs)

def login(self, user, organisation=None):
"""
Set headers appropriately for exporter and gov user
If no organisation given for exporter, an existing one will be used
"""
self.user = user # just for easy reference so we can always see who we are logged-in as
if isinstance(user, ExporterUser):

# Re-use existing organisation if not explicitly given one
if not organisation:
try:
org_relation = UserOrganisationRelationship.objects.get(user=user)
except UserOrganisationRelationship.DoesNotExist:
raise Exception("Exporter user must belong to an organisation to be able and login")
organisation = org_relation.organisation

# Use given organisation
else:
try:
UserOrganisationRelationship.objects.get(user=user, organisation=organisation)
except UserOrganisationRelationship.DoesNotExist:
raise Exception(
"Missing UserOrganisationRelationship for given exporter_user and organisation. Create the relationship and try again."
)

self.headers = {
"HTTP_EXPORTER_USER_TOKEN": user_to_token(user.baseuser_ptr),
"HTTP_ORGANISATION_ID": str(organisation.id),
}

elif isinstance(user, GovUser):
if organisation:
raise Exception("No organisation required for gov user")
self.headers = {"HTTP_GOV_USER_TOKEN": user_to_token(user)}
else:
raise Exception(f"Unknown user type: {user}")

def get(self, *args, **kwargs):
return super().get(*args, **kwargs, **self.headers)

def post(self, *args, **kwargs):
return super().post(*args, **kwargs, **self.headers)

def put(self, *args, **kwargs):
return super().put(*args, **kwargs, **self.headers)

def patch(self, *args, **kwargs):
return super().patch(*args, **kwargs, **self.headers)

def delete(self, *args, **kwargs):
return super().delete(*args, **kwargs, **self.headers)

def head(self, *args, **kwargs):
return super().head(*args, **kwargs, **self.headers)

def options(self, *args, **kwargs):
return super().options(*args, **kwargs, **self.headers)


@pytest.fixture
def exporter_client_with_standard_application(exporter_user_factory, standard_application_factory):
"""
Return: A client logged-in as exporter and their application
"""
exporter_user = exporter_user_factory()
relation = UserOrganisationRelationship.objects.get(user=exporter_user)
organisation = relation.organisation
standard_application = standard_application_factory(organisation=organisation)
client = LiteClient()
client.login(exporter_user, organisation)
return client, standard_application


# -------------------------- Fixtures ---------------------------


@pytest.fixture
def end_user(party_factory, party_on_application_factory):
from api.parties.enums import PartyType

return party_on_application_factory(party=party_factory(type=PartyType.END_USER))


@pytest.fixture
def standard_application(standard_application_factory):
return standard_application_factory()


@pytest.fixture
def open_application(open_application_factory):
return open_application_factory()
25 changes: 0 additions & 25 deletions api/documents/migrations/0002_add_document_fields.py

This file was deleted.

5 changes: 0 additions & 5 deletions api/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ class Document(TimestampableModel):
virus_scanned_at = models.DateTimeField(null=True, blank=True)
safe = models.NullBooleanField()

is_content_english = models.BooleanField(null=True, help_text="Is the document in English?")
includes_company_letterhead = models.BooleanField(
null=True, help_text="Does the document include at least one page on company letterhead?"
)

def __str__(self):
return self.name

Expand Down
7 changes: 0 additions & 7 deletions api/parties/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ class Party(TimestampableModel):

objects = PartyManager()

def __repr__(self):
return f"<{self.__class__.__name__} ({self.type}): {self.pk}>"

@property
def is_end_user(self):
return self.type == PartyType.END_USER

class Meta:
ordering = ["name"]

Expand Down
Loading

0 comments on commit 89bd7c8

Please sign in to comment.