Skip to content

Commit

Permalink
[IMP] l10n_it_location_nuts: remove flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
renda-dev committed Nov 25, 2024
1 parent 573f86d commit 1a14620
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 1 deletion.
9 changes: 8 additions & 1 deletion l10n_it_location_nuts/tests/test_nuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from unittest.mock import patch

from odoo.tests.common import TransactionCase

from .test_nuts_request_results import create_response_ok

MOCK_PATH = "odoo.addons.base_location_nuts.wizard.nuts_import.requests.get"


class TestNUTS(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
importer = cls.env["nuts.import"].create([{}])
importer.import_update_partner_nuts()
with patch(MOCK_PATH, return_value=create_response_ok()):
importer.import_update_partner_nuts()
cls.rome_nuts = cls.env["res.partner.nuts"].search([("code", "=", "ITI43")])
rome_state_id = cls.env.ref("base.state_it_rm").id
cls.it_partner = cls.env["res.partner"].create({"name": "it_partner"})
Expand Down
114 changes: 114 additions & 0 deletions l10n_it_location_nuts/tests/test_nuts_request_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from json import dumps

from requests.models import Response

NUTS = [
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/IT"},
"code": {"type": "literal", "value": "IT"},
"region_name": {"type": "literal", "value": "IT Italia"},
"level": {"type": "literal", "value": "0"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/IT"},
"code": {"type": "literal", "value": "IT"},
"region_name": {"type": "literal", "value": "IT Italia"},
"level": {"type": "literal", "value": "0"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITC"},
"code": {"type": "literal", "value": "ITC"},
"region_name": {"type": "literal", "value": "ITC Nord-Ovest"},
"level": {"type": "literal", "value": "1"},
"parent": {"type": "literal", "value": "IT"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITC"},
"code": {"type": "literal", "value": "ITC"},
"region_name": {"type": "literal", "value": "ITC Nord-Ovest"},
"level": {"type": "literal", "value": "1"},
"parent": {"type": "literal", "value": "IT"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITF"},
"code": {"type": "literal", "value": "ITF"},
"region_name": {"type": "literal", "value": "ITF Sud"},
"level": {"type": "literal", "value": "1"},
"parent": {"type": "literal", "value": "IT"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITH"},
"code": {"type": "literal", "value": "ITH"},
"region_name": {"type": "literal", "value": "ITH Nord-Est"},
"level": {"type": "literal", "value": "1"},
"parent": {"type": "literal", "value": "IT"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITI"},
"code": {"type": "literal", "value": "ITI"},
"region_name": {"type": "literal", "value": "ITI Centro (IT)"},
"level": {"type": "literal", "value": "1"},
"parent": {"type": "literal", "value": "IT"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITI4"},
"code": {"type": "literal", "value": "ITI4"},
"region_name": {"type": "literal", "value": "ITI4 Lazio"},
"level": {"type": "literal", "value": "2"},
"parent": {"type": "literal", "value": "ITI"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITI43"},
"code": {"type": "literal", "value": "ITI43"},
"region_name": {"type": "literal", "value": "ITI43 Roma"},
"level": {"type": "literal", "value": "3"},
"parent": {"type": "literal", "value": "ITI4"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITI44"},
"code": {"type": "literal", "value": "ITI44"},
"region_name": {"type": "literal", "value": "ITI44 Latina"},
"level": {"type": "literal", "value": "3"},
"parent": {"type": "literal", "value": "ITI4"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITZ"},
"code": {"type": "literal", "value": "ITZ"},
"region_name": {"type": "literal", "value": "ITZ Extra-Regio NUTS 1"},
"level": {"type": "literal", "value": "1"},
"parent": {"type": "literal", "value": "IT"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITZ"},
"code": {"type": "literal", "value": "ITZ"},
"region_name": {"type": "literal", "value": "ITZ Extra-Regio NUTS 1"},
"level": {"type": "literal", "value": "1"},
"parent": {"type": "literal", "value": "IT"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITZZ"},
"code": {"type": "literal", "value": "ITZZ"},
"region_name": {"type": "literal", "value": "ITZZ Extra-Regio NUTS 2"},
"level": {"type": "literal", "value": "2"},
"parent": {"type": "literal", "value": "ITZ"},
},
{
"s": {"type": "uri", "value": "http://data.europa.eu/nuts/code/ITZZZ"},
"code": {"type": "literal", "value": "ITZZZ"},
"region_name": {"type": "literal", "value": "ITZZZ Extra-Regio NUTS 3"},
"level": {"type": "literal", "value": "3"},
"parent": {"type": "literal", "value": "ITZZ"},
},
]


def create_response_ok():
response = Response()
response.code = "200"
response.status_code = 200
content = {
"head": {},
"results": {"distinct": False, "ordered": True, "bindings": NUTS},
}
response._content = dumps(content).encode()
return response

0 comments on commit 1a14620

Please sign in to comment.