import unittest
from pydirections.route_requester import DirectionsRequest
from pydirections.exceptions import InvalidModeError, InvalidAPIKeyError, InvalidAlternativeError

requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA")

class TestOptionalParameters(unittest.TestCase):
	def test_invalid_mode(self):
		"""
		    Tests the is_valid_mode function for an invalid input
		"""
		with self.assertRaises(InvalidModeError):
			requester.set_mode("flying")

	def test_invalid_alternative(self):
		"""
			Tests for error handling when an invalid value is provided to
			the set_alternative function
		"""
		with self.assertRaises(InvalidAlternativeError):
			requester.set_alternatives('False')

	def test_invalid_restrictions(self):
		"""
			Tests for invalid route restrictions
		"""
		with self.assertRaises(ValueError):
			requester.set_route_restrictions("freeways", "railways")

class TestAPIKey(unittest.TestCase):
	
	def test_invalid_api_key(self):
		invalid_key = 123456
		with self.assertRaises(InvalidAPIKeyError):
			requester.set_api_key(invalid_key)

if __name__ == '__main__':
	unittest.main()
import unittest
from pydirections.route_requester import DirectionsRequest
from pydirections.exceptions import InvalidModeError, InvalidAPIKeyError, InvalidAlternativeError
import os

MAPS_API_KEY = os.environ['MAPS_API_KEY']

class TestOptionalParameters(unittest.TestCase):
	def test_invalid_mode(self):
		"""
		    Tests the is_valid_mode function for an invalid input
		"""
		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
		with self.assertRaises(InvalidModeError):
			requester.set_mode("flying")

	def test_invalid_alternative(self):
		"""
			Tests for error handling when an invalid value is provided to
			the set_alternative function
		"""
		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
		with self.assertRaises(InvalidAlternativeError):
			requester.set_alternatives('False')

	def test_invalid_restrictions(self):
		"""
			Tests for invalid route restrictions
		"""
		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
		with self.assertRaises(ValueError):
			requester.set_route_restrictions("freeways", "railways")

class TestAPIKey(unittest.TestCase):
	def test_invalid_api_key(self):
		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
		invalid_key = 123456
		with self.assertRaises(InvalidAPIKeyError):
			requester.set_api_key(invalid_key)

if __name__ == '__main__':
	unittest.main()
Refactor tests to include API KEY
Refactor tests to include API KEY

  import unittest
  from pydirections.route_requester import DirectionsRequest
  from pydirections.exceptions import InvalidModeError, InvalidAPIKeyError, InvalidAlternativeError
+ import os
  
- requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA")
+ MAPS_API_KEY = os.environ['MAPS_API_KEY']
  
  class TestOptionalParameters(unittest.TestCase):
  	def test_invalid_mode(self):
  		"""
  		    Tests the is_valid_mode function for an invalid input
  		"""
+ 		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
  		with self.assertRaises(InvalidModeError):
  			requester.set_mode("flying")
  
  	def test_invalid_alternative(self):
  		"""
  			Tests for error handling when an invalid value is provided to
  			the set_alternative function
  		"""
+ 		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
  		with self.assertRaises(InvalidAlternativeError):
  			requester.set_alternatives('False')
  
  	def test_invalid_restrictions(self):
  		"""
  			Tests for invalid route restrictions
  		"""
+ 		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
  		with self.assertRaises(ValueError):
  			requester.set_route_restrictions("freeways", "railways")
  
  class TestAPIKey(unittest.TestCase):
- 	
  	def test_invalid_api_key(self):
+ 		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
  		invalid_key = 123456
  		with self.assertRaises(InvalidAPIKeyError):
  			requester.set_api_key(invalid_key)
  
  if __name__ == '__main__':
  	unittest.main()
Refactor tests to include API KEY
## Code Before:
import unittest
from pydirections.route_requester import DirectionsRequest
from pydirections.exceptions import InvalidModeError, InvalidAPIKeyError, InvalidAlternativeError

requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA")

class TestOptionalParameters(unittest.TestCase):
	def test_invalid_mode(self):
		"""
		    Tests the is_valid_mode function for an invalid input
		"""
		with self.assertRaises(InvalidModeError):
			requester.set_mode("flying")

	def test_invalid_alternative(self):
		"""
			Tests for error handling when an invalid value is provided to
			the set_alternative function
		"""
		with self.assertRaises(InvalidAlternativeError):
			requester.set_alternatives('False')

	def test_invalid_restrictions(self):
		"""
			Tests for invalid route restrictions
		"""
		with self.assertRaises(ValueError):
			requester.set_route_restrictions("freeways", "railways")

class TestAPIKey(unittest.TestCase):
	
	def test_invalid_api_key(self):
		invalid_key = 123456
		with self.assertRaises(InvalidAPIKeyError):
			requester.set_api_key(invalid_key)

if __name__ == '__main__':
	unittest.main()
## Instruction:
Refactor tests to include API KEY
## Code After:
import unittest
from pydirections.route_requester import DirectionsRequest
from pydirections.exceptions import InvalidModeError, InvalidAPIKeyError, InvalidAlternativeError
import os

MAPS_API_KEY = os.environ['MAPS_API_KEY']

class TestOptionalParameters(unittest.TestCase):
	def test_invalid_mode(self):
		"""
		    Tests the is_valid_mode function for an invalid input
		"""
		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
		with self.assertRaises(InvalidModeError):
			requester.set_mode("flying")

	def test_invalid_alternative(self):
		"""
			Tests for error handling when an invalid value is provided to
			the set_alternative function
		"""
		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
		with self.assertRaises(InvalidAlternativeError):
			requester.set_alternatives('False')

	def test_invalid_restrictions(self):
		"""
			Tests for invalid route restrictions
		"""
		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
		with self.assertRaises(ValueError):
			requester.set_route_restrictions("freeways", "railways")

class TestAPIKey(unittest.TestCase):
	def test_invalid_api_key(self):
		requester = DirectionsRequest(origin="San Francisco, CA", destination="Palo Alto, CA", key=MAPS_API_KEY)
		invalid_key = 123456
		with self.assertRaises(InvalidAPIKeyError):
			requester.set_api_key(invalid_key)

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