Beispiel #1
0
def test_unhappy_path_delete_returns_404_and_message(postgres_session):
    url = config.get_api_url()

    fake_session = requests.Session()

    authenticate(fake_session)

    r = fake_session.delete(f'{url}/api/articles/an-article')
    assert r.status_code == 404
    assert r.json()['message'] == 'Article not found.'
Beispiel #2
0
def test_happy_path_post_returns_201_and_tag_name(postgres_session):
    url = config.get_api_url()

    fake_session = requests.Session()

    authenticate(fake_session)

    tag = {'tag_name': 'verbos'}

    r = fake_session.post(f'{url}/api/tags', json=tag)

    assert r.status_code == 201
    assert r.json()['message'] == tag['tag_name']
Beispiel #3
0
def test_unhappy_path_post_returns_409_and_error_message(postgres_session):
    url = config.get_api_url()

    fake_session = requests.Session()

    authenticate(fake_session)

    tag = {'tag_name': 'verbos'}

    fake_session.post(f'{url}/api/tags', json=tag)
    r = fake_session.post(f'{url}/api/tags', json=tag)

    assert r.status_code == 409
    assert r.json()['message'] == f'Tag {tag["tag_name"]} is duplicate'
Beispiel #4
0
def test_happy_path_post_returns_201_and_article_title(postgres_session):
    url = config.get_api_url()

    fake_session = requests.Session()

    authenticate(fake_session)

    article = {
        "title": "An article",
        "description": "A remarkable description",
        "content": "Some very useful content",
        "tags": [],
        "category_id": 1
    }

    r = fake_session.post(f'{url}/api/articles', json=article)

    assert r.status_code == 201
    assert r.json()['message'] == 'An article'
Beispiel #5
0
def test_unhappy_path_post_returns_404_and_error_message(postgres_session):
    url = config.get_api_url()

    fake_session = requests.Session()

    authenticate(fake_session)

    article = {
        "title": "An article",
        "description": "A remarkable description",
        "content": "Some very useful content",
        "tags": [],
        "category_id": 1
    }

    fake_session.post(f'{url}/api/articles', json=article)
    r = fake_session.post(f'{url}/api/articles', json=article)

    assert r.status_code == 404
    assert r.json()['message'] == 'Can\'t create article. Title duplicate.'