def test_usage_refresh(self, name, usages): self._model.options = self._option self._model.pull_accounting = True self._usage_client.create_usage.return_value = {'id': '1'} plugin_handler = plugin.Plugin(self._model) plugin_handler.get_pending_accounting = MagicMock(return_value=usages) asset, contract, order = self._mock_order() plugin_handler.on_usage_refresh(asset, contract, order) plugin_handler.get_pending_accounting.assert_called_once_with( asset, contract, order) plugin.UsageClient.assert_called_once_with() if len(usages[0]): # Check calls self._usage_client.create_usage.assert_called_once_with( self._usage_record) self._usage_client.update_usage_state.assert_called_once_with( '1', 'Guided') self.assertEquals(1, contract.correlation_number) self.assertEquals(usages[1], contract.last_usage) self.assertEquals([call(), call()], order.save.call_args_list)
def test_usage_refresh_not_pull(self): self._model.pull_accounting = False plugin_handler = plugin.Plugin(self._model) plugin_handler.get_pending_accounting = MagicMock(return_value=([], None)) plugin_handler.on_usage_refresh(None, None, None) self.assertEquals(0, plugin_handler.get_pending_accounting.call_count)
def test_usage_spec_error(self): plugin_handler = plugin.Plugin(self._model) plugin_handler.get_usage_specs = MagicMock(return_value=[{}]) try: plugin_handler.configure_usage_spec() except PluginError as e: self.assertEquals( 'Plugin Error: Invalid product specification configuration, must include name and description', unicode(e))
def test_usage_refresh_error(self): plugin_handler = plugin.Plugin(self._model) plugin_handler.get_pending_accounting = MagicMock(return_value=([{}], None)) asset, contract, order = self._mock_order() try: plugin_handler.on_usage_refresh(asset, contract, order) except PluginError as e: self.assertEquals( 'Plugin Error: Invalid usage record, it must include date, unit and value', unicode(e))
def test_usage_spec_conf(self, name, specs, validator, side_effect=None): if side_effect is not None: side_effect(self) plugin_handler = plugin.Plugin(self._model) plugin_handler.get_usage_specs = MagicMock(return_value=specs) plugin_handler.configure_usage_spec() plugin.UsageClient.assert_called_once_with() validator(self)
def test_remove_usage_spec_error(self): self._model.options = self._option error = HTTPError() error.response = MagicMock(status_code=500) self._usage_client.delete_usage_spec.side_effect = error plugin_handler = plugin.Plugin(self._model) try: plugin_handler.remove_usage_specs() except HTTPError as e: self.assertEquals(500, e.response.status_code)
def test_remove_usage_specs(self, name, options, validator, side_effect=None): self._model.options = options if side_effect: side_effect(self) plugin_handler = plugin.Plugin(self._model) plugin_handler.remove_usage_specs() validator(self)