def test_put_new_object(get_client, resource, id_): ''' PUT new object, test if * the same user can GET it * other user can't GET it ''' init_cookies_with_user_id() client = get_client(auth_required=True) # 1. Login as user 1 client.login({'user_id': 1}) # 2. Create object data, status, headers = client.put(resource, id_, {}) assert status == 201 # 3. Test if creator has access data, status, headers = client.get(resource, id_) assert status == 200 # 4. Test if not logged gets 401 client.logout() data, status, headers = client.get(resource, id_) assert status == 401 # 5. Test if other user gets 404 client.login({'user_id': 2}) data, status, headers = client.get(resource, id_) assert status == 404 # 6. Test again correct user client.logout() client.login({'user_id': 1}) data, status, headers = client.get(resource, id_) assert status == 200
def test_put_on_existing(get_client, user_id, resource, id_, expected_status): ''' Test if PUT on existing object returns correct status ''' init_cookies_with_user_id() client = get_client(auth_required=True) client.login({'user_id': user_id}) data, status, headers = client.patch(resource, id_, {}) assert status == expected_status
def test_delete(get_client, user_id, resource, id_, expected_status): ''' Test if DELETE on object returns correct status ''' init_cookies_with_user_id() client = get_client(auth_required=True) client.login({'user_id': user_id}) data, status, headers = client.delete(resource, id_) assert status == expected_status
def test_401_no_auth_2(get_client, args): ''' 401 without authentication (client does not permit logging in) ''' init_cookies_with_user_id() client = get_client() method, *other_args = args data, status, headers = getattr(client, method)(*other_args) assert status == 401
def test_401_no_auth_1(get_client, args): ''' 401 without authentication ''' init_cookies_with_user_id() client = get_client(auth_required=True) method, *other_args = args data, status, headers = getattr(client, method)(*other_args) assert status == 401
def test_get_1(get_client, user_id, resource, expected_ids): ''' Test if GET on collection returns correct entities ''' init_cookies_with_user_id() client = get_client(auth_required=True) client.login({'user_id': user_id}) data, status, headers = client.get(resource, depth=0) assert status == 200 assert data == expected_ids
def test_401_incorrect_auth(get_client, args): ''' 401 with empty authentication ''' init_cookies_with_user_id() client = get_client(auth_required=True) client.login({'some': 'thing'}) method, *other_args = args data, status, headers = getattr(client, method)(*other_args) assert status == 401