def test_it_gets_author(client):
    technology_data = {
        'name': 'Python',
        'description': 'Programming language.',
    }
    create_technology_resp_data = client.post(
        '/technologies',
        json=technology_data,
        headers=auth_header_with_all_permissions
    ).get_json()
    technology = client.get(
        create_technology_resp_data['href']
    ).get_json()['data']
    data = {
        'name': 'Paweł',
        'surname': 'Niesiołowski',
        'email': '*****@*****.**',
        'description': 'Pasionate programmer.',
        'technologies': [technology['id']],
    }
    create_author_resp_data = client.post(
        '/authors',
        json=data,
        headers=auth_header_with_all_permissions
    ).get_json()
    resp = client.get(create_author_resp_data['href'])
    author = resp.get_json()['data']
    assert '200' in resp.status
    assert author['name'] == 'Paweł'
    assert author['surname'] == 'Niesiołowski'
    assert author['email'] == '*****@*****.**'
    assert author['description'] == 'Pasionate programmer.'
    assert len(author['technologies']) == 1
    assert author['technologies'][0]['name'] == 'Python'
    assert author['technologies'][0]['description'] == 'Programming language.'
def test_it_creates_author_with_technology(client):
    technology_data = {
        'name': 'Python',
        'description': 'Programming language',
    }
    resp = client.post(
        '/technologies',
        json=technology_data,
        headers=auth_header_with_all_permissions
    ).get_json()
    technology = client.get(resp['href']).get_json()['data']
    data = {
        'name': 'Paweł',
        'surname': 'Niesiołowski',
        'email': '*****@*****.**',
        'description': 'Pasionate programmer.',
        'technologies': [technology['id']],
    }
    resp = client.post(
        '/authors',
        json=data,
        headers=auth_header_with_all_permissions
    )
    authors = Author.query.filter(Author.surname == 'Niesiołowski').all()
    assert '201' in resp.status
    assert len(authors) == 1
    assert authors[0].technologies[0].name == 'Python'
def test_it_indexes_authors(client):
    first_author = {
        'name': 'Paweł',
        'surname': 'Niesiołowski',
        'email': '*****@*****.**',
    }
    second_author = {
        'name': 'Gal',
        'surname': 'Anonim',
        'email': '*****@*****.**',
    }
    client.post(
        '/authors',
        json=first_author,
        headers=auth_header_with_all_permissions
    )
    client.post(
        '/authors',
        json=second_author,
        headers=auth_header_with_all_permissions
    )
    resp = client.get('/authors')
    resp_data = resp.get_json()['data']
    assert '200' in resp.status
    assert len(resp_data) == 2
def test_it_indexes_reviewers(client):
    technology_id = create_technology_and_return_id(client, 'Python')
    first_reviewer = {
        'name': 'Paweł',
        'surname': 'Niesiołowski',
        'email': '*****@*****.**',
        'technologies': [technology_id],
    }
    second_reviewer = {
        'name': 'Gal',
        'surname': 'Anonim',
        'email': '*****@*****.**',
        'technologies': [technology_id],
    }
    client.post(
        '/reviewers',
        json=first_reviewer,
        headers=auth_header_with_all_permissions
    )
    client.post(
        '/reviewers',
        json=second_reviewer,
        headers=auth_header_with_all_permissions
    )
    resp = client.get('/reviewers')
    resp_data = resp.get_json()['data']
    assert '200' in resp.status
    assert len(resp_data) == 2
def test_it_changes_technologies_for_author(client):
    python_data = {
        'name': 'Python',
        'description': 'Programming language',
    }
    elixir_data = {
        'name': 'Elixir',
        'description': 'Programming language',
    }
    python_resp = client.post(
        '/technologies',
        json=python_data,
        headers=auth_header_with_all_permissions
    ).get_json()
    elixir_resp = client.post(
        '/technologies',
        json=elixir_data,
        headers=auth_header_with_all_permissions
    ).get_json()
    python_technology = client.get(python_resp['href']).get_json()['data']
    elixir_technology = client.get(elixir_resp['href']).get_json()['data']
    data = {
        'name': 'Paweł',
        'surname': 'Niesiołowski',
        'email': '*****@*****.**',
        'technologies': [python_technology['id']],
    }
    author_href = client.post(
        '/authors',
        json=data,
        headers=auth_header_with_all_permissions
    ).get_json()['href']

    edited_data = {
        'technologies': [elixir_technology['id']],
    }
    resp = client.patch(
        author_href,
        json=edited_data,
        headers=auth_header_with_all_permissions
    )
    authors = Author.query.filter(Author.surname == 'Niesiołowski').all()
    assert '204' in resp.status
    assert len(authors) == 1
    assert len(authors[0].technologies) == 1
    assert authors[0].technologies[0].name == 'Elixir'
