Beispiel #1
0
def test_delete_vote_unauthenticated_user():
    """
        This should raise HTTPNotFound because of unauthenticated user.
    """
    request = _mock_request(authenticated_user=None)
    with pytest.raises(httpexceptions.HTTPNotFound):
        views.delete_vote(request)
Beispiel #2
0
def test_delete_vote_authenticated_user_objects_none():
    """
        This should raise HTTPNotFound as all user, page, group, and language are None.
    """
    request = _mock_request(matchdict={'page_uri': 'http://www.annotran_test.com',
                                       'public_group_id': "12345",
                                       'public_language_id': "12345"},
                            authenticated_user=mock.Mock(id=2, username="******", uid="test2"))
    with pytest.raises(httpexceptions.HTTPNotFound):
        views.delete_vote(request)
Beispiel #3
0
def test_delete_vote_authenticated_user():
    """
        This should delete an existing vote from the db.
    """
    with mock.patch('annotran.languages.models.Language') as language:
        language.get_by_public_language_id = MagicMock(return_value=language)

        with mock.patch('annotran.pages.models.Page') as page:
            page.get_by_uri = MagicMock(return_value=page)

            with mock.patch('h.groups.models.Group') as group:
                group.get_by_pubid = MagicMock(return_value=group)

                with mock.patch('h.models.User') as user:
                    user.get_by_username = MagicMock(return_value=user)

                    with mock.patch('annotran.votes.models.Vote') as vote:
                        vote.delete_votes = MagicMock(return_value=vote)

                        request = _mock_request(matchdict={'page_uri': 'http://www.annotran_test.com',
                                                           'public_group_id': "12345",
                                                           'public_language_id': "12345"},
                                                authenticated_user=mock.Mock(id=2, username="******", uid="test2"))
                        result = views.delete_vote(request)
                        assert result == {}