import unittest
from performance.web import Request, RequestTypeError, RequestTimeError


class RequestTestCase(unittest.TestCase):
    def setUp(self):
        self.url = 'http://www.google.com'

    def test_constants(self):
        self.assertEqual('get', Request.GET)
        self.assertEqual('post', Request.POST)

    def test_init(self):
        request = Request(url=self.url)
        self.assertEqual(Request.GET, request.type)
        self.assertEqual(self.url, request.url)
        request = Request(url=self.url, type=Request.POST)
        self.assertEqual(Request.POST, request.type)

    def test_do(self):
        request = Request(url=self.url, type=Request.GET)
        request.do()
        self.assertTrue(hasattr(request, 'status_code'))
        request.type = Request.POST
        request.do()
        self.assertTrue(hasattr(request, 'status_code'))

    def test_invalid_type(self):
        type = 'foo_bar'
        request = Request(url=self.url, type=type)
        with self.assertRaises(RequestTypeError) as error:
            request.do()
        self.assertEqual('Invalid request type "%s"' % type, error.exception.__str__())

    def test_response_time(self):
        request = Request(url=self.url, type=Request.GET)
        request.do()
        self.assertEqual(request.finished - request.started, request.get_response_time())

    def test_time_error(self):
        request = Request(url=self.url, type=Request.GET)
        with self.assertRaises(RequestTimeError):
            request.get_response_time()

import unittest
from performance.web import Request, RequestTypeError, RequestTimeError


class RequestTestCase(unittest.TestCase):
    def setUp(self):
        self.host = 'http://www.google.com'

    def test_constants(self):
        self.assertEqual('get', Request.GET)
        self.assertEqual('post', Request.POST)

    def test_init(self):
        request = Request(url=self.host)
        self.assertEqual(Request.GET, request.type)
        self.assertEqual(self.host, request.url)
        request = Request(url=self.host, type=Request.POST)
        self.assertEqual(Request.POST, request.type)

    def test_do(self):
        request = Request(url=self.host, type=Request.GET)
        request.do()

    def test_invalid_type(self):
        type = 'foo_bar'
        request = Request(url=self.host, type=type)
        with self.assertRaises(RequestTypeError) as error:
            request.do()
        self.assertEqual('Invalid request type "%s"' % type, error.exception.__str__())

Remove tests for response_time, update variable names
Remove tests for response_time, update variable names

  import unittest
  from performance.web import Request, RequestTypeError, RequestTimeError
  
  
  class RequestTestCase(unittest.TestCase):
      def setUp(self):
-         self.url = 'http://www.google.com'
+         self.host = 'http://www.google.com'
  
      def test_constants(self):
          self.assertEqual('get', Request.GET)
          self.assertEqual('post', Request.POST)
  
      def test_init(self):
-         request = Request(url=self.url)
+         request = Request(url=self.host)
          self.assertEqual(Request.GET, request.type)
-         self.assertEqual(self.url, request.url)
+         self.assertEqual(self.host, request.url)
-         request = Request(url=self.url, type=Request.POST)
+         request = Request(url=self.host, type=Request.POST)
          self.assertEqual(Request.POST, request.type)
  
      def test_do(self):
-         request = Request(url=self.url, type=Request.GET)
+         request = Request(url=self.host, type=Request.GET)
          request.do()
-         self.assertTrue(hasattr(request, 'status_code'))
-         request.type = Request.POST
-         request.do()
-         self.assertTrue(hasattr(request, 'status_code'))
  
      def test_invalid_type(self):
          type = 'foo_bar'
-         request = Request(url=self.url, type=type)
+         request = Request(url=self.host, type=type)
          with self.assertRaises(RequestTypeError) as error:
              request.do()
          self.assertEqual('Invalid request type "%s"' % type, error.exception.__str__())
  
-     def test_response_time(self):
-         request = Request(url=self.url, type=Request.GET)
-         request.do()
-         self.assertEqual(request.finished - request.started, request.get_response_time())
- 
-     def test_time_error(self):
-         request = Request(url=self.url, type=Request.GET)
-         with self.assertRaises(RequestTimeError):
-             request.get_response_time()
- 
Remove tests for response_time, update variable names
## Code Before:
import unittest
from performance.web import Request, RequestTypeError, RequestTimeError


class RequestTestCase(unittest.TestCase):
    def setUp(self):
        self.url = 'http://www.google.com'

    def test_constants(self):
        self.assertEqual('get', Request.GET)
        self.assertEqual('post', Request.POST)

    def test_init(self):
        request = Request(url=self.url)
        self.assertEqual(Request.GET, request.type)
        self.assertEqual(self.url, request.url)
        request = Request(url=self.url, type=Request.POST)
        self.assertEqual(Request.POST, request.type)

    def test_do(self):
        request = Request(url=self.url, type=Request.GET)
        request.do()
        self.assertTrue(hasattr(request, 'status_code'))
        request.type = Request.POST
        request.do()
        self.assertTrue(hasattr(request, 'status_code'))

    def test_invalid_type(self):
        type = 'foo_bar'
        request = Request(url=self.url, type=type)
        with self.assertRaises(RequestTypeError) as error:
            request.do()
        self.assertEqual('Invalid request type "%s"' % type, error.exception.__str__())

    def test_response_time(self):
        request = Request(url=self.url, type=Request.GET)
        request.do()
        self.assertEqual(request.finished - request.started, request.get_response_time())

    def test_time_error(self):
        request = Request(url=self.url, type=Request.GET)
        with self.assertRaises(RequestTimeError):
            request.get_response_time()

## Instruction:
Remove tests for response_time, update variable names
## Code After:
import unittest
from performance.web import Request, RequestTypeError, RequestTimeError


class RequestTestCase(unittest.TestCase):
    def setUp(self):
        self.host = 'http://www.google.com'

    def test_constants(self):
        self.assertEqual('get', Request.GET)
        self.assertEqual('post', Request.POST)

    def test_init(self):
        request = Request(url=self.host)
        self.assertEqual(Request.GET, request.type)
        self.assertEqual(self.host, request.url)
        request = Request(url=self.host, type=Request.POST)
        self.assertEqual(Request.POST, request.type)

    def test_do(self):
        request = Request(url=self.host, type=Request.GET)
        request.do()

    def test_invalid_type(self):
        type = 'foo_bar'
        request = Request(url=self.host, type=type)
        with self.assertRaises(RequestTypeError) as error:
            request.do()
        self.assertEqual('Invalid request type "%s"' % type, error.exception.__str__())
