<commit_before># -*- coding: utf-8 -*-

u"""
.. module:: test_users
"""
from django.test import Client
from django.test import TestCase

from apps.volontulo.tests import common
from apps.volontulo.models import Offer


class TestUsersProfile(TestCase):
    u"""Class responsible for testing users profile view."""

    @classmethod
    def setUpTestData(cls):
        # volunteer user - totally useless
        common.initialize_empty_volunteer()
        # organization user - no offers
        common.initialize_empty_organization()
        # volunteer user - offers, organizations
        common.initialize_filled_volunteer_and_organization()

    def setUp(self):
        u"""Set up each test."""
        self.client = Client()

    # pylint: disable=invalid-name
    def test__logged_user_profile_anonymous(self):
        u"""Testing user profile page for anonymous."""
        response = self.client.get('/me', follow=True)

        self.assertRedirects(
            response,
            'http://testserver/login?next=/me',
            302,
            200,
        )
        self.assertEqual(len(response.redirect_chain), 1)
        self.assertEqual(
            response.redirect_chain[0],
            ('http://testserver/login?next=/me', 302),
        )

    # pylint: disable=invalid-name
    def test__logged_user_profile(self):
        u"""Testing default views on user profile form."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'users/user_profile.html')
        # check if contain image upload form (all users)
        # pylint: disable=no-member
        self.assertIn('image', response.context)
        self.assertContains(response, u'Wybierz grafikę')

    # pylint: disable=invalid-name
    def test__logged_user_profile_empty_volunteer(self):
        u"""Testing user profile page for volunteers."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        # pylint: disable=no-member
        self.assertIn('offers', response.context)
        self.assertContains(
            response,
            u"Zgłoś się w jednej z dostępnych "
            u"ofert wolontariuatu i zapełnij to miejsce."
        )

    # pylint: disable=invalid-name
    def test__logged_user_profile_filled_volunteer(self):
        u"""Testing user profile page for volunteers."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        # pylint: disable=no-member
        self.assertIn('offers', response.context)
        self.assertContains(
            response,
            u"Zgłoś się w jednej z dostępnych "
            u"ofert wolontariuatu i zapełnij to miejsce."
        )

    # pylint: disable=invalid-name
    def test__logged_user_profile_empty_organization(self):
        u"""Testing user profile page for empty organization."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        # pylint: disable=no-member
        self.assertIn('offers', response.context)
        self.assertContains(
            response,
            u'Ta organizacja nie utworzyła jeszcze żadnych ofert.'
        )

    # pylint: disable=invalid-name
    def test__logged_user_profile_filled_organization(self):
        u"""Testing user profile page for filled organization."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        # pylint: disable=no-member
        self.assertIn('offers', response.context)
        self.assertEqual(
            4,
            Offer.objects.all().filter(status_old=u'ACTIVE').count()
        )
        self.assertNotContains(
            response,
            u'Ta organizacja nie utworzyła jeszcze żadnych ofert.'
        )

    def test__userprofile_phone_no(self):
        u"""Testing user profile page for filled organization."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'users/user_profile.html')
        # pylint: disable=no-member
        self.assertIn('profile_form', response.context)
        self.assertContains(response, u'333666999')

    def test__userprofile_first_and_last_name(self):
        u"""Testing user profile page for filled first and last name."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'users/user_profile.html')
        # pylint: disable=no-member
        self.assertIn('profile_form', response.context)
        self.assertContains(response, u'Grzegorz')
        self.assertContains(response, u'Brzęczyszczykiewicz')

    def test__no_email_field_on_edit_profile_form(self):
        u"""Test if Email field is not visible edit profile form"""

        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'users/user_profile.html')
        # pylint: disable=no-member
        self.assertIn('profile_form', response.context)
        self.assertNotContains(response, u'Email')
<commit_msg>[issue-445] adds full stop at the end of docstring<commit_after># -*- coding: utf-8 -*-

u"""
.. module:: test_users
"""
from django.test import Client
from django.test import TestCase

from apps.volontulo.tests import common
from apps.volontulo.models import Offer


class TestUsersProfile(TestCase):
    u"""Class responsible for testing users profile view."""

    @classmethod
    def setUpTestData(cls):
        # volunteer user - totally useless
        common.initialize_empty_volunteer()
        # organization user - no offers
        common.initialize_empty_organization()
        # volunteer user - offers, organizations
        common.initialize_filled_volunteer_and_organization()

    def setUp(self):
        u"""Set up each test."""
        self.client = Client()

    # pylint: disable=invalid-name
    def test__logged_user_profile_anonymous(self):
        u"""Testing user profile page for anonymous."""
        response = self.client.get('/me', follow=True)

        self.assertRedirects(
            response,
            'http://testserver/login?next=/me',
            302,
            200,
        )
        self.assertEqual(len(response.redirect_chain), 1)
        self.assertEqual(
            response.redirect_chain[0],
            ('http://testserver/login?next=/me', 302),
        )

    # pylint: disable=invalid-name
    def test__logged_user_profile(self):
        u"""Testing default views on user profile form."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'users/user_profile.html')
        # check if contain image upload form (all users)
        # pylint: disable=no-member
        self.assertIn('image', response.context)
        self.assertContains(response, u'Wybierz grafikę')

    # pylint: disable=invalid-name
    def test__logged_user_profile_empty_volunteer(self):
        u"""Testing user profile page for volunteers."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        # pylint: disable=no-member
        self.assertIn('offers', response.context)
        self.assertContains(
            response,
            u"Zgłoś się w jednej z dostępnych "
            u"ofert wolontariuatu i zapełnij to miejsce."
        )

    # pylint: disable=invalid-name
    def test__logged_user_profile_filled_volunteer(self):
        u"""Testing user profile page for volunteers."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        # pylint: disable=no-member
        self.assertIn('offers', response.context)
        self.assertContains(
            response,
            u"Zgłoś się w jednej z dostępnych "
            u"ofert wolontariuatu i zapełnij to miejsce."
        )

    # pylint: disable=invalid-name
    def test__logged_user_profile_empty_organization(self):
        u"""Testing user profile page for empty organization."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        # pylint: disable=no-member
        self.assertIn('offers', response.context)
        self.assertContains(
            response,
            u'Ta organizacja nie utworzyła jeszcze żadnych ofert.'
        )

    # pylint: disable=invalid-name
    def test__logged_user_profile_filled_organization(self):
        u"""Testing user profile page for filled organization."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        # pylint: disable=no-member
        self.assertIn('offers', response.context)
        self.assertEqual(
            4,
            Offer.objects.all().filter(status_old=u'ACTIVE').count()
        )
        self.assertNotContains(
            response,
            u'Ta organizacja nie utworzyła jeszcze żadnych ofert.'
        )

    def test__userprofile_phone_no(self):
        u"""Testing user profile page for filled organization."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'users/user_profile.html')
        # pylint: disable=no-member
        self.assertIn('profile_form', response.context)
        self.assertContains(response, u'333666999')

    def test__userprofile_first_and_last_name(self):
        u"""Testing user profile page for filled first and last name."""
        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'users/user_profile.html')
        # pylint: disable=no-member
        self.assertIn('profile_form', response.context)
        self.assertContains(response, u'Grzegorz')
        self.assertContains(response, u'Brzęczyszczykiewicz')

    def test__no_email_field_on_edit_profile_form(self):
        u"""Test if Email field is not visible edit profile form."""

        self.client.post('/login', {
            'email': u'<EMAIL>',
            'password': '<PASSWORD>',
        })
        response = self.client.get('/me')

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'users/user_profile.html')
        # pylint: disable=no-member
        self.assertIn('profile_form', response.context)
        self.assertNotContains(response, u'Email')

{'fraction_non_alphanumeric': 0.1234235749117202, 'fraction_numerical': 0.005969396334286194, 'mean_word_length': 2.357324301439458, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '1683274', 'n_tokens_mistral': 3458, 'n_tokens_neox': 3368, 'n_words': 686}