def test_http_form_data(self): handler = HttpHandler(self.options) file = File(self.barcode, filename_format="%(id)s.pdf") form_data = handler.get_form_data(file) self.assertDictEqual(form_data, {'token': 'foobar', 'id': '600144'})
def test_http_call(self): handler = HttpHandler(Options(form_data=['token=7ff1e8749c107ff1e8749c107ff1e8749c10', 'typeid=29'])) file = File(self.barcode, filename_format="%(id)s.pdf") form_data = handler.get_form_data(file) file.add(Page(self.pdf_file.getPage(0))) file.add(Page(self.pdf_file.getPage(1))) f = StringIO.StringIO() file.write(f) files = {'file': (file.get_filename(), f.getvalue(), 'application/pdf', {})} # url = 'https://devmanager.edustaff.org/manager/einfo/getpost/auto_file_upload.aspx' url = 'http://localhost:9000/upload' r = requests.post(url, data=form_data, files=files) self.assertEquals(r.status_code, 200) self.assertIn('id: 600144', r.text)