Skip to content

Instantly share code, notes, and snippets.

@smoothml
Created February 23, 2018 09:36
Show Gist options
  • Save smoothml/b712ee33814fb9afe2cdbb3ed19ba0d3 to your computer and use it in GitHub Desktop.
Save smoothml/b712ee33814fb9afe2cdbb3ed19ba0d3 to your computer and use it in GitHub Desktop.
2018-02-23 Serverless computing tests.py
class TestClass(TestCase):
def setUp(self):
self.test_response = TEST_RESPONSE
self.test_response_reformatted = TEST_RESPONSE_REFORMATTED
def test_reformat_json(self):
print(self.test_response)
test_response_rates = self.test_response["rates"]
test_response_updated = reformat_json(self.test_response)
self.assertEqual(test_response_updated["base"], {
"S": self.test_response["base"]})
self.assertEqual(test_response_updated["date"], {
"S": self.test_response["date"]})
self.assertEqual(test_response_updated["AUD"], {
"N": str(test_response_rates["AUD"])})
self.assertEqual(test_response_updated["BGN"], {
"N": str(test_response_rates["BGN"])})
self.assertEqual(len(test_response_updated),
len(test_response_rates) + 2)
@mock.patch("main.requests.get", side_effect=mocked_requests_get)
@mock.patch("main.reformat_json", return_value=TEST_RESPONSE_REFORMATTED)
@mock.patch("botocore.client.BaseClient._make_api_call",
return_value={'ResponseMetadata': {'HTTPStatusCode': 200}})
def test_handle(self, boto_mock, mock_reformat_json, mock_get):
response = handle(None, None)
expected_call = [mock.call(u'PutItem', {'Item': self.test_response_reformatted,
'TableName': 'exchange-rates-table'})]
self.assertEqual(boto_mock.call_count, 1)
boto_mock.assert_has_calls(expected_call)
self.assertEqual(response["success"], True)
self.assertEqual(response["status_code"], 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment