def test_rate_usage(self):
        site = 'http://example.com/'
        usage_client.settings.SITE = site

        timestamp = '2016-04-15'
        duty_free = '10'
        price = '12'
        rate = '20'
        currency = 'EUR'
        product_url = site + 'DSProductInventory/api/productInventory/v2/product/' + self._product_id

        expected_json = {
            'status': 'Rated',
            'ratedProductUsage': [{
                'ratingDate': timestamp,
                'usageRatingTag': 'usage',
                'isBilled': False,
                'ratingAmountType': 'Total',
                'taxIncludedRatingAmount': price,
                'taxExcludedRatingAmount': duty_free,
                'taxRate': rate,
                'isTaxExempt': False,
                'offerTariffType': 'Normal',
                'currencyCode': currency,
                'productRef': product_url
            }]
        }

        client = usage_client.UsageClient()
        self._test_patch(
            expected_json,
            client.rate_usage,
            (BASIC_USAGE['id'], timestamp, duty_free, price, rate, currency, self._product_id)
        )
        reload(usage_client)
    def test_retrieve_usage(self,
                            name,
                            response,
                            exp_resp,
                            extra_query='',
                            state=None):
        # Create mocks
        mock_response = MagicMock()
        mock_response.json.return_value = response
        usage_client.requests.get.return_value = mock_response
        client = usage_client.UsageClient()

        cust_usage = client.get_customer_usage(self._customer,
                                               self._product_id,
                                               state=state)

        # Verify response
        self.assertEquals(exp_resp, cust_usage)

        # Verify calls
        usage_client.requests.get.assert_called_once_with(
            usage_client.settings.USAGE +
            '/api/usageManagement/v2/usage?relatedParty.id=' + self._customer +
            extra_query,
            headers={u'Accept': u'application/json'})

        mock_response.raise_for_status.assert_called_once_with()
        mock_response.json.assert_called_once_with()
    def test_update_usage_state(self):
        # Create Mocks
        status = 'Rated'
        expected_json = {'status': status}
        client = usage_client.UsageClient()

        self._test_patch(expected_json, client.update_usage_state,
                         (BASIC_USAGE['id'], status))
 def test_update_usage_invalid_state(self):
     client = usage_client.UsageClient()
     self._test_invalid_state(client.update_usage_state, (BASIC_USAGE['id'], 'invalid'), {})
 def test_retrieve_usage_invalid_state(self):
     client = usage_client.UsageClient()
     self._test_invalid_state(client.get_customer_usage, (self._customer, self._product_id), {'state': 'invalid'})