Beispiel #1
0
 def test_add_tag(self):
     hatchbuck = Hatchbuck("")
     hatchbuck.noop = True
     profile = hatchbuck.add_tag(
         "SUFYbGdOaEQ0cWR2N1JfV183UFNBSDllTktCc3E3OWRsN09qaW4tU3JqbzE1", ""
     )
     self.assertFalse(profile, testProfile)
Beispiel #2
0
 def test_profile_add_birthday(self):
     hatchbuck = Hatchbuck("")
     hatchbuck.noop = True
     profile = hatchbuck.profile_add_birthday(
         {
             "contactId": "TmpmT0QyUGE3UGdGejZMay1x"
             "bDNyUHJFWU91M2VwN0hCdGtZZFFCaWRZczE1"
         },
         {"month": "1", "day": "1", "year": "1984"},
     )
     self.assertTrue(profile, testProfile)
Beispiel #3
0
 def test_get_countrycode(self):
     hatchbuck = Hatchbuck("")
     hatchbuck.noop = True
     self.assertEqual(
         hatchbuck._get_countrycode(testProfile), "CH"
     )  # unique country
     self.assertEqual(hatchbuck._get_countrycode({}), None)  # no country
     self.assertEqual(
         hatchbuck._get_countrycode(
             {"addresses": [{"country": "Switzerland"}, {"country": "Germany"}]}
         ),
         None,
     )  # ambiguous country
Beispiel #4
0
 def test_profile_contains(self):
     hatchbuck = Hatchbuck("")
     hatchbuck.noop = True
     profile = hatchbuck.profile_contains(
         {
             "contactId": "SUFYbGdOaEQ0cWR2N1JfV183U"
             "FNBSDllTktCc3E3OWRsN09qaW4tU3JqbzE1",
             "phones": [{"number": "+(414) 454-5 53 00", "type": "work"}],
         },
         "phones",
         "number",
         "+(414) 454-5 53 00",
     )
     self.assertTrue(profile, testProfile)
Beispiel #5
0
 def test_cleanup_phone_number(self):
     hatchbuck = Hatchbuck("")
     hatchbuck.noop = True
     self.assertEqual(
         hatchbuck._cleanup_phone_number("+41 (44) 545-53-00"), "+41445455300"
     )
     self.assertEqual(
         hatchbuck._cleanup_phone_number("+41445455300"), "+41445455300"
     )
     self.assertEqual(
         hatchbuck._cleanup_phone_number("+41 44 545 53 00"), "+41445455300"
     )
     self.assertEqual(
         hatchbuck._cleanup_phone_number("\xa0+41 44 545 53 00\xa0"), "+41445455300"
     )
Beispiel #6
0
 def test_format_phone_number(self):
     hatchbuck = Hatchbuck("")
     hatchbuck.noop = True
     self.assertEqual(
         hatchbuck._format_phone_number("+41445455300"), "+41 44 545 53 00"
     )
     self.assertEqual(
         hatchbuck._format_phone_number("\xa0+41(44)545-53-00\xa0"),
         "+41 44 545 53 00",
     )
     self.assertEqual(
         hatchbuck._format_phone_number("+41 44 545 53 00"), "+41 44 545 53 00"
     )
     self.assertEqual(hatchbuck._format_phone_number("044 545 53 00"), None)
     self.assertEqual(
         hatchbuck._format_phone_number("044 545 53 00", "CH"), "+41 44 545 53 00"
     )
Beispiel #7
0
 def test_short_contact(self):
     hatchbuck = Hatchbuck("")
     hatchbuck.noop = True
     self.assertEqual(
         hatchbuck.short_contact(testProfile),
         "Contact(Bashar Said, [email protected])",
     )
     self.assertEqual(hatchbuck.short_contact({}), "Contact()")
     self.assertEqual(
         hatchbuck.short_contact({"firstName": "firstName", "lastName": "lastName"}),
         "Contact(firstName lastName)",
     )
     self.assertEqual(
         hatchbuck.short_contact(
             {"emails": [{"address": "*****@*****.**"}]}
         ),
         "Contact([email protected])",
     )
Beispiel #8
0
    def test_profile_add_address(self):
        hatchbuck = Hatchbuck("")
        hatchbuck.noop = True
        existingaddress = {
            "street": "Neugasse 10",
            "zip_code": "8005",
            "city": "Zürich",
            "country": "Switzerland",
        }
        # We're trying to add an address that is already there
        # Check that the address is there already
        self.assertTrue(
            hatchbuck.address_exists(
                testProfile,
                {
                    "street": existingaddress["street"],
                    "zip": existingaddress["zip_code"],
                    "city": existingaddress["city"],
                    "country": existingaddress["country"],
                    "type": "Work",
                },
            )
        )

        # try to add the address again
        profile = hatchbuck.profile_add_address(testProfile, existingaddress, "Work")

        # Check that the address is still there
        self.assertTrue(
            hatchbuck.address_exists(
                profile,
                {
                    "street": existingaddress["street"],
                    "zip": existingaddress["zip_code"],
                    "city": existingaddress["city"],
                    "country": existingaddress["country"],
                    "type": "Work",
                },
            )
        )

        # check that the profile was not modified by
        #  trying to add an existing address
        self.assertTrue(profile == testProfile)
