Skip to content
Myr

test_requests.py

This file

Path

test_requests.py

61 lines · 1.4 KiB · Python

Last changed by

added simple test fixture for Postbin and posting Kenneth Reitzbefore adoption02834e3

History of this file

Take it

sample test fixtures (none)Kenneth Reitzbefore adoption75b499d

lines 1–3why, one step back
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-3

added simple test fixture for Postbin and posting Kenneth Reitzbefore adoption02834e3

line 4why, one step back
4

sample test fixtures (none)Kenneth Reitzbefore adoption75b499d

line 5why, one step back
5import unittest

added simple test fixture for Postbin and posting Kenneth Reitzbefore adoption02834e3

line 6why, one step back
6from cStringIO import StringIO

temp "tests"Kenneth Reitzbefore adoption49f915f

lines 7–10why, one step back
7
8import requests910

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

lines 11–15why, one step back
11class RequestsTestSuite(unittest.TestCase):
12 """Requests test cases."""13 14 def setUp(self):15 pass

temp "tests"Kenneth Reitzbefore adoption49f915f

line 16why, one step back
16

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

lines 17–45why, one step back
17 def tearDown(self):
18 """Teardown."""19 pass20 21 def test_invalid_url(self):22 self.assertRaises(ValueError, requests.get, 'hiwpefhipowhefopw')2324 def test_HTTP_200_OK_GET(self):25 r = requests.get('http://google.com')26 self.assertEqual(r.status_code, 200)2728 def test_HTTPS_200_OK_GET(self):29 r = requests.get('https://google.com')30 self.assertEqual(r.status_code, 200)3132 def test_HTTP_200_OK_HEAD(self):33 r = requests.head('http://google.com')34 self.assertEqual(r.status_code, 200)3536 def test_HTTPS_200_OK_HEAD(self):37 r = requests.head('https://google.com')38 self.assertEqual(r.status_code, 200)3940 def test_AUTH_HTTPS_200_OK_GET(self):41 auth = requests.AuthObject('requeststest', 'requeststest')42 url = 'https://convore.com/api/account/verify.json'43 r = requests.get(url, auth=auth)4445 self.assertEqual(r.status_code, 200)

added simple test fixture for Postbin and posting Kenneth Reitzbefore adoption02834e3

lines 46–57why, one step back
46
47 def test_POSTBIN_GET_POST_FILES(self):4849 bin = requests.post('http://www.postbin.org/')50 self.assertEqual(bin.status_code, 200)5152 post = requests.post(bin.url, data={'some': 'data'})53 self.assertEqual(post.status_code, 201)5455 post2 = requests.post(bin.url, files={'some': StringIO('data')})56 self.assertEqual(post2.status_code, 201)57

a few test fixtures for nowKenneth Reitzbefore adoption4a3f559

lines 58–61why, one step back
58
5960if __name__ == '__main__':61 unittest.main()