2016-11-07 11 views
1

フラスコサービスでポストコールを作成することはできません。Pytest、Jenkins、FlaskでPOSTコールを実行できません

def test_post_create_file(client): 
     fileContent = {'filename': 'TestName', 'content': 'TestContent'} 
     client.post('/v1.0/files', data = json.dumps(fileContent)) 

POST機能:ここに私のコードです

@app.route('/v1.0/files',methods=['POST']) 
def read_create_file(): 
    cont = request.get_json(silent=True) 
    file = cont['filename'] 
    content = cont['content'] 
    if not file or not content: 
    return "empty file or content", 404 
    if create_file(file, content): 
    return "CREATED", 200 

例外:

Error Message 

TypeError: 'NoneType' object is unsubscriptable 

Trace 

client = <FlaskClient <Flask 'e'>> 

    def test_post_create_file(client): 
     fileContent = {'filename': 'ArchivoPrueba', 'content': 'ContenidoPrueba'} 
>  client.post('/v1.0/files', data = json.dumps(fileContent)) 

test_e.py:24: 

私はそれが配列としてJSONオブジェクトにアクセスしようとは何かを持っていると信じて、確信はないけど。

def test_post_create_file(client): 
     fileContent = {'filename': 'ArchivoPrueba', 'content': 'ContenidoPrueba'} 
     client.post('/v1.0/files', data = json.dumps(fileContent), content_type='application/json') 

CONTENT_TYPEパラメータが欠落していました:

答えて

0

ただ答えを見つけました。

関連する問題