Exemple #1
0
def test_cart_delivery_addresses(client, cart):
    # set up cart contents
    cart.delivery_address = factories.AustralianDeliveryAddressFactory()
    cart.save()

    # Add another address not attached to the card
    factories.AustralianDeliveryAddressFactory()

    resp = client.get('/_cart/')
    data = loads(resp.content.decode('utf-8'))
    assert data['delivery_addresses'] == [{
        'type':
        'AustralianDeliveryAddress',
        'selected':
        True,
        'data': {
            'addressee': cart.delivery_address.addressee,
            'address': cart.delivery_address.address,
            'suburb': cart.delivery_address.suburb,
            'state': cart.delivery_address.state,
            'postcode': cart.delivery_address.postcode,
        },
        'url':
        '/_cart/address/{}/'.format(cart.delivery_address_id),
    }]
Exemple #2
0
def test_view_inactive_delivery_address(admin_user, admin_client):
    addr = factories.AustralianDeliveryAddressFactory(user=admin_user,
                                                      active=False)

    url = "/_cart/address/{}/".format(addr.id)
    resp = admin_client.get(url)
    assert resp.status_code == 404
Exemple #3
0
def fill_cart(cart):
    factories.MyLineItemFactory(cart=cart)
    factories.MyLineItemFactory(cart=cart)
    factories.CartDiscountFactory(cart=cart, percentage=10)
    cart.delivery_address = factories.AustralianDeliveryAddressFactory()
    cart.payment_method = smodels.PipeCard.objects.create(card_id="Visa4242")
    if not cart.user:
        cart.email = Faker().safe_email()
    cart.save()
Exemple #4
0
def test_cart_delivery_addresses_logged_in(admin_user, admin_client, admin_cart):
    # set up cart contents
    admin_cart.delivery_address = factories.AustralianDeliveryAddressFactory(
        addressee="Active Address", user=admin_user
    )
    admin_cart.save()
    other_addr = factories.AustralianDeliveryAddressFactory(
        user=admin_user, addressee="Inactive Address"
    )

    # Add another address not attached to the card
    factories.AustralianDeliveryAddressFactory()
    factories.AustralianDeliveryAddressFactory(
        user=admin_user, active=False, addressee="Disabled Address"
    )

    resp = admin_client.get("/_cart/")
    data = loads(resp.content.decode("utf-8"))
    assert data["delivery_addresses"] == [
        {
            "type": "AustralianDeliveryAddress",
            "selected": True,
            "data": {
                "addressee": admin_cart.delivery_address.addressee,
                "address": admin_cart.delivery_address.address,
                "suburb": admin_cart.delivery_address.suburb,
                "state": admin_cart.delivery_address.state,
                "postcode": admin_cart.delivery_address.postcode,
            },
            "url": "/_cart/address/{}/".format(admin_cart.delivery_address_id),
        },
        {
            "type": "AustralianDeliveryAddress",
            "selected": False,
            "data": {
                "addressee": other_addr.addressee,
                "address": other_addr.address,
                "suburb": other_addr.suburb,
                "state": other_addr.state,
                "postcode": other_addr.postcode,
            },
            "url": "/_cart/address/{}/".format(other_addr.id),
        },
    ]
Exemple #5
0
def test_select_delivery_address(admin_user, admin_client, admin_cart):
    addr = factories.AustralianDeliveryAddressFactory(user=admin_user)

    url = "/_cart/address/{}/".format(addr.id)
    resp = admin_client.patch(url,
                              dumps({"selected": True}),
                              content_type="application/json")
    assert resp.status_code == 200
    admin_cart.refresh_from_db()
    assert admin_cart.delivery_address_id == addr.id
Exemple #6
0
def test_cart_delivery_addresses_logged_in(admin_user, admin_client,
                                           admin_cart):
    # set up cart contents
    admin_cart.delivery_address = factories.AustralianDeliveryAddressFactory(
        addressee="Active Address", user=admin_user)
    admin_cart.save()
    other_addr = factories.AustralianDeliveryAddressFactory(
        user=admin_user, addressee="Inactive Address")

    # Add another address not attached to the card
    factories.AustralianDeliveryAddressFactory()
    factories.AustralianDeliveryAddressFactory(user=admin_user,
                                               active=False,
                                               addressee="Disabled Address")

    resp = admin_client.get('/_cart/')
    data = loads(resp.content.decode('utf-8'))
    assert data['delivery_addresses'] == [
        {
            'type': 'AustralianDeliveryAddress',
            'selected': True,
            'data': {
                'addressee': admin_cart.delivery_address.addressee,
                'address': admin_cart.delivery_address.address,
                'suburb': admin_cart.delivery_address.suburb,
                'state': admin_cart.delivery_address.state,
                'postcode': admin_cart.delivery_address.postcode,
            },
            'url': '/_cart/address/{}/'.format(admin_cart.delivery_address_id),
        },
        {
            'type': 'AustralianDeliveryAddress',
            'selected': False,
            'data': {
                'addressee': other_addr.addressee,
                'address': other_addr.address,
                'suburb': other_addr.suburb,
                'state': other_addr.state,
                'postcode': other_addr.postcode,
            },
            'url': '/_cart/address/{}/'.format(other_addr.id),
        },
    ]
