Esempio n. 1
0
 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)
Esempio n. 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')
Esempio n. 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
Esempio n. 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