bolinette.testing.fixture.client.mock

Here are the examples of the python api bolinette.testing.fixture.client.mock taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

54 Examples 7

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_get_books_paginated(client):
    rv = await client.get('/book?page=1')
    assert rv['code'] == 200
    assert len(rv['data']) == 20
    assert rv['pagination']['page'] == 1
    assert rv['pagination']['per_page'] == 20
    assert rv['pagination']['total'] == 100
    for i in range(20):
        assert equal_books(rv['data'][i], client.mock(i, 'book').to_response())


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_get_book(client):
    author1 = client.mock(1, 'person')
    book1 = utils.book.create_book(client.mock, 1, 1)

    rv = await client.get(f'/book/{book1["uid"]}')
    assert rv['code'] == 200
    assert equal_books(rv['data'], book1.to_response(), author1.to_response())


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_get_book2(client):
    author2 = client.mock(2, 'person')
    book3 = utils.book.create_book(client.mock, 3, 2)

    rv = await client.get(f'/book/{book3["uid"]}')
    assert rv['code'] == 200
    assert equal_books(rv['data'], book3.to_response(), author2.to_response())


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_create_book(client):
    author1 = client.mock(1, 'person')
    book4 = utils.book.create_book(client.mock, 4, 1)
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.post('/book', book4.to_payload())
    assert rv['code'] == 201
    assert equal_books(rv['data'], book4.to_response(), author1.to_response())
    assert rv['data']['created_by']['username'] == user1['username']
    assert rv['data']['updated_by']['username'] == user1['username']


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_create_book_bad_request(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.post('/book', {})
    assert rv['code'] == 422
    assert 'param.required:name' in rv['messages']
    assert 'param.required:pages' in rv['messages']
    assert 'param.required:author' in rv['messages']


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_create_book_author_not_found(client):
    author3 = client.mock(3, 'person')
    book4 = utils.book.create_book(client.mock, 4, 3)
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.post('/book', book4.to_payload())
    assert rv['code'] == 404
    assert f'entity.not_found:person:uid:{author3["uid"]}' in rv['messages']


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_update_book(client):
    author2 = client.mock(2, 'person')
    book1 = utils.book.create_book(client.mock, 1, 2)
    user2 = client.mock(2, 'user')

    await client.post('/user/login', user2.to_payload('login'))

    rv = await client.put(f'/book/{book1["uid"]}', book1.to_payload())
    assert rv['code'] == 200
    assert equal_books(rv['data'], book1.to_response(), author2.to_response())
    assert rv['data']['updated_by']['username'] == user2['username']


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_update_book_bad_request(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.put('/book/1', {'name': 'new book name'})
    assert rv['code'] == 422
    assert 'param.required:pages' in rv['messages']
    assert 'param.required:author' in rv['messages']


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_update_book_not_found(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.patch('/book/4', {'name': 'new book name'})
    assert rv['code'] == 404


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_patch_book(client):
    author1 = client.mock(1, 'person')
    book1 = utils.book.create_book(client.mock, 1, 1)
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.patch(f'/book/{book1["uid"]}', {'name': 'new book name'})
    assert rv['code'] == 200
    assert rv['data']['name'] == 'new book name'
    assert rv['data']['pages'] == book1['pages']
    assert rv['data']['author']['full_name'] == author1.to_response()['full_name']


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_patch_book_bad_request(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.patch('/book/1', {'name': ''})
    assert rv['code'] == 422
    assert 'param.non_nullable:name' in rv['messages']


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_update_book_author_not_found(client):
    user1 = client.mock(1, 'user')
    book1 = client.mock(1, 'book')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.patch(f'/book/{book1["uid"]}', {'author': {'uid': 'unknown'}})
    assert rv['code'] == 404
    assert 'entity.not_found:person:uid:unknown' in rv['messages']


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_delete_book(client):
    user1 = client.mock(1, 'user')
    book1 = client.mock(1, 'book')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.delete(f'/book/{book1["uid"]}')
    assert rv['code'] == 200

    rv = await client.get(f'/book/{book1["uid"]}')
    assert rv['code'] == 404


@bolitest(before=utils.book.set_up)

3 Source : test_book_ctrl.py
with MIT License
from bolinette

async def test_delete_book_not_found(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.delete('/book/4')
    assert rv['code'] == 404

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_get_one_library(client):
    library2 = client.mock(2, 'library')

    rv = await client.get(f'/library/{library2["key"]}')
    assert rv['code'] == 200
    assert rv['data']['key'] == library2['key']
    assert rv['data']['name'] == library2['name']
    assert rv['data']['address'] == library2['address']


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_create_library(client):
    library4 = client.mock(4, 'library')

    rv = await client.post('/library', library4.to_payload())
    assert rv['code'] == 201
    assert rv['data']['key'] == library4['key']
    assert rv['data']['name'] == library4['name']
    assert rv['data']['address'] == library4['address']


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_create_library_and_get(client):
    library4 = client.mock(4, 'library')

    await client.post('/library', library4.to_payload())

    rv = await client.get(f'/library/{library4["key"]}')
    assert rv['code'] == 200
    assert rv['data']['key'] == library4['key']
    assert rv['data']['name'] == library4['name']
    assert rv['data']['address'] == library4['address']


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_create_library_conflict(client):
    library1 = client.mock(1, 'library')
    library4 = client.mock(4, 'library')
    library4['key'] = library1['key']

    rv = await client.post('/library', library4.to_payload())
    assert rv['code'] == 409
    assert f'param.conflict:key:{library1["key"]}' in rv['messages']


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_update_library(client):
    library1 = client.mock(1, 'library')
    key = library1['key']
    library1['key'] = 'new_library_key'
    library1['name'] = 'New Library Name'
    library1['address'] = 'New Library Address'

    rv = await client.put(f'/library/{key}', library1.to_response())
    assert rv['code'] == 200
    assert libraries_equal(library1, rv['data'])


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_update_library_and_get(client):
    library1 = client.mock(1, 'library')
    key = library1['key']
    library1['key'] = 'new_library_key'
    library1['name'] = 'New Library Name'
    library1['address'] = 'New Library Address'

    rv = await client.put(f'/library/{key}', library1.to_response())
    assert rv['code'] == 200

    rv = await client.get('/library/new_library_key')
    assert rv['code'] == 200
    assert libraries_equal(library1, rv['data'])


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_update_library_bad_request(client):
    library1 = client.mock(1, 'library')

    rv = await client.put(f'/library/{library1["key"]}', {})
    assert rv['code'] == 422
    assert 'param.required:key' in rv['messages']
    assert 'param.required:name' in rv['messages']


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_update_library_conflict(client):
    library1 = client.mock(1, 'library')
    library2 = client.mock(2, 'library')

    rv = await client.put(f'/library/{library1["key"]}', library2.to_payload())
    assert rv['code'] == 409
    assert f'param.conflict:key:{library2["key"]}' in rv['messages']


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_patch_library(client):
    library1 = client.mock(1, 'library')
    library1['name'] = 'New Library Name'

    rv = await client.patch(f'/library/{library1["key"]}', {'name': library1['name']})
    assert rv['code'] == 200
    assert libraries_equal(library1, rv['data'])


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_patch_library_bad_request(client):
    library1 = client.mock(1, 'library')

    rv = await client.patch(f'/library/{library1["key"]}', {'name': None})
    assert rv['code'] == 422
    assert 'param.non_nullable:name' in rv['messages']


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_patch_library_conflict(client):
    library1 = client.mock(1, 'library')
    library2 = client.mock(2, 'library')

    rv = await client.patch(f'/library/{library1["key"]}', {'key': library2['key']})
    assert rv['code'] == 409
    assert f'param.conflict:key:{library2["key"]}' in rv['messages']


@bolitest(before=set_up)

3 Source : test_library_ctrl.py
with MIT License
from bolinette

async def test_delete_library(client):
    library1 = client.mock(1, 'library')

    rv = await client.delete(f'/library/{library1["key"]}')
    assert rv['code'] == 200
    assert libraries_equal(library1, rv['data'])


@bolitest(before=set_up)

3 Source : test_person_ctrl.py
with MIT License
from bolinette

async def test_get_person(client: BolitestClient):
    person1 = client.mock(1, 'person')

    rv = await client.get(f'/person/{person1["uid"]}')
    person1_res = person1.to_response()
    assert rv['code'] == 200
    assert rv['data']['first_name'] == person1_res['first_name']
    assert rv['data']['last_name'] == person1_res['last_name']
    assert rv['data']['full_name'] == person1_res['full_name']
    assert len(rv['data']['books']) == 2


@bolitest(before=utils.book.set_up)

3 Source : test_person_ctrl.py
with MIT License
from bolinette

async def test_get_person_books(client: BolitestClient):
    person1 = client.mock(1, 'person')
    book1 = client.mock(1, 'book')
    book2 = client.mock(2, 'book')

    rv = await client.get(f'/person/{person1["uid"]}')
    assert rv['code'] == 200
    assert len(rv['data']['books']) == 2
    assert any((b for b in rv['data']['books'] if b['uid'] == book1['uid']))
    assert any((b for b in rv['data']['books'] if b['uid'] == book2['uid']))
    assert (rv['data']['last_book']['uid'] ==
            sorted([book1, book2], key=lambda b: b['publication_date'], reverse=True)[0]['uid'])

3 Source : test_tag_ctrl.py
with MIT License
from bolinette

async def test_get_tags(client: BolitestClient):
    rv = await client.get('/tag')
    assert rv['code'] == 200
    assert len(rv['data']) == 6
    for i in range(6):
        tag = client.mock(i + 1, 'tag')
        assert rv['data'][i]['name'] == tag['name']


@bolitest(before=tags_setup)

3 Source : test_tag_ctrl.py
with MIT License
from bolinette

async def test_get_tag(client: BolitestClient):
    tag1 = client.mock(1, 'tag')
    tag4 = client.mock(4, 'tag')
    tag6 = client.mock(6, 'tag')
    tag6['children'] = []
    tag4['children'] = [tag6]
    tag1['children'] = [tag4]

    rv = await client.get(f'/tag/{tag1["name"]}')
    assert rv['code'] == 200
    assert_tags_equal(rv['data'], tag1)


@bolitest()

3 Source : test_tag_ctrl.py
with MIT License
from bolinette

async def test_create_tag(client: BolitestClient):
    tag1 = client.mock(1, 'tag')

    rv = await client.post('/tag', tag1.to_payload())
    assert rv['code'] == 201


@bolitest()

3 Source : test_tag_ctrl.py
with MIT License
from bolinette

async def test_get_tag_labels(client: BolitestClient):
    tag1 = client.mock(1, 'tag')

    rv = await client.get(f'/tag/{tag1["name"]}')
    assert len(rv['data']['labels']) == 2
    assert len([label for label in rv['data']['labels'] if label['id'] == 1]) == 1
    assert len([label for label in rv['data']['labels'] if label['id'] == 2]) == 1


@bolitest(before=labels_setup)

3 Source : test_tag_ctrl.py
with MIT License
from bolinette

async def test_get_label(client: BolitestClient):
    tag1 = client.mock(1, 'tag')
    label1 = client.mock(1, 'label')

    rv = await client.get(f'/label/{tag1["name"]}/1')
    assert rv['code'] == 200
    assert rv['data']['tag']['name'] == tag1['name']
    assert rv['data']['name'] == label1['name']


@bolitest(before=labels_setup)

3 Source : test_tag_ctrl.py
with MIT License
from bolinette

async def test_get_label_not_found(client: BolitestClient):
    tag1 = client.mock(1, 'tag')

    rv = await client.get(f'/label/{tag1["name"]}/3')
    assert rv['code'] == 404
    assert f'entity.not_found:label:tag.name,id:{tag1["name"]},3'

    rv = await client.get('/label/non_existing_tag/1')
    assert rv['code'] == 404
    assert 'entity.not_found:label:tag.name,id:non_existing_tag,1'

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_login_failed(client):
    user1 = client.mock(1, 'user')

    rv = await client.post('/user/login', {'username': user1['username'],
                                           'password': user1['password'][:-1]})
    assert rv['code'] == 401
    assert 'user.login.wrong_credentials' in rv['messages']

    rv = await client.post('/user/login', {'username': user1['username'] + "2",
                                           'password': user1['password']})
    assert rv['code'] == 401
    assert 'user.login.wrong_credentials' in rv['messages']


@bolitest(before=set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_login(client):
    user1 = client.mock(1, 'user')

    rv = await client.post('/user/login', user1.to_payload('login'))
    assert rv['code'] == 200


@bolitest(before=set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_access_user_info(client):
    user1 = client.mock(1, 'user')

    rv = await client.post('/user/login', user1.to_payload('login'))
    assert rv['code'] == 200

    rv = await client.get('/user/info')
    assert rv['code'] == 200
    assert rv['data'].get('username') == user1['username']
    assert rv['data'].get('email') == user1['email']
    assert rv['data'].get('password') is None


@bolitest(before=set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_logout(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.get('/user/info')
    assert rv['code'] == 200

    rv = await client.post('/user/logout')
    assert rv['code'] == 200

    rv = await client.get('/user/info')
    assert rv['code'] == 401


@bolitest(before=set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_register(client):
    user2 = client.mock(2, 'user', post_mock_fn=_fix_mocked_user)

    rv = await client.post('/user/register', user2.to_payload('register'))
    assert rv['code'] == 201

    rv = await client.post('/user/login', user2.to_payload('login'))
    assert rv['code'] == 200


@bolitest(before=set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_logged_in_after_register(client):
    user2 = client.mock(2, 'user', post_mock_fn=_fix_mocked_user)

    rv = await client.post('/user/register', user2.to_payload('register'))
    assert rv['code'] == 201

    rv = await client.get('/user/info')
    assert rv['code'] == 200
    assert rv['data'].get('username') == user2['username']
    assert rv['data'].get('email') == user2['email']


@bolitest(before=set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_register_conflict(client):
    user1 = client.mock(1, 'user', post_mock_fn=_fix_mocked_user)

    rv = await client.post('/user/register', user1.to_payload('register'))
    assert rv['code'] == 409
    assert f'param.conflict:username:{user1["username"]}' in rv['messages']
    assert f'param.conflict:email:{user1["email"]}' in rv['messages']


@bolitest(before=set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_change_username(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.patch('/user/me', {'username': 'new_username'})
    assert rv['code'] == 200
    assert rv['data']['username'] == 'new_username'
    assert rv['data']['email'] == user1['email']


@bolitest(before=set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_change_password(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))
    await client.patch('/user/me', {'password': 'new_password'})
    await client.post('/user/logout')
    await client.post('/user/login', {'username': user1['username'], 'password': 'new_password'})

    rv = await client.get('/user/info')
    assert rv['code'] == 200


@bolitest(before=admin_set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_get_users(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.get('/user')
    assert rv['code'] == 200
    assert len(rv['data']) == 2


@bolitest(before=admin_set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_get_users_forbidden(client):
    user1 = client.mock(2, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.get('/user')
    assert rv['code'] == 403
    assert 'user.forbidden:admin' in rv['messages']


@bolitest(before=admin_set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_add_self_role(client):
    user1 = client.mock(1, 'user')
    role1 = client.mock(1, 'role')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.post(f'/user/{user1["username"]}/roles', role1.to_payload())
    assert rv['code'] == 201
    assert f'user.roles.added:{user1["username"]}:{role1["name"]}' in rv['messages']


@bolitest(before=admin_set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_add_role_not_admin(client):
    user2 = client.mock(2, 'user')
    role1 = client.mock(1, 'role')

    await client.post('/user/login', user2.to_payload('login'))

    rv = await client.post(f'/user/{user2["username"]}/roles', role1.to_payload())
    assert rv['code'] == 403
    assert 'user.forbidden:admin' in rv['messages']


@bolitest(before=admin_set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_remove_role(client):
    user1 = client.mock(1, 'user')
    role1 = client.mock(1, 'role')

    await client.post('/user/login', user1.to_payload('login'))
    await client.post(f'/user/{user1["username"]}/roles', role1.to_payload())

    rv = await client.delete(f'/user/{user1["username"]}/roles/{role1["name"]}')
    assert rv['code'] == 200
    assert f'user.roles.removed:{user1["username"]}:{role1["name"]}' in rv['messages']


@bolitest(before=admin_set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_remove_role_not_found(client):
    user1 = client.mock(1, 'user')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.delete(f'/user/{user1["username"]}/roles/unknown_role')
    assert rv['code'] == 404
    assert 'entity.not_found:role:name:unknown_role' in rv['messages']


@bolitest(before=admin_set_up)

3 Source : test_user_ctrl.py
with MIT License
from bolinette

async def test_remove_role_not_in_user_roles(client):
    user1 = client.mock(1, 'user')
    role1 = client.mock(1, 'role')

    await client.post('/user/login', user1.to_payload('login'))

    rv = await client.delete(f'/user/{user1["username"]}/roles/{role1["name"]}')
    assert rv['code'] == 422
    assert f'user.roles.not_found:{user1["username"]}:{role1["name"]}' in rv['messages']


@bolitest(before=admin_set_up)

See More Examples