Skip to content

Commit

Permalink
test: pytests for EIOs
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Jan 27, 2025
1 parent 28a2c98 commit 8151e39
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def test_operation_registration_workflow(self, operation_type, purpose):
#### Operation Information Form ####
self._set_operation_information(purpose, operation_type)
#### Facility From ####
self._set_facilities()
if purpose != Operation.Purposes.ELECTRICITY_IMPORT_OPERATION:
self._set_facilities()

if purpose == Operation.Purposes.NEW_ENTRANT_OPERATION:
#### New Entrant Application Form ####
Expand Down
56 changes: 56 additions & 0 deletions bc_obps/service/tests/test_operation_service_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
from uuid import uuid4
from zoneinfo import ZoneInfo
from registration.models.facility import Facility
from registration.schema.v2.operation_timeline import OperationTimelineFilterSchema

from registration.models.contact import Contact
Expand Down Expand Up @@ -357,6 +358,61 @@ def test_create_or_replace_new_entrant_application():
assert operation.date_of_first_shipment == Operation.DateOfFirstShipmentChoices.ON_OR_BEFORE_MARCH_31_2024
assert operation.documents.filter(type=DocumentType.objects.get(name='new_entrant_application')).count() == 1


class TestRegisterOperationInformation:
@staticmethod
def test_register_operation_information_new_eio():
approved_user_operator = baker.make_recipe('utils.approved_user_operator')
payload = OperationInformationIn(
registration_purpose='Electricity Import Operation',
name="TestEIO",
type="Electricity Import Operation",
)
# check operation updates
operation = OperationServiceV2.register_operation_information(
approved_user_operator.user.user_guid, None, payload
)
operation.refresh_from_db()
assert Operation.objects.count() == 1
assert operation.created_by == approved_user_operator.user
assert operation.created_at is not None
# check purpose and status
assert operation.registration_purpose == Operation.Purposes.ELECTRICITY_IMPORT_OPERATION
assert operation.status == Operation.Statuses.DRAFT
# check facility
facilities = Facility.objects.filter(designated_operations__operation=operation).all()
assert facilities.count() == 1
assert facilities[0].name == "TestEIO"
assert facilities[0].type == Facility.Types.ELECTRICITY_IMPORT

@staticmethod
def test_register_operation_information_existing_eio():
approved_user_operator = baker.make_recipe('utils.approved_user_operator')
users_operation = baker.make_recipe(
'utils.operation', operator=approved_user_operator.operator, created_by=approved_user_operator.user
)
payload = OperationInformationIn(
registration_purpose='Electricity Import Operation',
name="UpdatedEIO",
type="Electricity Import Operation",
)
# check operation updates
operation = OperationServiceV2.register_operation_information(
approved_user_operator.user.user_guid, users_operation.id, payload
)
operation.refresh_from_db()
assert Operation.objects.count() == 1
assert operation.updated_by == approved_user_operator.user
assert operation.updated_at is not None
# check purpose and status
assert operation.registration_purpose == Operation.Purposes.ELECTRICITY_IMPORT_OPERATION
assert operation.status == Operation.Statuses.DRAFT
# check facility
facilities = Facility.objects.filter(designated_operations__operation=operation).all()
assert facilities.count() == 1
assert facilities[0].name == "UpdatedEIO"
assert facilities[0].type == Facility.Types.ELECTRICITY_IMPORT

@staticmethod
def test_register_operation_information_new_operation():
approved_user_operator = baker.make_recipe('utils.approved_user_operator')
Expand Down

0 comments on commit 8151e39

Please sign in to comment.