<commit_before>"""
Tests accounts views
"""

# Django
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.views import login
from django.urls import reverse
from django.http.response import Http404
from django.test import RequestFactory, TestCase

# Third Party
from mock import patch
from nose.tools import eq_, ok_, raises

# MuckRock
from muckrock.accounts import views
from muckrock.core.factories import (
    AgencyFactory,
    NotificationFactory,
    QuestionFactory,
    UserFactory,
)
from muckrock.core.test_utils import (
    http_get_response,
    http_post_response,
    mock_middleware,
)
from muckrock.core.utils import new_action, notify
from muckrock.foia.factories import FOIAComposerFactory, FOIARequestFactory
from muckrock.foia.views import Detail as FOIARequestDetail
from muckrock.qanda.views import Detail as QuestionDetail


def http_get_post(url, view, data):
    """Performs both a GET and a POST on the same url and view."""
    get_response = http_get_response(url, view)
    post_response = http_post_response(url, view, data)
    return (get_response, post_response)


class TestAccountFunctional(TestCase):
    """Functional tests for account"""

    def setUp(self):
        self.user = UserFactory()

    def test_public_views(self):
        """Test public views while not logged in"""
        # give the user a composer so they have a public profile
        FOIAComposerFactory(user=self.user, status="submitted")
        response = http_get_response(reverse("acct-login"), login)
        eq_(response.status_code, 200)
        # account overview page
        response = http_get_response(reverse("accounts"), views.AccountsView.as_view())
        eq_(response.status_code, 302)
        # profile page
        request_factory = RequestFactory()
        request = request_factory.get(self.user.profile.get_absolute_url())
        request = mock_middleware(request)
        request.user = AnonymousUser()
        response = views.ProfileView.as_view()(request, username=self.user.username)
        eq_(response.status_code, 200)

    @raises(Http404)
    def test_private_profile(self):
        """Test public views while not logged in"""
        response = http_get_response(reverse("acct-login"), login)
        eq_(response.status_code, 200)
        # account overview page
        response = http_get_response(reverse("accounts"), views.AccountsView.as_view())
        eq_(response.status_code, 302)<commit_msg>remove login view<commit_after>"""
Tests accounts views
"""

# Django
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.views import login
from django.http.response import Http404
from django.test import RequestFactory, TestCase
from django.urls import reverse

# Third Party
from mock import patch
from nose.tools import eq_, ok_, raises

# MuckRock
from muckrock.accounts import views
from muckrock.core.factories import (
    AgencyFactory,
    NotificationFactory,
    QuestionFactory,
    UserFactory,
)
from muckrock.core.test_utils import (
    http_get_response,
    http_post_response,
    mock_middleware,
)
from muckrock.core.utils import new_action, notify
from muckrock.foia.factories import FOIAComposerFactory, FOIARequestFactory
from muckrock.foia.views import Detail as FOIARequestDetail
from muckrock.qanda.views import Detail as QuestionDetail


def http_get_post(url, view, data):
    """Performs both a GET and a POST on the same url and view."""
    get_response = http_get_response(url, view)
    post_response = http_post_response(url, view, data)
    return (get_response, post_response)


class TestAccountFunctional(TestCase):
    """Functional tests for account"""

    def setUp(self):
        self.user = UserFactory()

    def test_public_views(self):
        """Test public views while not logged in"""
        # give the user a composer so they have a public profile
        FOIAComposerFactory(user=self.user, status="submitted")
        # account overview page
        response = http_get_response(reverse("accounts"), views.AccountsView.as_view())
        eq_(response.status_code, 302)
        # profile page
        request_factory = RequestFactory()
        request = request_factory.get(self.user.profile.get_absolute_url())
        request = mock_middleware(request)
        request.user = AnonymousUser()
        response = views.ProfileView.as_view()(request, username=self.user.username)
        eq_(response.status_code, 200)

    @raises(Http404)
    def test_private_profile(self):
        """Test public views while not logged in"""
        # account overview page
        response = http_get_response(reverse("accounts"), views.AccountsView.as_view())
        eq_(response.status_code, 302)
{'fraction_non_alphanumeric': 0.08522025524907369, 'fraction_numerical': 0.007410456978180321, 'mean_word_length': 3.932994923857868, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6799347', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1365, 'n_words': 375}