Пример #1
0
    def test_formatted_existing_user_with_phone_change_outputs_usager(
            self, mock_get):
        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.content = "content"
        mock_response.json = mock.Mock(
            return_value={
                "given_name": self.usager.given_name,
                "family_name": self.usager.family_name,
                "sub": self.usager_sub_fc,
                "preferred_username": self.usager.preferred_username,
                "birthdate": self.usager.birthdate,
                "gender": self.usager.gender,
                "birthplace": self.usager.birthplace,
                "birthcountry": self.usager.birthcountry,
                "email": "*****@*****.**",
            })
        mock_get.return_value = mock_response

        usager, error = get_user_info(self.connection_with_phone)

        self.assertEqual(usager.id, self.usager.id)
        self.assertEqual(usager.given_name, "Joséphine")
        self.assertEqual(usager.phone, "0 800 840 800")
        self.assertIsNone(error)

        last_journal_entry = Journal.objects.last()
        self.assertEqual(last_journal_entry.action, "update_phone_usager")
Пример #2
0
    def test_empty_response_does_not_fail_badly(self, mock_get):
        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.content = "content"
        mock_response.json = mock.Mock(return_value={})
        mock_get.return_value = mock_response
        usager, error = get_user_info(self.connection)

        self.assertIsNone(usager)
        self.assertIn("Unable to find sub in FC user info", error)
Пример #3
0
    def test_badly_formated_user_info_outputs_error(self, mock_get):
        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.content = "content"
        mock_response.json = mock.Mock(
            return_value={
                "family_name": "Mercier",
                "sub": "123",
                "preferred_username": "******",
                "birthdate": "1981-07-27",
                "gender": "female",
                "birthplace": "95277",
                "birthcountry": "99100",
                "email": "*****@*****.**",
            })
        mock_get.return_value = mock_response
        usager, error = get_user_info("abc", "def")

        self.assertEqual(usager, None)
        self.assertIn("The FranceConnect ID is not complete:", error)
Пример #4
0
    def test_badly_formatted_new_user_info_outputs_error(self, mock_get):
        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.content = "content"
        mock_response.json = mock.Mock(
            return_value={  # without 'given_name'
                "family_name": "Mercier",
                "sub": "456",
                "preferred_username": "******",
                "birthdate": "1981-07-27",
                "gender": Usager.GENDER_FEMALE,
                "birthplace": "95277",
                "birthcountry": Usager.BIRTHCOUNTRY_FRANCE,
                "email": "*****@*****.**",
            }
        )
        mock_get.return_value = mock_response
        usager, error = get_user_info(self.connection)

        self.assertIsNone(usager)
        self.assertIn("The FranceConnect ID is not complete:", error)
Пример #5
0
    def test_well_formated_user_info_outputs_usager(self, mock_get):
        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.content = "content"
        mock_response.json = mock.Mock(
            return_value={
                "given_name": "Fabrice",
                "family_name": "Mercier",
                "sub": "123",
                "preferred_username": "******",
                "birthdate": "1981-07-27",
                "gender": "female",
                "birthplace": "95277",
                "birthcountry": "99100",
                "email": "*****@*****.**",
            })
        mock_get.return_value = mock_response

        usager, error = get_user_info("abc", "def")

        self.assertEqual(usager.given_name, "Fabrice")
        self.assertEqual(error, None)
Пример #6
0
    def test_well_formatted_new_user_info_outputs_usager(self, mock_get):
        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.content = "content"
        mock_response.json = mock.Mock(
            return_value={
                "given_name": "Fabrice",
                "family_name": "Mercier",
                "sub": "456",
                "preferred_username": "******",
                "birthdate": "1981-07-27",
                "gender": Usager.GENDER_FEMALE,
                "birthplace": "95277",
                "birthcountry": Usager.BIRTHCOUNTRY_FRANCE,
                "email": "*****@*****.**",
            })
        mock_get.return_value = mock_response

        usager, error = get_user_info(self.connection)

        self.assertEqual(usager.given_name, "Fabrice")
        self.assertEqual(usager.email, "*****@*****.**")
        self.assertIsNone(error)