Exemplo n.º 1
0
def test_odoo_authenticate(app, app_context, mocker):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    authenticate_mock = mocker.patch.object(
        app_context.odoo_common, "authenticate", return_value=1
    )
    uid = odoo.authenticate()
    authenticate_mock.assert_called_with("odoo", "admin", "admin", {})
    assert uid == 1
Exemplo n.º 2
0
def test_base_model_create_or_update_many2one(app, app_context):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    app_context.odoo_common.authenticate.return_value = 1
    app_context.odoo_object = MagicMock()

    class Partner(odoo.Model):
        _name = "res.partner"

        name = odoo.StringType()
        related_model_id = odoo.Many2oneType()

    partner = Partner()
    partner.name = "test_partner"
    partner.related_model_id = [2, "related"]
    partner.create_or_update()
    app_context.odoo_object.execute_kw.assert_called_with(
        "odoo",
        1,
        "admin",
        "res.partner",
        "create",
        ({
            "name": "test_partner",
            "related_model_id": 2
        }, ),
        {},
    )
Exemplo n.º 3
0
def test_base_model_create_or_update_no_serializable(app, app_context):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    app_context.odoo_common.authenticate.return_value = 1
    app_context.odoo_object = MagicMock()

    class Partner(odoo.Model):
        _name = "res.partner"

        name = odoo.StringType()

        @serializable
        def serializable_field(self):
            return ""

    partner = Partner()
    partner.name = "test_partner"
    partner.create_or_update()
    app_context.odoo_object.execute_kw.assert_called_with(
        "odoo",
        1,
        "admin",
        "res.partner",
        "create",
        ({
            "name": "test_partner"
        }, ),
        {},
    )
Exemplo n.º 4
0
def test_base_model_search_by_id(app, app_context):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    app_context.odoo_common.authenticate.return_value = 1
    app_context.odoo_object = MagicMock()
    app_context.odoo_object.execute_kw.return_value = [{
        "id": 2,
        "name": "test_partner"
    }]

    class Partner(odoo.Model):
        _name = "res.partner"

        name = odoo.StringType()

    partner = Partner.search_by_id(2)
    app_context.odoo_object.execute_kw.assert_called_with(
        "odoo",
        1,
        "admin",
        "res.partner",
        "search_read",
        ([["id", "=", 2]], ),
        {
            "fields": ["id", "name"],
            "limit": 1
        },
    )
    assert partner.id == 2
    assert partner.name == "test_partner"
Exemplo n.º 5
0
def test_odoo_uid(app, app_context, mocker):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    mocker.patch.object(
        app_context.odoo_common, "authenticate", return_value=1
    )
    assert odoo.uid == 1
Exemplo n.º 6
0
def test_odoo_init(app, mocker):
    make_model_base_mock = mocker.patch("flask_odoo.make_model_base")
    init_app_mock = mocker.patch.object(Odoo, "init_app")
    odoo = Odoo(app)
    assert odoo.app == app
    make_model_base_mock.assert_called_with(odoo)
    assert odoo.Model == make_model_base_mock.return_value
    init_app_mock.assert_called_with(app)
Exemplo n.º 7
0
def test_odoo_object(app, app_context, mocker):
    server_proxy_mock = mocker.patch("flask_odoo.xmlrpc.client.ServerProxy")
    odoo = Odoo(app)
    server_proxy = odoo.object
    assert app_context.odoo_object == server_proxy
    server_proxy_mock.assert_called_with(
        "http://localhost:8069/xmlrpc/2/object"
    )
Exemplo n.º 8
0
def test_base_model_repr(app):
    odoo = Odoo(app)

    class Partner(odoo.Model):
        _name = "res.partner"

    partner = Partner()
    partner.id = 1
    assert str(partner) == "<Partner(id=1)>"
Exemplo n.º 9
0
def test_odoo_getitem(app, app_context):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    app_context.odoo_common.authenticate.return_value = 1
    app_context.odoo_object = MagicMock()
    object_proxy = odoo["test.model"]
    assert isinstance(object_proxy, ObjectProxy)
    object_proxy.odoo == odoo
    assert object_proxy.model_name == "test.model"
Exemplo n.º 10
0
def test_base_model_delete(app, app_context):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    app_context.odoo_common.authenticate.return_value = 1
    app_context.odoo_object = MagicMock()

    class Partner(odoo.Model):
        _name = "res.partner"

    partner = Partner()
    partner.id = 2
    partner.delete()
    app_context.odoo_object.execute_kw.assert_called_with(
        "odoo", 1, "admin", "res.partner", "unlink", ([2], ), {})
Exemplo n.º 11
0
def test_base_model_search_read(app, app_context):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    app_context.odoo_common.authenticate.return_value = 1
    app_context.odoo_object = MagicMock()
    records = [
        {
            "id": 1,
            "name": "rec1",
            "active": True
        },
        {
            "id": 2,
            "name": "rec2",
            "active": False
        },
    ]
    app_context.odoo_object.execute_kw.return_value = records

    class Partner(odoo.Model):
        _name = "res.partner"

        name = odoo.StringType()
        is_active = odoo.BooleanType(serialized_name="active")

    search_criteria = [["is_company", "=", True]]
    objects = Partner.search_read(search_criteria, offset=100, limit=10)
    app_context.odoo_object.execute_kw.assert_called_with(
        "odoo",
        1,
        "admin",
        "res.partner",
        "search_read",
        (search_criteria, ),
        {
            "fields": ["id", "name", "active"],
            "offset": 100,
            "limit": 10
        },
    )
    assert objects == [Partner(records[0]), Partner(records[1])]
    assert objects[0].is_active
    assert not objects[1].is_active
Exemplo n.º 12
0
def test_base_model_create_or_update(app, app_context):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    app_context.odoo_common.authenticate.return_value = 1
    app_context.odoo_object = MagicMock()
    app_context.odoo_object.execute_kw.return_value = 2

    class Partner(odoo.Model):
        _name = "res.partner"

        name = odoo.StringType()

    partner = Partner()
    assert not partner.id
    partner.name = "test_partner"
    partner.create_or_update()
    app_context.odoo_object.execute_kw.assert_called_with(
        "odoo",
        1,
        "admin",
        "res.partner",
        "create",
        ({
            "name": "test_partner"
        }, ),
        {},
    )
    assert partner.id == 2
    partner.name = "new_name"
    partner.create_or_update()
    app_context.odoo_object.execute_kw.assert_called_with(
        "odoo",
        1,
        "admin",
        "res.partner",
        "write",
        ([2], {
            "name": "new_name"
        }),
        {},
    )
Exemplo n.º 13
0
def test_base_model_search_count(app, app_context):
    odoo = Odoo(app)
    app_context.odoo_common = MagicMock()
    app_context.odoo_common.authenticate.return_value = 1
    app_context.odoo_object = MagicMock()
    app_context.odoo_object.execute_kw.return_value = 2

    class Partner(odoo.Model):
        _name = "res.partner"

    search_criteria = [["is_company", "=", True]]
    count = Partner.search_count(search_criteria)

    app_context.odoo_object.execute_kw.assert_called_with(
        "odoo",
        1,
        "admin",
        "res.partner",
        "search_count",
        (search_criteria, ),
        {},
    )
    assert count == 2
Exemplo n.º 14
0
from flask import Flask
from flask_odoo import Odoo

app = Flask(__name__)
app.config["ODOO_URL"] = "http://localhost:8069"
app.config["ODOO_DB"] = "odoo"
app.config["ODOO_USERNAME"] = "******"
app.config["ODOO_PASSWORD"] = "******"
odoo = Odoo(app)