def test_import_customer_data_order_many_piers_no_berth_found(berth, boat_type):
    BerthFactory(pier=PierFactory(harbor=berth.pier.harbor), number=berth.number)

    data = [
        {
            "customer_id": "313432",
            "leases": [],
            "boats": [],
            "orders": [
                {
                    "created_at": "2019-12-02 00:00:00.000",
                    "order_sum": "251.00",
                    "vat_percentage": "25.0",
                    "is_paid": True,
                    "berth": {
                        "harbor_servicemap_id": berth.pier.harbor.servicemap_id,
                        "pier_id": "Fake-identifier",
                        "berth_number": berth.number,
                    },
                    "comment": "Laskunumero: 247509 RAMSAYRANTA A 004",
                }
            ],
            "comment": "",
            "id": "48319ebc-5eaf-4285-a565-15848225614b",
        }
    ]

    assert CustomerProfile.objects.count() == 0
    assert BerthLease.objects.count() == 0

    result = CustomerProfile.objects.import_customer_data(data)
    assert result == {"313432": UUID("48319ebc-5eaf-4285-a565-15848225614b")}

    assert CustomerProfile.objects.count() == 1
    assert BerthLease.objects.count() == 0
def test_create_berth_application(superuser_api_client, berth_switch_reason):
    berth = BerthFactory()
    berth_node_id = to_global_id(BerthNode, berth.id)
    harbor_node_id = to_global_id(HarborNode, berth.pier.harbor.id)
    boat_type = BoatTypeFactory()

    variables = {
        "berthSwitch": {
            "berthId": berth_node_id,
            "reason": berth_switch_reason.id
        },
        "berthApplication": {
            "language": "en",
            "firstName": "John",
            "lastName": "Doe",
            "phoneNumber": "1234567890",
            "email": "*****@*****.**",
            "address": "Mannerheimintie 1",
            "zipCode": "00100",
            "municipality": "Helsinki",
            "boatType": boat_type.id,
            "boatWidth": 2,
            "boatLength": 3,
            "informationAccuracyConfirmed": True,
            "acceptFitnessNews": False,
            "acceptLibraryNews": False,
            "acceptOtherCultureNews": False,
            "acceptBoatingNewsletter": True,
            "choices": [{
                "harborId": harbor_node_id,
                "priority": 1
            }],
        },
    }
    executed = superuser_api_client.execute(CREATE_BERTH_APPLICATION_MUTATION,
                                            input=variables)
    assert executed == {
        "data": {
            "createBerthApplication": {
                "berthApplication": {
                    "berthSwitch": {
                        "berth": {
                            "id": berth_node_id
                        },
                        "reason": {
                            "id": str(berth_switch_reason.id)
                        },
                    },
                    "harborChoices": [{
                        "harbor": {
                            "id": harbor_node_id
                        }
                    }],
                }
            }
        }
    }
def _generate_berth_switch_info():
    berth = BerthFactory()
    berth.pier.harbor.create_translation("fi", name="Nykyinen satama")

    berth_switch_reason = BerthSwitchReason.objects.language("fi").create(
        title="Good reason"
    )

    berth_switch = BerthSwitch.objects.create(berth=berth, reason=berth_switch_reason)
    return berth_switch
def _get_berth_switch_offer_context(subject: str = "Berth offer"):
    customer = CustomerProfileFactory.build()
    offer = BerthSwitchOfferFactory.build(
        customer=customer,
        application=BerthApplicationFactory.build(customer=customer),
        berth=BerthFactory.build(),
        lease=BerthLeaseFactory.build(
            customer=customer,
            # Fixed to a harbor with a real image
            berth__pier__harbor__image_file="/img/helsinki_harbors/41189.jpg",
        ),
    )
    return _get_offer_context(subject, offer)
