import os
import unittest
import vcr
import urllib2

TEST_CASSETTE_FILE = 'test/test_req.yaml'


class TestHttpRequest(unittest.TestCase):

    def tearDown(self):
        try:
            os.remove(TEST_CASSETTE_FILE)
        except OSError:
            pass

    def test_response_code(self):
        code = urllib2.urlopen('http://www.iana.org/domains/example/').getcode()
        with vcr.use_cassette(TEST_CASSETTE_FILE):
            self.assertEqual(code, urllib2.urlopen('http://www.iana.org/domains/example/').getcode())
            self.assertEqual(code, urllib2.urlopen('http://www.iana.org/domains/example/').getcode())

    def test_response_body(self):
        body = urllib2.urlopen('http://www.iana.org/domains/example/').read()
        with vcr.use_cassette(TEST_CASSETTE_FILE):
            self.assertEqual(body, urllib2.urlopen('http://www.iana.org/domains/example/').read())
            self.assertEqual(body, urllib2.urlopen('http://www.iana.org/domains/example/').read())

    def test_response_headers(self):
        with vcr.use_cassette(TEST_CASSETTE_FILE):
            headers = urllib2.urlopen('http://www.iana.org/domains/example/').info().items()
            self.assertEqual(headers, urllib2.urlopen('http://www.iana.org/domains/example/').info().items())


class TestHttps(unittest.TestCase):

    def tearDown(self):
        try:
            os.remove(TEST_CASSETTE_FILE)
        except OSError:
            pass
    
    def test_response_code(self):
        code = urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').getcode()
        with vcr.use_cassette(TEST_CASSETTE_FILE):
            self.assertEqual(code, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').getcode())
            self.assertEqual(code, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').getcode())

    def test_response_body(self):
	body = urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').read()
        with vcr.use_cassette(TEST_CASSETTE_FILE):
            self.assertEqual(body, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').read())
            self.assertEqual(body, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').read())

    def test_response_headers(self):
        with vcr.use_cassette(TEST_CASSETTE_FILE):
            headers = urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').info().items()
            self.assertEqual(headers, urllib2.urlopen('https://api.twitter.com/1/legal/tos.json').info().items())
   

if __name__ == '__main__':
    unittest.main()

@@ -1279,16 +1279,652 @@
 ems())%0A%0A
+    def test_multiple_requests(self):%0A        body1 = urllib2.urlopen('http://www.iana.org/domains/example/').read()%0A%09body2 = urllib2.urlopen('http://api.twitter.com/1/legal/tos.json').read()%0A        with vcr.use_cassette(TEST_CASSETTE_FILE):%0A            self.assertEqual(body1, urllib2.urlopen('http://www.iana.org/domains/example/').read())%0A%09    self.assertEqual(body2, urllib2.urlopen('http://api.twitter.com/1/legal/tos.json').read())%0A            self.assertEqual(body1, urllib2.urlopen('http://www.iana.org/domains/example/').read())%0A%09    self.assertEqual(body2, urllib2.urlopen('http://api.twitter.com/1/legal/tos.json').read())%0A%0A
 %0Aclass T
@@ -2495,17 +2495,24 @@
 (self):%0A
-%09
+        
 body = u

add tests for multiple requests