def test_it_gets_technology(client):
    description = '''An interpreted, high-level,
general-purpose programming language'''
    data = {
        'name': 'Python',
        'description': description
    }
    post_resp = client.post(
        '/technologies',
        json=data,
        headers=auth_header_with_all_permissions
    )
    post_resp_data = post_resp.get_json()
    get_resp = client.get(post_resp_data['href'])
    get_resp_data = get_resp.get_json()
    assert '200' in get_resp.status
    assert get_resp_data['data']['name'] == 'Python'
    assert get_resp_data['data']['description'] == description
def test_index_technologies(client):
    python_data = {
        'name': 'Python',
        'description': 'Object oriented programming language',
    }
    elixir_data = {
        'name': 'Elixir',
        'description': 'Functional programming language',
    }
    client.post(
        '/technologies',
        json=python_data,
        headers=auth_header_with_all_permissions
    )
    client.post(
        '/technologies',
        json=elixir_data,
        headers=auth_header_with_all_permissions
    )
    resp = client.get('/technologies')
    resp_data = resp.get_json()
    assert '200' in resp.status
    assert len(resp_data['data']) == 2
def test_it_gets_reviewer(client):
    technology_id = create_technology_and_return_id(client, 'Python')
    reviewer_data = {
        'name': 'Paweł',
        'surname': 'Niesiołowski',
        'email': '*****@*****.**',
        'technologies': [technology_id],
    }
    reviewer_href = client.post(
        '/reviewers',
        json=reviewer_data,
        headers=auth_header_with_all_permissions
    ).get_json()['href']

    resp = client.get(reviewer_href)
    resp_data = resp.get_json()['data']

    assert '200' in resp.status
    assert resp_data['name'] == 'Paweł'
    assert resp_data['surname'] == 'Niesiołowski'
    assert resp_data['email'] == '*****@*****.**'
    assert len(resp_data['technologies']) == 1
    assert resp_data['technologies'][0]['name'] == 'Python'
def test_it_edits_technology(client):
    data = {
        'name': 'Python 3',
        'description': 'Programming language',
    }
    create_resp = client.post(
        '/technologies',
        json=data,
        headers=auth_header_with_all_permissions
    )
    create_resp_data = create_resp.get_json()
    get_resp = client.get(create_resp_data['href'])
    get_resp_data = get_resp.get_json()
    edited_data = {
        'name': 'Python',
    }
    edit_resp = client.patch(
        create_resp_data['href'],
        json=edited_data,
        headers=auth_header_with_all_permissions
    )
    assert '204' in edit_resp.status
    technologies = Technology.query.filter(Technology.name == 'Python').all()
    assert len(technologies) == 1
def test_it_returns_404_if_technology_does_not_exist(client):
    resp = client.get('/technologies/1')
    resp_data = resp.get_json()
    assert '404' in resp.status
    assert 404 == resp_data['error']
    assert 'Not found' in resp_data['message']
def test_it_returns_404_when_there_is_no_technology(client):
    resp = client.get('/technologies')
    resp_data = resp.get_json()
    assert '404' in resp.status
    assert resp_data['error'] == 404
    assert 'Not found' in resp_data['message']
def test_it_returns_404_if_there_is_not_any_author(client):
    resp = client.get('/authors')
    resp_data = resp.get_json()
    assert '404' in resp.status
    assert resp_data['error'] == 404
    assert 'Not found' in resp_data['message']
def test_it_returns_404_if_author_does_not_exist(client):
    resp = client.get('/authors/1')
    resp_data = resp.get_json()
    assert '404' in resp.status
    assert resp_data['error'] == 404
    assert 'Not found' in resp_data['message']