def test_catering_product_category_endpoints_get(user_api_client,
                                                 catering_product_category,
                                                 endpoint):
    url = LIST_URL if endpoint == 'list' else get_detail_url(
        catering_product_category)

    response = user_api_client.get(url)
    assert response.status_code == 200
    if endpoint == 'list':
        assert len(response.data['results']) == 1
        data = response.data['results'][0]
    else:
        data = response.data

    expected_keys = {
        'id',
        'name',
        'products',
        'provider',
    }
    check_keys(data, expected_keys)

    assert data['id']
    assert data['name'] == {'fi': catering_product_category.name_fi}
    assert data['provider'] == catering_product_category.provider.pk
Ejemplo n.º 2
0
def test_catering_provider_endpoints_get(user_api_client, catering_provider,
                                         endpoint):
    url = LIST_URL if endpoint == 'list' else get_detail_url(catering_provider)

    response = user_api_client.get(url)
    assert response.status_code == 200
    if endpoint == 'list':
        assert len(response.data['results']) == 1
        data = response.data['results'][0]
    else:
        data = response.data

    expected_keys = {
        'id',
        'name',
        'price_list_url',
        'units',
    }
    check_keys(data, expected_keys)

    assert data['id']
    assert data['name'] == catering_provider.name
    assert data['price_list_url'] == {
        'fi': catering_provider.price_list_url_fi
    }
    assert set(data['units']) == set(
        catering_provider.units.values_list('id', flat=True))
def test_catering_product_endpoints_get(user_api_client, catering_product, endpoint):
    url = LIST_URL if endpoint == 'list' else get_detail_url(catering_product)

    response = user_api_client.get(url)
    assert response.status_code == 200
    if endpoint == 'list':
        assert len(response.data['results']) == 1
        data = response.data['results'][0]
    else:
        data = response.data

    expected_keys = {
        'id',
        'name',
        'category',
        'description',
    }
    check_keys(data, expected_keys)

    assert data['id']
    assert data['name'] == {'fi': catering_product.name_fi}
def test_catering_orders_endpoints_get(user_api_client, user, catering_order,
                                       catering_product, endpoint):
    url = LIST_URL if endpoint == 'list' else get_detail_url(catering_order)

    response = user_api_client.get(url)
    assert response.status_code == 200
    if endpoint == 'list':
        assert len(response.data['results']) == 1
        data = response.data['results'][0]
    else:
        data = response.data

    expected_keys = {
        'id',
        'created_at',
        'modified_at',
        'reservation',
        'order_lines',
        'invoicing_data',
        'message',
        'serving_time',
    }
    check_keys(data, expected_keys)

    assert data['id']
    assert data['created_at']
    assert data['modified_at']
    assert data['reservation'] == catering_order.reservation.pk
    assert data['invoicing_data'] == catering_order.invoicing_data
    assert data['message'] == catering_order.message
    assert data['serving_time'] == '12:00:00'

    order_lines = data['order_lines']
    assert len(order_lines) == 1
    order_line = order_lines[0]
    check_keys(order_line, {'product', 'quantity'})
    assert order_line['product'] == catering_product.pk
    assert order_line['quantity'] == 1
def test_catering_provider_endpoints_get(user_api_client, catering_provider, endpoint):
    url = LIST_URL if endpoint == 'list' else get_detail_url(catering_provider)

    response = user_api_client.get(url)
    assert response.status_code == 200
    if endpoint == 'list':
        assert len(response.data['results']) == 1
        data = response.data['results'][0]
    else:
        data = response.data

    expected_keys = {
        'id',
        'name',
        'price_list_url',
        'units',
    }
    check_keys(data, expected_keys)

    assert data['id']
    assert data['name'] == catering_provider.name
    assert data['price_list_url'] == {'fi': catering_provider.price_list_url_fi}
    assert set(data['units']) == set(catering_provider.units.values_list('id', flat=True))
def test_catering_orders_endpoints_get(user_api_client, user, catering_order, catering_product, endpoint):
    url = LIST_URL if endpoint == 'list' else get_detail_url(catering_order)

    response = user_api_client.get(url)
    assert response.status_code == 200
    if endpoint == 'list':
        assert len(response.data['results']) == 1
        data = response.data['results'][0]
    else:
        data = response.data

    expected_keys = {
        'id',
        'created_at',
        'modified_at',
        'reservation',
        'order_lines',
        'invoicing_data',
        'message',
        'serving_time',
    }
    check_keys(data, expected_keys)

    assert data['id']
    assert data['created_at']
    assert data['modified_at']
    assert data['reservation'] == catering_order.reservation.pk
    assert data['invoicing_data'] == catering_order.invoicing_data
    assert data['message'] == catering_order.message
    assert data['serving_time'] == '12:00:00'

    order_lines = data['order_lines']
    assert len(order_lines) == 1
    order_line = order_lines[0]
    check_keys(order_line, {'product', 'quantity'})
    assert order_line['product'] == catering_product.pk
    assert order_line['quantity'] == 1