Exemplo n.º 1
0
    def test_get_friends_returns(self, mock_friend_class):
        mock_friend_class.objects.friends.return_value = [MagicMock(username='******'),
                                                          MagicMock(username='******'), MagicMock(username='******')]
        mock_user = MagicMock()
        actual = get_friends(user=mock_user)
        expected = ['john', 'james', 'ben']

        self.assertListEqual(actual, expected)
        mock_friend_class.objects.friends.assert_called_with(mock_user)
Exemplo n.º 2
0
def friends(request):
    if request.user is None:
        return HttpResponse(status=401)
    if request.method == 'GET':
        response = get_friends(user=request.user)
        return HttpResponse(dumps(response))
    elif request.method == 'POST':
        friend_name = _get_post_param(param='username', request=request)
        add_friend(user=request.user, friend_name=friend_name)
        return HttpResponse(status=200)
Exemplo n.º 3
0
 def test_get_friends_returns_empty_list_for_no_friends(self, mock_friend_class):
     mock_friend_class.objects.friends.return_value = []
     actual = get_friends(user=MagicMock())
     expected = []
     self.assertListEqual(actual, expected)