def test_standard_extension(self, _): """ Check if lane extension is included in ASP ref file """ user = _users_with_mock_address(0) result, _error = format_address(user) self.assertEqual(result.get("std_extension"), LaneExtension.B.name) user = _users_with_mock_address(16) result, _error = format_address(user) self.assertEqual(result.get("std_extension"), LaneExtension.T.name)
def update_hexa_address(self): """ This method tries to fill the HEXA address fields based the current address of the job seeker (User model). Conversion from standard itou address to HEXA is making sync geo API calls. Returns current object or re-raise error, thus calling this method should be done in a try/except block """ result, error = format_address(self.user) if error: raise ValidationError(error) # Fill matching fields self.hexa_lane_type = result.get("lane_type") self.hexa_lane_number = result.get("number") self.hexa_std_extension = result.get("std_extension", "") self.hexa_non_std_extension = result.get("non_std_extension") self.hexa_lane_name = result.get("lane") self.hexa_post_code = result.get("post_code") self.hexa_additional_address = result.get("additional_address") # Special field: Commune object contains both city name and INSEE code insee_code = result.get("insee_code") self.hexa_commune = Commune.objects.by_insee_code(insee_code).first() if not self.hexa_commune: raise ValidationError(self.ERROR_HEXA_LOOKUP_COMMUNE) self.save() return self
def test_non_standard_extension(self, _): """ Non-standard extension, i.e. not in ASP ref file """ user = _users_with_mock_address(17) result, _error = format_address(user) self.assertEqual(result.get("non_std_extension"), "G") self.assertIsNone(result.get("std_extension"))
def test_not_existing_address(self, _mock): job_seeker = JobSeekerFactory(address_line_1="9, avenue de Huet", post_code="32531", city="MalletVille", department="32") result, error = format_address(job_seeker) self.assertFalse(result) self.assertEqual( error, "Erreur de geocoding, impossible d'obtenir un résultat")
def test_sanity(self, _): """ Sanity check: every mock entries must be parseable and result must be valid """ for idx, _elt in enumerate(RESULTS_BY_ADDRESS): user = _users_with_mock_address(idx) result, error = format_address(user) self.assertIsNone(error) self.assertIsNotNone(result)
def test_asp_addresses(self, _): """ Test some of the most common address format Complete if needed. """ user = _users_with_mock_address(0) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.RUE.name) self.assertEqual(result.get("number"), "37") user = _users_with_mock_address(1) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.RTE.name) self.assertEqual(result.get("number"), "382") user = _users_with_mock_address(2) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.RUE.name) self.assertEqual(result.get("number"), "5") user = _users_with_mock_address(3) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.AV.name) self.assertEqual(result.get("number"), "35") user = _users_with_mock_address(4) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.BD.name) self.assertEqual(result.get("number"), "67") user = _users_with_mock_address(5) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.PL.name) self.assertEqual(result.get("number"), "2") user = _users_with_mock_address(6) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.CITE.name) user = _users_with_mock_address(7) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.CHEM.name) self.assertEqual(result.get("number"), "261") user = _users_with_mock_address(8) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.LD.name) user = _users_with_mock_address(9) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.PAS.name) self.assertEqual(result.get("number"), "1") user = _users_with_mock_address(10) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.SQ.name) self.assertEqual(result.get("number"), "2") user = _users_with_mock_address(11) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.HAM.name) user = _users_with_mock_address(12) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.QUAR.name) self.assertEqual(result.get("number"), "16") user = _users_with_mock_address(13) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.RES.name) self.assertEqual(result.get("number"), "1") user = _users_with_mock_address(14) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.VOIE.name) self.assertEqual(result.get("number"), "172") user = _users_with_mock_address(15) result, error = format_address(user) self.assertIsNone(error) self.assertEqual(result.get("lane_type"), LaneType.ALL.name) self.assertEqual(result.get("number"), "3")
def test_none(self, _mock): result, error = format_address(None) self.assertFalse(result) self.assertEqual( error, "Impossible de transformer cet objet en adresse HEXA")