def test_get_user_mock_server(self):
     responses.add(responses.GET,
                   'https://randomuser.me/api',
                   json=MOCK_USER)
     user = mock_example.get_user()
     assert isinstance(user, mock_example.User)
     assert user.firstname == 'mona'
     assert user.lastname == 'rafrafi'
     assert user.gender == 'female'
     assert user.email == '*****@*****.**'
     assert user.username == 'greenladybug656'
Ejemplo n.º 2
0
 def test_get_user_mock_server(self):
     responses.add(responses.GET,
                   'https://randomuser.me/api',
                   json=MOCK_USER)
     user = mock_example.get_user()
     self.assertIsInstance(user, mock_example.User)
     self.assertEqual(user.firstname, 'mona')
     self.assertEqual(user.lastname, 'rafrafi')
     self.assertEqual(user.gender, 'female')
     self.assertEqual(user.email, '*****@*****.**')
     self.assertEqual(user.username, 'greenladybug656')
 def test(self, mocker):
     # from mock_example import get_user, User
     mocker.patch('mock_example.get_user',
                  return_value=mock_example.User.create_from_api(MOCK_USER))
     user = mock_example.get_user()
     assert user.firstname == 'mona'
 def test_get_user_server_is_unreachable(self):
     # By default, with responses, we have a connexion error by default
     with pytest.raises(mock_example.APIUnreachableException):
         mock_example.get_user()
 def test_get_user_not_found(self):
     responses.add(responses.GET, 'https://randomuser.me/api', status=404)
     with pytest.raises(mock_example.HttpNotFound):
         mock_example.get_user()
Ejemplo n.º 6
0
 def test(self, my_mock_test_user):
     # from mock_example import get_user, User
     my_mock_test_user.return_value = mock_example.User.create_from_api(
         MOCK_USER)
     user = mock_example.get_user()
     self.assertEqual(user.firstname, 'mona')