示例#1
0
 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)
示例#2
0
 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')
示例#3
0
    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
示例#4
0
    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