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

from __future__ import unicode_literals

import json

from django.utils.six.moves.urllib_parse import urlsplit

from django_webtest import WebTest

from .auth import TestUserMixin

from popolo.models import Person

from candidates.models import ExtraField
from .factories import CandidacyExtraFactory, PersonExtraFactory
from .uk_examples import UK2015ExamplesMixin


class TestUpdatePersonView(TestUserMixin, UK2015ExamplesMixin, WebTest):

    def setUp(self):
        super(TestUpdatePersonView, self).setUp()
        person_extra = PersonExtraFactory.create(
            base__id='2009',
            base__name='<NAME>'
        )

        CandidacyExtraFactory.create(
            election=self.election,
            base__person=person_extra.base,
            base__post=self.dulwich_post_extra.base,
            base__on_behalf_of=self.green_party_extra.base
        )

    def test_update_person_view_get_without_login(self):
        response = self.app.get('/person/2009/update')
        self.assertEqual(response.status_code, 302)
        split_location = urlsplit(response.location)
        self.assertEqual('/accounts/login/', split_location.path)
        self.assertEqual('next=/person/2009/update', split_location.query)

    def test_update_person_view_get_refused_copyright(self):
        response = self.app.get('/person/2009/update', user=self.user_refused)
        self.assertEqual(response.status_code, 302)
        split_location = urlsplit(response.location)
        self.assertEqual('/copyright-question', split_location.path)
        self.assertEqual('next=/person/2009/update', split_location.query)

    def test_update_person_view_get(self):
        # For the moment just check that the form's actually there:
        response = self.app.get('/person/2009/update', user=self.user)
        form = response.forms['person-details']
        self.assertIsNotNone(form)

    def test_update_person_submission_copyright_refused(self):<commit_msg>Test that not_standing values are preserved on 'identity edits'<commit_after># -*- coding: utf-8 -*-

from __future__ import unicode_literals

import json

from django.utils.six.moves.urllib_parse import urlsplit

from django_webtest import WebTest

from .auth import TestUserMixin

from popolo.models import Person

from candidates.models import ExtraField
from .factories import CandidacyExtraFactory, PersonExtraFactory
from .uk_examples import UK2015ExamplesMixin


class TestUpdatePersonView(TestUserMixin, UK2015ExamplesMixin, WebTest):

    def setUp(self):
        super(TestUpdatePersonView, self).setUp()
        person_extra = PersonExtraFactory.create(
            base__id='2009',
            base__name='<NAME>'
        )

        CandidacyExtraFactory.create(
            election=self.election,
            base__person=person_extra.base,
            base__post=self.dulwich_post_extra.base,
            base__on_behalf_of=self.green_party_extra.base
        )

    def test_update_person_should_not_lose_existing_not_standing(self):
        # Pretend that we know she wasn't standing in the earlier election:
        tessa = Person.objects.get(pk=2009)
        tessa.extra.not_standing.add(self.earlier_election)
        response = self.app.get('/person/2009/update', user=self.user)
        form = response.forms['person-details']
        form.submit()
        self.assertEqual(
            list(tessa.extra.not_standing.all()),
            [self.earlier_election])

    def test_update_person_view_get_without_login(self):
        response = self.app.get('/person/2009/update')
        self.assertEqual(response.status_code, 302)
        split_location = urlsplit(response.location)
        self.assertEqual('/accounts/login/', split_location.path)
        self.assertEqual('next=/person/2009/update', split_location.query)

    def test_update_person_view_get_refused_copyright(self):
        response = self.app.get('/person/2009/update', user=self.user_refused)
        self.assertEqual(response.status_code, 302)
        split_location = urlsplit(response.location)
        self.assertEqual('/copyright-question', split_location.path)
        self.assertEqual('next=/person/2009/update', split_location.query)

    def test_update_person_view_get(self):
        # For the moment just check that the form's actually there:
        response = self.app.get('/person/2009/update', user=self.user)
        form = response.forms['person-details']
        self.assertIsNotNone(form)

    def test_update_person_submission_copyright_refused(self):
{'fraction_non_alphanumeric': 0.09349682504926647, 'fraction_numerical': 0.018830742281585287, 'mean_word_length': 3.4828263002944064, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3612262', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1296, 'n_words': 232}