Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Traficom checks from PASI CSV-import #410

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions parking_permits/management/commands/import_pasi_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from parking_permits.models import Address, Customer, Order, ParkingPermit, Vehicle
from parking_permits.models.order import OrderStatus
from parking_permits.models.parking_permit import ContractType, ParkingPermitStatus
from parking_permits.models.vehicle import VehicleUser
from parking_permits.services import dvv, kami
from parking_permits.services.traficom import Traficom

# E.g. 1.1.2011 1:01, 31.12.2012 15:50
PASI_DATETIME_FORMAT = re.compile(
Expand Down Expand Up @@ -244,7 +244,14 @@ def process_pasi_permit(self, pasi_permit: PasiResidentPermit):
# Validation & initialization
person_info = self.get_person_info(pasi_permit.national_id_number)
permit_address_type = self.find_permit_address_type(pasi_permit, person_info)
vehicle = self.fetch_vehicle(pasi_permit.registration_number)
vehicle = Vehicle.objects.get_or_create(
registration_number=pasi_permit.registration_number.strip()
)[0]
vehicle.users.add(
VehicleUser.objects.get_or_create(
national_id_number=pasi_permit.national_id_number.strip()
)[0]
)
self.validate_vehicle(pasi_permit, vehicle)

# Create/get all the instances required for a parking permit.
Expand Down Expand Up @@ -408,15 +415,6 @@ def update_or_create_customer(

return customer

@staticmethod
def fetch_vehicle(registration_number: str) -> Vehicle:
try:
return Traficom().fetch_vehicle_details(registration_number)
except Exception as e:
raise PasiImportError(
"Something went wrong during Traficom vehicle fetch"
) from e

@staticmethod
def validate_vehicle(pasi_permit: PasiResidentPermit, vehicle: Vehicle) -> NoReturn:
if not vehicle.users.filter(
Expand Down
19 changes: 0 additions & 19 deletions parking_permits/tests/commands/test_import_pasi_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,25 +318,6 @@ def test_validate_vehicle_raises_error_on_failure(self, pasi_resident_permit):
with pytest.raises(PasiValidationError):
PasiCommand.validate_vehicle(pasi_resident_permit, vehicle)

@patch.object(Traficom, "fetch_vehicle_details", return_value="Hello, world!")
def test_fetch_vehicle_gets_vehicle_from_traficom(self, mock_fetch_vehicle_details):
vehicle = PasiCommand.fetch_vehicle("FOO-123")

mock_fetch_vehicle_details.assert_called_once_with("FOO-123")
assert vehicle == "Hello, world!"

@patch.object(Traficom, "fetch_vehicle_details", return_value="Hello, world!")
def test_fetch_vehicle_raises_pasi_error_on_failure(
self, mock_fetch_vehicle_details
):
def raise_error(*_, **__):
raise ValueError

mock_fetch_vehicle_details.side_effect = raise_error

with pytest.raises(PasiImportError):
PasiCommand.fetch_vehicle("FOO-123")

def test_vehicle_has_active_permits_returns_true_if_has_active_permits(self):
vehicle = VehicleFactory(registration_number="FOO-123")
ParkingPermitFactory(status=ParkingPermitStatus.VALID, vehicle=vehicle)
Expand Down