<commit_before>"""Tests for profile, library, album and photo views."""
from __future__ import unicode_literals
from django.test import Client, TestCase
from django.contrib.auth.models import AnonymousUser, User
from imager_profile.tests import UserFactory
from .test_auth import user_from_response

DEFAULT_IMG = 'media/django-magic.jpg'
HOME = '/'
REG = '/accounts/register/'
LOGIN = '/accounts/login/'
LOGOUT = '/accounts/logout/'
PROFILE = '/accounts/logout/'
LIBRARY = '/images/library/'
ALBUM = '/images/album/'
PHOTO = '/images/photo/'

# import photofactory

# GOOD_REG_PARAMS = {'username': 'CoolPerson{}',
#                    'email': '<EMAIL>',
#                    'password1': '<PASSWORD>',
#                    'password2': '<PASSWORD>'}

NUM_USERS = 3

# LINK_PATTERN = r'/accounts/activate/.*/'


class AuthenticatedCase(TestCase):
    """Test case where we will fully register as part of setup."""

    def setUp(self):
        """Set up for unauthenticated case with no users."""
        self.client = Client()
        self.user_batch = UserFactory.create_batch(NUM_USERS)

        for user in self.user_batch:
            params = {'username': user.username, 'password': '<PASSWORD>'}
            response = self.client.post(LOGIN, params, follow=True)
            setattr(self, '{}_response'.format(user.username), response)

    def test_num_users(self):
        """Test there are as many users in the database as we registered."""
        self.assertEqual(User.objects.count(), NUM_USERS)

    def test_all_logged_in(self):
        """Test that all users are logged in."""
        for user in self.user_batch:
            response = getattr(self, '{}_response'.format(user.username))
            context_user = user_from_response(response)
            self.assertEqual(user, context_user)
            self.assertTrue(user.is_authenticated())
            self.assertTrue(context_user.is_authenticated())

    # test that profile page is loaded from each response
    # test that library page is accessible
    # test default image if no cover
    # test that owners see all of their albums
    # test that owners see all of their photos
    # test that owners don't see anyone elses's albums
    # test that owners don't see anyone else's photos
    # test that each album link from library can be clicked on (??)
    # test that each photo link in library and in album can be clicked on
<commit_msg>SetUp creates separate client sessions per user.<commit_after>"""Tests for profile, library, album and photo views."""
from __future__ import unicode_literals
from django.test import Client, TestCase
from django.contrib.auth.models import User
from imager_profile.tests import UserFactory
from .test_auth import user_from_response

DEFAULT_IMG = 'media/django-magic.jpg'
HOME = '/'
REG = '/accounts/register/'
LOGIN = '/accounts/login/'
LOGOUT = '/accounts/logout/'
PROFILE = '/accounts/profile/'
LIBRARY = '/images/library/'
ALBUM = '/images/album/'
PHOTO = '/images/photo/'

# import photofactory

# GOOD_REG_PARAMS = {'username': 'CoolPerson{}',
#                    'email': '<EMAIL>',
#                    'password1': '<PASSWORD>',
#                    'password2': '<PASSWORD>'}

NUM_USERS = 3

# LINK_PATTERN = r'/accounts/activate/.*/'


class AuthenticatedCase(TestCase):
    """Test case where we will fully register as part of setup."""

    def setUp(self):
        """Set up for unauthenticated case with no users."""
        self.user_batch = UserFactory.create_batch(NUM_USERS)
        self.users_sessions = []

        for user in self.user_batch:
            client = Client()
            params = {'username': user.username, 'password': '<PASSWORD>'}
            response = client.post(LOGIN, params, follow=True)
            session = {'user': user, 'client': client, 'login_response': response}
            self.users_sessions.append(session)

    def test_num_users(self):
        """Test there are as many users in the database as we registered."""
        self.assertEqual(User.objects.count(), NUM_USERS)

    def test_all_logged_in(self):
        """Test that all users are logged in."""
        for session in self.users_sessions:
            user = session['user']
            context_user = user_from_response(session['login_response'])
            self.assertEqual(user, context_user)
            self.assertTrue(user.is_authenticated())
            self.assertTrue(context_user.is_authenticated())

    def test_login_to_profile(self):
        """Test that response has redirected to profile page."""
        for session in self.users_sessions:
            login_response = session['login_response']
            self.assertEqual(login_response.status_code, 200)
            self.assertEqual(login_response.request['PATH_INFO'], PROFILE)

    def test_library_ok(self):
        """Test that library page is accessible."""
        for session in self.users_sessions:
            client = session['client']
            response = client.get('/images/library/')
            self.assertEqual(response.status_code, 200)

    def test_library_ok(self):
        """Test that library page is accessible."""
        for session in self.users_sessions:
            client = session['client']
            response = client.get('/images/library/')
            self.assertEqual(response.status_code, 200)


    # test that library page is accessible
    # test default image if no cover
    # test that owners see all of their albums
    # test that owners see all of their photos
    # test that owners don't see anyone elses's albums
    # test that owners don't see anyone else's photos
    # test that each album link from library can be clicked on (??)
    # test that each photo link in library and in album can be clicked on

{'fraction_non_alphanumeric': 0.10899324207243112, 'fraction_numerical': 0.0025992029111072605, 'mean_word_length': 2.9185336048879837, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2125984', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1557, 'n_words': 499}