def test_create_valid_data(self): """ Test create ErpRegisteration with valid data """ erp = ErpRegisteration(name='erp', data=self.valid_data) erp.validate() assert erp.data == self.valid_data
def _test_create_erp_invalid(self, data, missing_key): with pytest.raises( ValueError, message= 'template should fail to instantiate if data dict is missing the %s' % missing_key): erp = ErpRegisteration(name='erp', data=data) erp.validate()
def test_get_bot_client(self): """ Test _get_bot_client :return: """ client_get = patch('js9.j.clients.telegram_bot.get', MagicMock()).start() erp = ErpRegisteration(name='erp', data=self.valid_data) erp._get_bot_client() data = { 'bot_token_': erp.data['botToken'], } client_get.assert_called_with(instance=erp.guid, data=data, create=True, die=True)
def test_get_erp_client(self): """ Test _get_erp_client """ client_get = patch('js9.j.clients.erppeek.get', MagicMock()).start() erp = ErpRegisteration(name='erp', data=self.valid_data) erp._get_erp_client() data = { 'url': erp.data['url'], 'db': erp.data['db'], 'password_': erp.data['password'], 'username': erp.data['username'], } client_get.assert_called_with(instance=erp.guid, data=data, create=True, die=True)
def test_registeration_error(self): """ Test error during registeration """ with pytest.raises( j.exceptions.RuntimeError, message='action should fail if an error was raised'): erp = ErpRegisteration(name='erp', data=self.valid_data) erp._get_erp_client = MagicMock(side_effect=Exception) erp._get_bot_client = MagicMock() erp.register('node')
def test_register_old_node(self): """ Test register old node """ erp = ErpRegisteration(name='erp', data=self.valid_data) client = MagicMock() client.count_records = MagicMock(return_value=1) erp._get_erp_client = MagicMock(return_value=client) erp._get_bot_client = MagicMock() erp.register('node') client.create_record.assert_not_called() assert erp._get_erp_client.called assert erp._get_bot_client.called
def test_register_new_node(self): """ Test register new node """ erp = ErpRegisteration(name='erp', data=self.valid_data) client = MagicMock() client.count_records = MagicMock(return_value=0) erp._get_erp_client = MagicMock(return_value=client) erp._get_bot_client = MagicMock() erp.register('node') client.create_record.assert_called_once_with( 'stock.production.lot', { 'name': 'node', 'product_id': erp.data['productId'] }) assert erp._get_erp_client.called assert erp._get_bot_client.called