def test_import_customer_data_lease_many_piers_no_berth_found(berth, boat_type):
    BerthFactory(pier=PierFactory(harbor=berth.pier.harbor), number=berth.number)

    data = [
        {
            "customer_id": "313432",
            "leases": [
                {
                    "harbor_servicemap_id": berth.pier.harbor.servicemap_id,
                    "pier_id": "Fake-identifier",
                    "berth_number": berth.number,
                    "start_date": "2019-06-10",
                    "end_date": "2019-09-14",
                    "boat_index": 0,
                }
            ],
            "boats": [
                {
                    "boat_type": boat_type.name,
                    "name": "My Boaty",
                    "registration_number": "",
                    "width": "1.40",
                    "length": "3.30",
                    "draught": None,
                    "weight": 500,
                }
            ],
            "orders": [],
            "comment": "",
            "id": "48319ebc-5eaf-4285-a565-15848225614b",
        }
    ]

    assert CustomerProfile.objects.count() == 0
    assert BerthLease.objects.count() == 0

    result = CustomerProfile.objects.import_customer_data(data)
    assert result == {"313432": UUID("48319ebc-5eaf-4285-a565-15848225614b")}

    assert CustomerProfile.objects.count() == 1
    assert BerthLease.objects.count() == 0
Beispiel #6
0
def test_create_berth_switch_offer_wrong_berth(api_client, berth_application,
                                               berth):
    berth_lease = BerthLeaseFactory(
        start_date=calculate_season_start_date(),
        end_date=calculate_season_end_date(),
        status=LeaseStatus.PAID,
    )
    berth_application.customer = berth_lease.customer

    berth_application.berth_switch = BerthSwitchFactory(
        berth=BerthFactory(number="9999"), )
    berth_application.save()

    variables = {
        "applicationId": to_global_id(BerthApplicationNode,
                                      berth_application.id),
        "newBerthId": to_global_id(BerthNode, berth.id),
    }
    executed = api_client.execute(CREATE_BERTH_SWITCH_OFFER_MUTATION,
                                  input=variables)

    assert_in_errors("NO_LEASE", executed)
def test_update_berth_application_by_owner(berth_customer_api_client,
                                           berth_application,
                                           customer_profile):
    berth_application_id = to_global_id(BerthApplicationNode,
                                        berth_application.id)
    remove_choice = HarborChoiceFactory(application=berth_application)

    berth = BerthFactory()
    harbor_node_id = to_global_id(HarborNode, berth.pier.harbor.id)

    customer_profile.user = berth_customer_api_client.user
    customer_profile.save()
    berth_application.customer = customer_profile
    berth_application.save()

    variables = {
        "id": berth_application_id,
        "language": "en",
        "firstName": "John",
        "lastName": "Doe",
        "phoneNumber": "1234567890",
        "email": "*****@*****.**",
        "address": "Mannerheimintie 1",
        "zipCode": "00100",
        "municipality": "Helsinki",
        "boatWidth": "2.00",
        "boatLength": "3.00",
        "acceptFitnessNews": False,
        "acceptLibraryNews": False,
        "acceptOtherCultureNews": False,
        "acceptBoatingNewsletter": True,
        "addChoices": [{
            "harborId": harbor_node_id,
            "priority": 1
        }],
        "removeChoices": [to_global_id(HarborChoiceType, remove_choice.id)],
    }

    assert berth_application.harborchoice_set.count() == 1

    executed = berth_customer_api_client.execute(
        UPDATE_BERTH_APPLICATION_OWNER_MUTATION, input=variables)

    assert executed == {
        "data": {
            "updateBerthApplication": {
                "berthApplication": {
                    "id": berth_application_id,
                    "language": "EN",
                    "firstName": "John",
                    "lastName": "Doe",
                    "phoneNumber": "1234567890",
                    "email": "*****@*****.**",
                    "address": "Mannerheimintie 1",
                    "zipCode": "00100",
                    "municipality": "Helsinki",
                    "boatWidth": "2.00",
                    "boatLength": "3.00",
                    "acceptFitnessNews": False,
                    "acceptLibraryNews": False,
                    "acceptOtherCultureNews": False,
                    "acceptBoatingNewsletter": True,
                    "harborChoices": [{
                        "harbor": {
                            "id": harbor_node_id
                        }
                    }],
                }
            }
        }
    }
