Ho seguente codicedati del modulo mancanti nella richiesta
class MyClass(restful.Resource):
def get(self):
headers = {'Content-Type': 'text/html'}
return make_response(render_template('myfile.html'),200,headers)
def post(self):
session['CONSUMER_KEY']=request.form.get('consumer_key')
session['CONSUMER_SECRET']=request.form.get('consumer_secret')
render_template('myfile.html')
api.add_resource(MyClass,"/mag/",endpoint="mag")
ho scritto seguente test:
def mytest(self):
content_type={"Content-Type": "application/x - www - form - urlencoded","Content-Disposition": "form-data"}
response = self.client.post(
api.url_for(MyClass), data = json.dumps({'consumer_key':'testconsumerkey',
'consumer_secret':'testconsumersecret'}),
headers=content_type
)
La questione è di dati forma è vuoto e questo è i valori non sono sempre impostate in sessione. Quando eseguo il debug, vedo che request.data è popolato ma request.form è un dizionario vuoto. Qualcuno può suggerire come posso inviare i dati del modulo in una richiesta di post da un test
MODIFICA: Dettagli ambiente Python 2.7, framework web Flask, self.client is. Sto usando flask.ext.testing
Potrebbe aggiungere som dettagli circa il vostro ambiente? È una fiasca, giusto? Che tipo è 'self.client' nel tuo test? –
Python 2.7, Flask framework web, self.client è –
Priyam