Esempio n. 1
0
def test_create_weekly_business_on_edge_week_number():
    """
    Test if possible to create weekly_business object on week 1 and 52
    """
    weekly_business = WeeklyBusinessFactory(week=1)
    second_weekly_business = WeeklyBusinessFactory(week=52)

    assert weekly_business.week == 1
    assert second_weekly_business.week == 52
Esempio n. 2
0
def test_update_weekly_business_to_free_week(weekly_business):
    """
    Test if possible to update weekly_business object to a free week
    """
    second_weekly_business = WeeklyBusinessFactory(week=6)
    second_weekly_business.week = 7
    second_weekly_business.save()

    assert weekly_business.week == 5
    assert second_weekly_business.week == 7
Esempio n. 3
0
def test_create_weekly_business_non_existing_week_number():
    """
    Test if possible to create weekly_business object on non existing week numbers
    """
    with pytest.raises(ValueError) as v_err_lt:
        WeeklyBusinessFactory(week=0)
    with pytest.raises(ValueError) as v_err_gt:
        WeeklyBusinessFactory(week=53)

    assert "Uke må være mellom 1 og 52" == str(v_err_lt.value)
    assert "Uke må være mellom 1 og 52" == str(v_err_gt.value)
Esempio n. 4
0
def test_update_weekly_business_to_taken_week(weekly_business):
    """
    Test if possible to update weekly_business object to a taken week
    """
    with pytest.raises(ValueError) as v_err:
        second_weekly_business = WeeklyBusinessFactory(week=6)
        second_weekly_business.week = 5
        second_weekly_business.save()

    assert "Finnes allerede en ukens bedrift for denne uken" == str(
        v_err.value)
def test_weekly_business_ordering(default_client):
    """weekly_business should be ordered by year then week"""
    oldest = WeeklyBusinessFactory(year=today().year + 1, week=2)
    middel = WeeklyBusinessFactory(year=today().year + 1, week=10)
    newest = WeeklyBusinessFactory(year=today().year + 2, week=4)

    response = default_client.get(_get_weekly_business_url())
    response = response.json()

    assert response["results"][0].get("business_name") == oldest.business_name
    assert response["results"][1].get("business_name") == middel.business_name
    assert response["results"][2].get("business_name") == newest.business_name
Esempio n. 6
0
def test_update_weekly_business_to_non_existing_week_number():
    """
    Test if possible to update weekly_business object to non existing week numbers
    """
    with pytest.raises(ValueError) as v_err_lt:
        weekly_business = WeeklyBusinessFactory(week=7)
        weekly_business.week = 0
        weekly_business.save()
    with pytest.raises(ValueError) as v_err_gt:
        weekly_business = WeeklyBusinessFactory(week=6)
        weekly_business.week = 53
        weekly_business.save()

    assert "Uke må være mellom 1 og 52" == str(v_err_lt.value)
    assert "Uke må være mellom 1 og 52" == str(v_err_gt.value)
Esempio n. 7
0
def test_create_weekly_business_last_year():
    """
    Test if possible to create weekly_business object last year
    """
    with pytest.raises(ValueError) as v_err:
        WeeklyBusinessFactory(year=(today().year) - 1)
    assert "Ukens bedrift kan ikke opprettes i fortiden" == str(v_err.value)
def test_retrieve_when_not_found_returns_detail(default_client):
    """Should return a detail message in response."""
    weekly_business_not_found = WeeklyBusinessFactory.build()
    url = _get_weekly_business_detail_url(weekly_business_not_found)
    response = default_client.get(url)

    assert response.status_code == status.HTTP_404_NOT_FOUND
    assert response.json().get("detail")
Esempio n. 9
0
def test_create_weekly_business_on_free_week(weekly_business):
    """
    Test if possible to create weekly_business object on a free week
    """
    second_weekly_business = WeeklyBusinessFactory(week=6)

    assert weekly_business.week == 5
    assert second_weekly_business.week == 6
Esempio n. 10
0
def test_create_weekly_business_on_taken_week(weekly_business):
    """
    Test if possible to create weekly_business object on a taken week
    """
    with pytest.raises(ValueError) as v_err:
        WeeklyBusinessFactory(week=5)

    assert "Finnes allerede en ukens bedrift for denne uken" == str(
        v_err.value)
def test_destroy_when_not_found():
    """Should return a detail message in response."""
    client = get_api_client(user=UserFactory(), group_name=AdminGroup.INDEX)
    weekly_business_not_found = WeeklyBusinessFactory.build()

    url = _get_weekly_business_detail_url(weekly_business_not_found)
    response = client.delete(url)

    assert response.status_code == status.HTTP_404_NOT_FOUND
    assert response.json().get("detail")
def test_list_returns_weekly_business(default_client):
    """Should return all weekly_business."""
    WeeklyBusinessFactory()
    response = default_client.get(_get_weekly_business_url())

    assert len(response.json())
Esempio n. 13
0
def weekly_business():
    return WeeklyBusinessFactory()
Esempio n. 14
0
def test_create_weekly_business_next_year():
    """
    Test if possible to create weekly_business object next year
    """
    weekly_business = WeeklyBusinessFactory(year=(today().year) + 1)
    assert weekly_business.year == (today().year) + 1