<commit_before>from copy import copy
from unittest import mock

from django.conf import settings
from django.core.urlresolvers import reverse
from django.test import TestCase

from .. import view_helpers


class ViewTest(TestCase):
    fixtures = [
        'wizard_builder_data',
    ]

    @classmethod
    def setUpClass(cls):
        settings.SITE_ID = 1
        super().setUpClass()

    def setUp(self):
        super().setUp()
        self.step = '1'
        self.data = {'question_2': 'aloe ipsum speakerbox'}
        self.url = reverse('wizard_update', kwargs={'step': self.step})

    def test_storage_receives_post_data(self):
        self.client.post(self.url, self.data)
        self.assertEqual(
            self.client.session[view_helpers.StorageHelper.session_data_key],
            self.data,
        )

    def test_storage_populates_form_data(self):
        self.client.post(self.url, self.data)
        response = self.client.get(self.url)
        form = response.context['form']
        self.assertEqual(
            form.data,
            self.data,
        )

    def test_form_data_accurate_when_goto_step_specified(self):
        data_with_goto_step = copy(self.data)<commit_msg>better test name<commit_after>from copy import copy
from unittest import mock

from django.conf import settings
from django.core.urlresolvers import reverse
from django.test import TestCase

from .. import view_helpers


class ViewTest(TestCase):
    fixtures = [
        'wizard_builder_data',
    ]

    @classmethod
    def setUpClass(cls):
        settings.SITE_ID = 1
        super().setUpClass()

    def setUp(self):
        super().setUp()
        self.step = '1'
        self.data = {'question_2': 'aloe ipsum speakerbox'}
        self.url = reverse('wizard_update', kwargs={'step': self.step})

    def test_storage_receives_post_data(self):
        self.client.post(self.url, self.data)
        self.assertEqual(
            self.client.session[view_helpers.StorageHelper.session_data_key],
            self.data,
        )

    def test_storage_populates_form_data(self):
        self.client.post(self.url, self.data)
        response = self.client.get(self.url)
        form = response.context['form']
        self.assertEqual(
            form.data,
            self.data,
        )

    def test_form_data_wizard_goto_step_regression(self):
        data_with_goto_step = copy(self.data)
{'fraction_non_alphanumeric': 0.10145530145530146, 'fraction_numerical': 0.002494802494802495, 'mean_word_length': 2.596412556053812, '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': '7131099', 'n_tokens_mistral': 740, 'n_tokens_neox': 730, 'n_words': 139}