def test_registered_customer(self): ddb = utils.get_dynamo_client() with Stubber(ddb) as stubber, \ patch('sc_cost_meter.utils.get_env_var_value') as env_var_val: env_var_val.return_value = "SomeTable" response = { "Item": { "ProductCode": { "S": "prod-1234" }, "MarketplaceCustomerId": { "S": "cust-1234" }, "SynapseUserId": { "S": "11111" } }, "ResponseMetadata": { "RequestId": "7O3ULIVRKDGRG2I27D5NOO8SSRVV4KQNSO5AEMVJF66Q9ASUAAJG", "HTTPStatusCode": 200, } } stubber.add_response('get_item', response) utils.get_dynamo_client = MagicMock(return_value=ddb) synapse_id = "11111" result = utils.get_marketplace_customer_info(synapse_id) expected = { 'SynapseUserId': '11111', 'MarketplaceCustomerId': 'cust-1234', 'ProductCode': 'prod-1234' } self.assertEqual(result, expected)
def test_multiple_synapse_ids(self): client = utils.get_dynamo_client() with Stubber(client) as stubber, \ patch('sc_cost_meter.utils.get_env_var_value') as mock_get_env_var_value: mock_get_env_var_value.return_value = "some-table" response = { "Items": [{ "SynapseUserId": { "S": "111111" } }, { "SynapseUserId": { "S": "222222" } }], "ResponseMetadata": { "RequestId": "7f6e2b4e-537e-45b6-b48e-dbc0657861e4", "HTTPStatusCode": 200, } } expected = ["111111", "222222"] stubber.add_response('scan', response) utils.get_dynamo_client = MagicMock(return_value=client) result = utils.get_marketplace_synapse_ids() self.assertEqual(expected, result)
def test_no_env_var_marketplace_id_dynamo_table_name(self): ddb = utils.get_dynamo_client() with Stubber(ddb) as stubber, \ patch('sc_cost_meter.utils.get_env_var_value') as env_var_mock: env_var_mock.return_value = None synapse_id = "11111" result = utils.get_marketplace_customer_info(synapse_id) self.assertEqual({}, result)
def test_no_registered_customer(self): ddb = utils.get_dynamo_client() with Stubber(ddb) as stubber, \ patch('sc_cost_meter.utils.get_env_var_value') as env_var_val: env_var_val.return_value = "SomeTable" response = {} stubber.add_response('get_item', response) utils.get_dynamo_client = MagicMock(return_value=ddb) synapse_id = "11111" result = utils.get_marketplace_customer_info(synapse_id) self.assertEqual({}, result)
def test_product_code_not_found(self): client = utils.get_dynamo_client() with Stubber(client) as stubber, \ patch('sc_cost_meter.utils.get_env_var_value') as mock_get_env_var_value: mock_get_env_var_value.return_value = "some-table" response = { "ResponseMetadata": { "RequestId": "7f6e2b4e-537e-45b6-b48e-dbc0657861e4", "HTTPStatusCode": 200, } } expected = None stubber.add_response('get_item', response) utils.get_dynamo_client = MagicMock(return_value=client) result = utils.get_marketplace_product_code("111111") self.assertEqual(expected, result)