Exemple #7
0
def test_delete_delivery_address(client, cart):
    addr = factories.AustralianDeliveryAddressFactory()
    cart.delivery_address = addr
    cart.save()

    url = "/_cart/address/{}/".format(addr.id)
    resp = client.delete(url)
    assert resp.status_code == 204
    cart.refresh_from_db()
    assert cart.delivery_address is None
    addr.refresh_from_db()
    assert not addr.active
Exemple #8
0
def test_select_inactive_delivery_address(admin_user, admin_client,
                                          admin_cart):
    addr = factories.AustralianDeliveryAddressFactory(user=admin_user,
                                                      active=False)

    url = '/_cart/address/{}/'.format(addr.id)
    resp = admin_client.patch(url,
                              dumps({'selected': True}),
                              content_type='application/json')
    assert resp.status_code == 404
    admin_cart.refresh_from_db()
    assert admin_cart.delivery_address_id != addr.id
Exemple #9
0
def test_cart_delivery_addresses(client, cart):
    # set up cart contents
    cart.delivery_address = factories.AustralianDeliveryAddressFactory()
    cart.save()

    # Add another address not attached to the card
    factories.AustralianDeliveryAddressFactory()

    resp = client.get("/_cart/")
    data = loads(resp.content.decode("utf-8"))
    assert data["delivery_addresses"] == [
        {
            "type": "AustralianDeliveryAddress",
            "selected": True,
            "data": {
                "addressee": cart.delivery_address.addressee,
                "address": cart.delivery_address.address,
                "suburb": cart.delivery_address.suburb,
                "state": cart.delivery_address.state,
                "postcode": cart.delivery_address.postcode,
            },
            "url": "/_cart/address/{}/".format(cart.delivery_address_id),
        }
    ]
Exemple #10
0
def test_view_owned_unselected_delivery_address(admin_user, admin_client):
    addr = factories.AustralianDeliveryAddressFactory(user=admin_user)

    url = "/_cart/address/{}/".format(addr.id)
    resp = admin_client.get(url)
    data = loads(resp.content.decode("utf-8"))
    assert data == {
        "type": "AustralianDeliveryAddress",
        "data": {
            "addressee": addr.addressee,
            "address": addr.address,
            "suburb": addr.suburb,
            "state": addr.state,
            "postcode": addr.postcode,
        },
        "selected": False,
        "url": url,
    }
Exemple #11
0
def test_view_owned_unselected_delivery_address(admin_user, admin_client):
    addr = factories.AustralianDeliveryAddressFactory(user=admin_user)

    url = '/_cart/address/{}/'.format(addr.id)
    resp = admin_client.get(url)
    data = loads(resp.content.decode('utf-8'))
    assert data == {
        'type': "AustralianDeliveryAddress",
        'data': {
            'addressee': addr.addressee,
            'address': addr.address,
            'suburb': addr.suburb,
            'state': addr.state,
            'postcode': addr.postcode,
        },
        'selected': False,
        'url': url,
    }
Exemple #12
0
def test_view_delivery_address(client, cart):
    cart.delivery_address = factories.AustralianDeliveryAddressFactory()
    cart.save()

    url = "/_cart/address/{}/".format(cart.delivery_address_id)
    resp = client.get(url)
    data = loads(resp.content.decode("utf-8"))
    assert data == {
        "type": "AustralianDeliveryAddress",
        "data": {
            "addressee": cart.delivery_address.addressee,
            "address": cart.delivery_address.address,
            "suburb": cart.delivery_address.suburb,
            "state": cart.delivery_address.state,
            "postcode": cart.delivery_address.postcode,
        },
        "selected": True,
        "url": url,
    }
Exemple #13
0
def test_view_delivery_address(client, cart):
    cart.delivery_address = factories.AustralianDeliveryAddressFactory()
    cart.save()

    url = '/_cart/address/{}/'.format(cart.delivery_address_id)
    resp = client.get(url)
    data = loads(resp.content.decode('utf-8'))
    assert data == {
        'type': "AustralianDeliveryAddress",
        'data': {
            'addressee': cart.delivery_address.addressee,
            'address': cart.delivery_address.address,
            'suburb': cart.delivery_address.suburb,
            'state': cart.delivery_address.state,
            'postcode': cart.delivery_address.postcode,
        },
        'selected': True,
        'url': url,
    }
Exemple #14
0
def test_view_unowned_delivery_address(admin_user, client):
    addr = factories.AustralianDeliveryAddressFactory(user=admin_user)

    url = '/_cart/address/{}/'.format(addr.id)
    resp = client.get(url)
    assert resp.status_code == 404