def test_dollars_to_target(self, mock_rates): mock_rate = 12.34567 # Any number will do. # As long as the JSON contains the data the program needs, it does not need to be a complete response example_api_response = {'base': 'USD', 'date': '2019-02-04', 'rates': {'EUR': mock_rate}} mock_rates.side_effect = [ example_api_response ] # 100 dollars is 1234.567 Euros at this made up exchange rate converted = exchange_rate.convert_dollars_to_target(100, 'EUR') self.assertEqual(1234.567, converted)
def test_dollars_to_target_2(self, mock_requests_get): mock_rate = 123.4567 example_api_response = {"rates":{"CAD": mock_rate},"base":"USD","date":"2020-10-02"} # Another mock for the mock_requests_get - the .json() method needs to return the example response mock_requests_get().json.return_value = example_api_response converted = exchange_rate.convert_dollars_to_target(100, 'CAD') expected = 12345.67 self.assertEqual(expected, converted)
def test_request_rates(self, mock_rate): mock_rate = 15.00 example_api_response = { 'base': 'USD', 'date': '2019-02-04', 'rates': { 'EUR': mock_rate } } mock_rate.side_effect = [example_api_response] converted = exchange_rate.convert_dollars_to_target(100, 'EUR') self.assertEqual(15.00, converted)
def test_dollars_to_target(self, mock_rates): mock_rate = 12.34567 # any number will do example_api_response = { 'base': 'USD', 'date': '2019-02-04', 'rates': { 'EUR': mock_rate } } mock_rates.side_effect = [example_api_response] #100 dollars is 1234.567 Euros at this made up exchange rate converted = exchange_rate.convert_dollars_to_target(100, 'EUR') self.assertEqual(1234.567, converted)
def test_dollars_to_target_2(self, mock_requests_json): mock_rate = 123.4567 example_api_response = { "rates": { "CAD": mock_rate }, "base": "USD", "date": "2020-10-02" } mock_requests_json.return_value = example_api_response converted = exchange_rate.convert_dollars_to_target(100, 'CAD') expected = 12345.67 self.assertEqual(expected, converted)