def test_import_customer_data_with_valid_data_set():
    berth1 = BerthFactory()
    berth2 = BerthFactory()
    berth3 = BerthFactory()
    boat_type1 = BoatTypeFactory()
    boat_type2 = BoatTypeFactory()
    data = [
        {
            "customer_id": "313431",
            "leases": [
                {
                    "harbor_servicemap_id": berth1.pier.harbor.servicemap_id,
                    "berth_number": berth1.number,
                    "pier_id": berth1.pier.identifier,
                    "start_date": "2019-06-10",
                    "end_date": "2019-09-14",
                    "boat_index": 0,
                }
            ],
            "boats": [
                {
                    "boat_type": boat_type1.name,
                    "name": "McBoatface 111",
                    "registration_number": "31123A",
                    "width": "2.00",
                    "length": "5.30",
                    "draught": None,
                    "weight": None,
                }
            ],
            "orders": [
                {
                    "created_at": "2019-12-02 00:00:00.000",
                    "order_sum": "251.00",
                    "vat_percentage": "25.0",
                    "is_paid": True,
                    "berth": {
                        "harbor_servicemap_id": berth2.pier.harbor.servicemap_id,
                        "pier_id": berth2.pier.identifier,
                        "berth_number": berth2.number,
                    },
                    "comment": "Laskunumero: 247509 RAMSAYRANTA A 004",
                }
            ],
            "organization": {
                "type": "company",
                "name": "Nice Profitable Firm Ltd.",
                "address": "Mannerheimintie 1 A 1",
                "postal_code": "00100",
                "city": "Helsinki",
            },
            "comment": "VENEPAIKKA PERUTTU 9.1.2012 Hetu/Y-tunnus Timmistä: 01018000T",
            "id": "98edea83-4c92-4dda-bb90-f22e9dafe94c",
        },
        {
            "customer_id": "313432",
            "leases": [
                {
                    "harbor_servicemap_id": berth3.pier.harbor.servicemap_id,
                    "pier_id": berth3.pier.identifier,
                    "berth_number": berth3.number,
                    "start_date": "2019-06-10",
                    "end_date": "2019-09-14",
                }
            ],
            "boats": [
                {
                    "boat_type": boat_type2.name,
                    "name": "My Boaty",
                    "registration_number": "",
                    "width": "1.40",
                    "length": "3.30",
                    "draught": None,
                    "weight": 500,
                }
            ],
            "orders": [],
            "comment": "",
            "id": "48319ebc-5eaf-4285-a565-15848225614b",
        },
    ]

    assert CustomerProfile.objects.count() == 0

    result = CustomerProfile.objects.import_customer_data(data)

    # Test both customers were created
    assert CustomerProfile.objects.count() == 2
    assert len(result.keys()) == 2

    # First customer
    customer1 = CustomerProfile.objects.get(id=data[0].get("id"))

    assert customer1.organization.name == data[0].get("organization", {}).get("name")
    assert customer1.orders.count() == 1
    assert customer1.boats.count() == 1
    assert customer1.berth_leases.count() == 2

    assert customer1.boats.first().registration_number == "31123A"

    # Test that the lease belongs to the berth specified
    assert (
        customer1.berth_leases.filter(
            berth__number=berth1.number, berth__pier__harbor=berth1.pier.harbor
        ).count()
        == 1
    )
    order = customer1.orders.first()
    assert order.lease.berth.number == berth2.number
    assert order.lease.status == LeaseStatus.PAID
    assert order.price == Decimal("251.00")
    assert order.tax_percentage == Decimal("25.00")
    assert order.order_lines.count() == 0

    # First customer
    customer2 = CustomerProfile.objects.get(id=data[1].get("id"))

    assert not hasattr(customer2, "organization")
    assert customer2.orders.count() == 0
    assert customer2.boats.count() == 1

    # Test that the lease belongs to the berth specified
    assert (
        customer2.berth_leases.filter(
            berth__number=berth3.number, berth__pier__harbor=berth3.pier.harbor
        ).count()
        == 1
    )