コード例 #1
0
ファイル: test_item.py プロジェクト: duong-le/flask-photo-app
 def test_create_item_with_invalid_length(self, client):
     access_token = get_access_token(client)
     long_name = {
         'description': 'g' * 201,
         'image_url': f'https://googl{"e" * 200}.com',
     }
     response = post(client, '/categories/1/items', long_name, access_token)
     assert response.status_code == 400
コード例 #2
0
def test_request_with_invalid_body(client):
    access_token = get_access_token(client)
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {access_token}'
    }
    response = client.post('/categories/1/items', headers=headers, data='{,}')
    assert response.status_code == 400
コード例 #3
0
ファイル: test_item.py プロジェクト: duong-le/flask-photo-app
 def test_create_item_with_invalid_category_id(self, client):
     access_token = get_access_token(client)
     body = {
         'description':
         'Countryside',
         'image_url':
         'https://upload.wikimedia.org/wikipedia/commons/3/35/Neckertal_20150527-6384.jpg',
     }
     response = post(client, '/categories/5/items', body, access_token)
     assert response.status_code == 404
コード例 #4
0
ファイル: test_item.py プロジェクト: duong-le/flask-photo-app
 def test_create_item_with_invalid_type(self, client):
     access_token = get_access_token(client)
     body = {
         'description':
         1234567,
         'image_url':
         'upload.wikimedia.org/wikipedia/commons/3/35/Neckertal_20150527-6384.jpg',
     }
     response = post(client, '/categories/1/items', body, access_token)
     assert response.status_code == 400
コード例 #5
0
ファイル: test_item.py プロジェクト: duong-le/flask-photo-app
 def test_update_item_with_invalid_author(self, client):
     access_token = get_access_token(client)
     body = {
         'description':
         'Beach',
         'image_url':
         'https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/beach-quotes-1559667853.jpg',
     }
     response = put(client, '/categories/1/items/3', body, access_token)
     assert response.status_code == 403
コード例 #6
0
 def test_create_category_with_unknown_field(self, client):
     access_token = get_access_token(client)
     body = {
         'name': 'Landscape',
         'description': 'Countryside',
         'image_url':
         'https://upload.wikimedia.org/wikipedia/commons/3/35/Neckertal_20150527-6384.jpg',
         'title': 'Beautiful countryside'
     }
     response = post(client, '/categories', body, access_token)
     assert response.status_code == 400
コード例 #7
0
 def test_create_category_with_empty_field(self, client):
     access_token = get_access_token(client)
     body = {
         'name':
         '',
         'description':
         '',
         'image_url':
         'https://upload.wikimedia.org/wikipedia/commons/3/35/Neckertal_20150527-6384.jpg',
     }
     response = post(client, '/categories', body, access_token)
     assert response.status_code == 400
コード例 #8
0
 def test_create_category_with_valid_body(self, client):
     access_token = get_access_token(client)
     body = {
         'name':
         'Landscape',
         'description':
         'Countryside',
         'image_url':
         'https://upload.wikimedia.org/wikipedia/commons/3/35/Neckertal_20150527-6384.jpg',
     }
     response = post(client, '/categories', body, access_token)
     assert response.status_code == 201
     assert response.get_json()['name'] == body['name']
     assert response.get_json()['description'] == body['description']
     assert response.get_json()['image_url'] == body['image_url']
コード例 #9
0
 def test_create_category_with_missing_field(self, client):
     access_token = get_access_token(client)
     body = {'name': 'Landscape', 'description': 'Countryside'}
     response = post(client, '/categories', body, access_token)
     assert response.status_code == 400
コード例 #10
0
ファイル: test_user.py プロジェクト: tinhvqbk/flask-photo-app
 def test_get_user_with_valid_token(self, client):
     access_token = get_access_token(client)
     response = get(client, '/users/me', access_token)
     assert response.status_code == 200
     assert response.get_json()['id'] == 1
     assert response.get_json()['name'] == 'Duong Le'
コード例 #11
0
ファイル: test_item.py プロジェクト: duong-le/flask-photo-app
 def test_delete_item_with_invalid_author(self, client):
     access_token = get_access_token(client)
     response = delete(client, '/categories/1/items/3', access_token)
     assert response.status_code == 403