Beispiel #9
0
 def test_clean_address(self):
     hatchbuck = Hatchbuck("")
     hatchbuck.noop = True
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "Neugasse 10",
             "zip": "8005",
             "city": "Zürich",
             "country": "Switzerland",
         }),
         {
             "street": "Neugasse 10",
             "zip": "8005",
             "city": "Zürich",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )  # no change
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "Neugasse 10",
             "zip": "8005",
             "city": "Zurich",
             "country": "Switzerland",
         }),
         {
             "street": "Neugasse 10",
             "zip": "8005",
             "city": "Zürich",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({"country": ""}),
         {
             "street": "",
             "zip": "",
             "city": "",
             "country": "",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Zürich, Canton of Zürich, Switzerland",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Zürich",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Bern, Canton of Bern, Switzerland",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Bern",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Neuenkirch, Kanton Luzern, Schweiz",
             "country": "",
             "type": "Other",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Neuenkirch",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Frankfurt Am Main Area, Germany",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Frankfurt Am Main",
             "country": "Germany",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Sankt Gallen Area, Switzerland",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Sankt Gallen",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Santa Monica, California",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Santa Monica",
             "country": "United States",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "San Francisco Bay Area",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "San Francisco",
             "country": "",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Austria area",
             "country": ""
         }),
         {
             "street": "",
             "zip": "",
             "city": "",
             "country": "Austria",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Vienna, Vienna, Austria",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Vienna",
             "country": "Austria",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Wohlen AG, Kanton Aargau, Schweiz",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Wohlen AG",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Austin, Texas Area",
             "country": ""
         }),
         {
             "street": "",
             "zip": "",
             "city": "Austin, Texas",
             "country": "",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Greater New York City Area",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "New York City",
             "country": "",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Switzerland",
             "country": ""
         }),
         {
             "street": "",
             "zip": "",
             "city": "",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Helsinki Area, Finland",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Helsinki",
             "country": "Finland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "United States",
             "country": ""
         }),
         {
             "street": "",
             "zip": "",
             "city": "",
             "country": "United States",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Zürich Area, Switzerland",
             "country": "ch",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Zürich",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Zürich Area, Switzerland",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Zürich",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Brisbane Area, Australia",
             "country": "au",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Brisbane",
             "country": "Australia",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Amsterdam Area, Netherlands",
             "country": "nl",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Amsterdam",
             "country": "Netherlands",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Brisbane Area, Australia",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Brisbane",
             "country": "Australia",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "",
             "country": "CH"
         }),
         {
             "street": "",
             "zip": "",
             "city": "",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "Pflanzschulstrasse 34",
             "zip": "CH-8004",
             "city": "Zürich",
             "country": "",
         }),
         {
             "street": "Pflanzschulstrasse 34",
             "zip": "8004",
             "city": "Zürich",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Zürich Area, Svizzera",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Zürich",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Luxembourg",
             "country": ""
         }),
         {
             "street": "",
             "zip": "",
             "city": "",
             "country": "Luxembourg",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Boulogne-Billancourt, Île-de-France, France",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Boulogne-Billancourt",
             "country": "France",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Lausanne, Canton de Vaud, Suisse",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Lausanne",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Région de Lausanne, Suisse",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Lausanne",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Région de Genève, Suisse",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Genève",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Copenhagen, Capital Region, Denmark",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Copenhagen",
             "country": "Denmark",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Copenhagen Area, Capital Region, Denmark",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Copenhagen",
             "country": "Denmark",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "München und Umgebung, Deutschland",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "München",
             "country": "Germany",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Currais Novos e Região, Brasil",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Currais Novos",
             "country": "Brazil",
             "state": "",
             "type": "Other",
         },
     )
     self.assertEqual(
         hatchbuck._clean_address({
             "street": "",
             "zip": "",
             "city": "Zürich und Umgebung, Schweiz",
             "country": "",
         }),
         {
             "street": "",
             "zip": "",
             "city": "Zürich",
             "country": "Switzerland",
             "state": "",
             "type": "Other",
         },
     )
Beispiel #10
0
    def test_clean_all_phone_numbers(self):
        hatchbuck = Hatchbuck("")
        hatchbuck.noop = True
        profile1 = {
            "phones": [
                {
                    "id": "1",
                    "number": "+(414) 454-5 53 00",
                    "type": "Work",
                    "typeId": "asdf",
                },
                {
                    "id": "2",
                    "number": "+(414) 454-5 53 00",
                    "type": "Home",
                    "typeId": "qwer",
                },
                {
                    "id": "3",
                    "number": "(044) 545-53-00",
                    "type": "Work",
                    "typeId": "asdf",
                },
            ]
        }
        self.assertEqual(
            hatchbuck.clean_all_phone_numbers(profile1),
            {
                "phones": [
                    {
                        "id": "1",
                        "number": "+41 44 545 53 00",
                        "type": "Work",
                        "typeId": "asdf",
                    }
                ]
            },
        )
        profile2 = {
            "phones": [
                {
                    "id": "1",
                    "number": "(044) 545-53-00",
                    "type": "Work",
                    "typeId": "asdf",
                }
            ],
            "addresses": [{"country": "Switzerland"}],
        }
        self.assertEqual(
            hatchbuck.clean_all_phone_numbers(profile2),
            {
                "phones": [
                    {
                        "id": "1",
                        "number": "+41 44 545 53 00",
                        "type": "Work",
                        "typeId": "asdf",
                    }
                ],
                "addresses": [{"country": "Switzerland"}],
            },
        )

        profile3 = {
            "phones": [
                {
                    "id": "1",
                    "number": "(044) 545-53-00",
                    "type": "Work",
                    "typeId": "asdf",
                }
            ],
            "addresses": [{"country": "Switzerland "}],  # note the space
        }
        self.assertEqual(
            hatchbuck.clean_all_phone_numbers(profile3),
            {
                "phones": [
                    {
                        "id": "1",
                        "number": "+41 44 545 53 00",
                        "type": "Work",
                        "typeId": "asdf",
                    }
                ],
                "addresses": [{"country": "Switzerland "}],
            },
        )