Skip to content

Commit

Permalink
[ADD] bpost_address_validation: add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kouffsamuel committed Apr 17, 2023
1 parent 65a0ce0 commit db727c7
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bpost_address_validation/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2023 ACSONE SA/NV
from . import test_bpost_address_validation_wizard
120 changes: 120 additions & 0 deletions bpost_address_validation/tests/test_bpost_address_validation_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import responses

from odoo.tests.common import TransactionCase


class TestBpostAddressValidationWizard(TransactionCase):
@classmethod
@responses.activate
def setUpClass(cls):
super(TestBpostAddressValidationWizard, cls).setUpClass()

cls.country = cls.env["res.country"].search([("code", "=", "BE")])
cls.partner = cls.env["res.partner"].create(
{
"name": "Acsone",
"street": "Quai Banneng 6",
"city": "Liège",
"zip": "4000",
"country_id": cls.country.id,
}
)
cls.return_value = {
"ValidateAddressesResponse": {
"ValidatedAddressResultList": {
"ValidatedAddressResult": [
{
"@id": "1",
"ValidatedAddressList": {
"ValidatedAddress": [
{
"PostalAddress": {
"StructuredDeliveryPointLocation": {
"StreetName": "QUAI BANNING",
"StreetNumber": "6",
},
"StructuredPostalCodeMunicipality": {
"PostalCode": "4000",
"MunicipalityName": "LIÈGE",
},
"CountryName": "BELGIQUE",
},
"AddressLanguage": "fr",
"ServicePointDetail": {
"GeographicalLocationInfo": {
"GeographicalLocation": {
"Latitude": {
"Value": "50.61389",
"CoordinateType": "DEGDEC",
},
"Longitude": {
"Value": "5.575775",
"CoordinateType": "DEGDEC",
},
}
}
},
"Label": {
"Line": ["QUAI BANNING 6", "4000 LIÈGE"]
},
}
]
},
"Error": [
{
"ComponentRef": "UnstructuredDeliveryPointLocation",
"ErrorCode": "anomaly_in_field",
"ErrorSeverity": "warning",
}
],
"DetectedInputAddressLanguage": "fr",
"FormattedSubmittedAddress": {
"Line": ["Quai Banneng 6", "4000 Liège"]
},
"TransactionID": "10379d53-2072-420e-b875-e83148ef94e0",
}
]
}
}
}
responses.add(
method=responses.POST,
url="https://webservices-pub.bpost.be/ws/"
+ "ExternalMailingAddressProofingCSREST_v1/address/validateAddresses",
json=cls.return_value,
)
cls.wizard = cls.env["bpost.address.validation.wizard"].create(
{"partner_id": cls.partner.id}
)
cls.wizard._compute_response_address()

@classmethod
def tearDownClass(cls):
super(TestBpostAddressValidationWizard, cls).tearDownClass()

def test_is_not_valid(self):
self.assertFalse(self.wizard.is_valid)

def test_apply_changes(self):
self.wizard.apply_changes()

self.assertEqual("QUAI BANNING 6", self.partner.street)
self.assertEqual("LIÈGE", self.partner.city)
self.assertEqual("4000", self.partner.zip)

def test_suggest_changes(self):
self.assertEqual("QUAI BANNING 6 4000, LIÈGE", self.wizard.suggest_changes)
self.assertFalse(self.wizard.bad_address)
self.assertFalse(self.wizard.is_valid)

def test_invalid_address(self):
self.partner.street = "Quai Banning"
self.wizard._compute_response_address()
self.assertTrue(self.wizard.bad_address)
self.assertFalse(self.wizard.is_valid)

def test_valid_address(self):
self.partner.street = "Quai Banning 6"
self.wizard._compute_response_address()
self.assertTrue(self.wizard.is_valid)
self.assertFalse(self.wizard.bad_address)

0 comments on commit db727c7

Please sign in to comment.