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