Example #1
0
 def test_save(self):
     postdata = self._generate_post_data(self.pdm)
     
     for pronoun, formset in create_pronoun_formset(self.pdm, postdata):
         saved = save_pronoun_formset(self.pdm, pronoun, formset, self.editor)
     
     assert Lexicon.objects.count() == 3, "expecting 3"
Example #2
0
 def test_repeated_saves_dont_explode(self):
     # saving the same data multiple times should not increase the size of the set.
     
     postdata = self._generate_post_data(self.pdm)
     postdata['1_1-1-entry'] = 'testing' # change something
     postdata['1_1-TOTAL_FORMS'] = u'2'
     
     for pronoun, formset in create_pronoun_formset(self.pdm, postdata):
         saved = save_pronoun_formset(self.pdm, pronoun, formset, self.editor)
         saved = save_pronoun_formset(self.pdm, pronoun, formset, self.editor)
         saved = save_pronoun_formset(self.pdm, pronoun, formset, self.editor)
     
     # should now have 4 lexical items
     assert Lexicon.objects.count() == 4, "expecting 4"
     
     # CHECK VALUES....
     for pron in self.pdm.pronoun_set.all():
         entries = pron.entries.all().order_by('id')
         
         if pron.id == 1:
             assert len(entries) == 2
             assert entries[0].entry == 'pron-{0}'.format(pron.id)
             assert entries[0].annotation == 'ann-{0}'.format(pron.id)
             # the new lexical entry!
             assert entries[1].entry == 'testing'
             assert entries[1].annotation == ''
         else:
             assert len(entries) == 1
             assert entries[0].entry == 'pron-{0}'.format(pron.id)
             assert entries[0].annotation == 'ann-{0}'.format(pron.id)
Example #3
0
    def test_save(self):
        postdata = self._generate_post_data(self.pdm)

        for pronoun, formset in create_pronoun_formset(self.pdm, postdata):
            save_pronoun_formset(self.pdm, pronoun, formset, self.editor)

        assert Lexicon.objects.count() == 3, "expecting 3"
Example #4
0
 def test_tokens(self):
     formsets = create_pronoun_formset(self.pdm,
                                       self._generate_post_data(self.pdm))
     rows = sort_formset(formsets)
     assert rows[0][0] == u'1st (excl) Person Singular'
     assert rows[1][0] == u'2nd Person Singular'
     assert rows[2][0] == u'3rd Person Singular'
Example #5
0
 def test_row_formsets(self):
     formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm))
     for row in sort_formset(formsets):
         assert row[1]['A'] is not None
         assert row[1]['S'] is None
         assert row[1]['O'] is None
         assert row[1]['P'] is None
Example #6
0
    def test_repeated_saves_dont_explode(self):
        # saving the same data multiple times should not increase the size of
        # the set.

        postdata = self._generate_post_data(self.pdm)
        postdata['1_1-1-entry'] = 'testing'  # change something
        postdata['1_1-TOTAL_FORMS'] = u'2'

        for pronoun, formset in create_pronoun_formset(self.pdm, postdata):
            save_pronoun_formset(self.pdm, pronoun, formset, self.editor)
            save_pronoun_formset(self.pdm, pronoun, formset, self.editor)
            save_pronoun_formset(self.pdm, pronoun, formset, self.editor)

        # should now have 4 lexical items
        assert Lexicon.objects.count() == 4, "expecting 4"

        # CHECK VALUES....
        for pron in self.pdm.pronoun_set.all():
            entries = pron.entries.all().order_by('id')

            if pron.id == 1:
                assert len(entries) == 2
                assert entries[0].entry == 'pron-{0}'.format(pron.id)
                assert entries[0].annotation == 'ann-{0}'.format(pron.id)
                # the new lexical entry!
                assert entries[1].entry == 'testing'
                assert entries[1].annotation == ''
            else:
                assert len(entries) == 1
                assert entries[0].entry == 'pron-{0}'.format(pron.id)
                assert entries[0].annotation == 'ann-{0}'.format(pron.id)
Example #7
0
 def test_each_formset_gets_the_right_entry(self):
     """Does each formset have the correct entry?"""
     formsets = create_pronoun_formset(self.pdm)
     for formid, form in formsets:
         assert len(form.forms) == formid.entries.count() == 1
         # is PK correct?
         assert form.forms[0].initial['entry'] == 'pron-%d' % formid.entries.all()[0].pk
Example #8
0
 def test_all_forms_are_valid(self):
     """All created formsets with these data should be valid"""
     formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm))
     for formid, formset in formsets:
         for form in formset.forms:
             if not form.is_valid():
                 raise AssertionError("Form should be valid. Errors are: %r" % form.errors)
         assert formset.is_valid(), "Formset should be valid. Errors are: %r" % formset.errors
Example #9
0
 def test_each_formset_gets_the_right_entry(self):
     """Does each formset have the correct entry?"""
     formsets = create_pronoun_formset(self.pdm)
     for formid, form in formsets:
         assert len(form.forms) == formid.entries.count() == 1
         # is PK correct?
         expected = 'pron-%d' % formid.entries.all()[0].pk
         assert form.forms[0].initial['entry'] == expected
Example #10
0
 def test_row_formsets(self):
     formsets = create_pronoun_formset(self.pdm,
                                       self._generate_post_data(self.pdm))
     for row in sort_formset(formsets):
         assert row[1]['A'] is not None
         assert row[1]['S'] is None
         assert row[1]['O'] is None
         assert row[1]['P'] is None
Example #11
0
 def test_four_per_row(self):
     formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm))
     for row in sort_formset(formsets):
         assert len(row[1]) == 4
         assert 'A' in row[1]
         assert 'S' in row[1]
         assert 'O' in row[1]
         assert 'P' in row[1]
Example #12
0
 def test_four_per_row(self):
     formsets = create_pronoun_formset(self.pdm,
                                       self._generate_post_data(self.pdm))
     for row in sort_formset(formsets):
         assert len(row[1]) == 4
         assert 'A' in row[1]
         assert 'S' in row[1]
         assert 'O' in row[1]
         assert 'P' in row[1]
Example #13
0
 def test_each_formset_gets_the_right_values(self):
     """Is the value of each form field set correctly?"""
     formsets = create_pronoun_formset(self.pdm)
     for formid, form in formsets:
         assert len(form.forms) == formid.entries.count() == 1
         initial = form.forms[0].initial
         expected = formid.entries.all()[0]
         for key in initial:
             assert getattr(expected, key) == initial[key], \
                 'Expected %s to be %r not %r' % (key, expected, initial[key])
Example #14
0
    def test_formset_with_multiple_entries(self):
        pron_with_extra = self._add_extra_entry()
        # test formset
        formsets = create_pronoun_formset(self.pdm)

        for formid, form in formsets:
            if formid == pron_with_extra:
                assert len(form.forms) == formid.entries.count() == 2
            else:
                assert len(form.forms) == formid.entries.count() == 1
Example #15
0
 def test_formset_with_multiple_entries(self):
     pron_with_extra = self._add_extra_entry()
     # test formset
     formsets = create_pronoun_formset(self.pdm)
     
     for formid, form in formsets:
         if formid == pron_with_extra:
             assert len(form.forms) == formid.entries.count() == 2
         else:
             assert len(form.forms) == formid.entries.count() == 1
Example #16
0
 def test_formset_submission_with_create(self):
     postdata = self._generate_post_data(self.pdm)
     postdata['1_1-1-entry'] = 'testing' # change something
     postdata['1_1-TOTAL_FORMS'] = u'2'
     formsets = create_pronoun_formset(self.pdm, postdata)
     
     for f in formsets: 
         assert f[1].is_valid(), "Formset should be valid!"
         if f[0].id == 1:
             assert f[1].has_changed(), "This one formset should have changed!"
         else:
             assert not f[1].has_changed(), "This formset should not have changed!"
Example #17
0
 def test_all_forms_are_valid(self):
     """All created formsets with these data should be valid"""
     formsets = create_pronoun_formset(self.pdm,
                                       self._generate_post_data(self.pdm))
     for formid, formset in formsets:
         for form in formset.forms:
             if not form.is_valid():
                 raise AssertionError(
                     "Form should be valid. Errors are: %r" % form.errors)
         if not formset.is_valid():
             raise AssertionError(
                 "Formset should be valid. Errors are: %r" % formset.errors)
Example #18
0
 def test_each_formset_gets_the_right_values(self):
     """Is the value of each form field set correctly?"""
     formsets = create_pronoun_formset(self.pdm)
     for formid, form in formsets:
         assert len(form.forms) == formid.entries.count() == 1
         initial = form.forms[0].initial
         expected = formid.entries.all()[0]
         for key in initial:
             obtained = initial[key]
             if getattr(expected, key) != obtained:
                 e = 'Expected %s = %r not %r' % (key, expected, obtained)
                 raise AssertionError(e)
Example #19
0
 def test_save_with_update(self):
     postdata = self._generate_post_data(self.pdm)
     postdata['1_1-0-entry'] = 'testing' # change something
     
     for pronoun, formset in create_pronoun_formset(self.pdm, postdata):
         saved = save_pronoun_formset(self.pdm, pronoun, formset, self.editor)
     
     # should still only have 3 lexical items
     assert Lexicon.objects.count() == 3, "expecting 3"
     
     # ...but the form of pk 1 should have changed..
     lex = Lexicon.objects.get(pk=1)
     assert lex.entry == 'testing'
Example #20
0
    def test_save_with_update(self):
        postdata = self._generate_post_data(self.pdm)
        postdata['1_1-0-entry'] = 'testing'  # change something

        for pronoun, formset in create_pronoun_formset(self.pdm, postdata):
            save_pronoun_formset(self.pdm, pronoun, formset, self.editor)

        # should still only have 3 lexical items
        assert Lexicon.objects.count() == 3, "expecting 3"

        # ...but the form of pk 1 should have changed..
        lex = Lexicon.objects.get(pk=1)
        assert lex.entry == 'testing'
Example #21
0
 def test_save_with_delete(self):
     postdata = self._generate_post_data(self.pdm)
     postdata['1_1-0-entry'] = u''
     
     for pronoun, formset in create_pronoun_formset(self.pdm, postdata):
         saved = save_pronoun_formset(self.pdm, pronoun, formset, self.editor)
         
     # should now have 2 lexical items
     assert Lexicon.objects.count() == 2, "expecting 2"
     # should have an empty pronoun set for pronoun 1
     assert Pronoun.objects.get(pk=1).entries.count() == 0
     # should have deleted the lexical object 1
     with self.assertRaises(Lexicon.DoesNotExist):
         assert Lexicon.objects.get(pk=1)
Example #22
0
    def test_formset_submission_with_create(self):
        postdata = self._generate_post_data(self.pdm)
        postdata['1_1-1-entry'] = 'testing'  # change something
        postdata['1_1-TOTAL_FORMS'] = u'2'
        formsets = create_pronoun_formset(self.pdm, postdata)

        for f in formsets:
            assert f[1].is_valid(), "Formset should be valid!"
            if f[0].id == 1:
                assert f[1].has_changed(), \
                    "This one formset should have changed!"
            else:
                assert not f[1].has_changed(), \
                    "This formset should not have changed!"
Example #23
0
def edit(request, paradigm_id):
    pdm = get_object_or_404(Paradigm, pk=paradigm_id)
    paradigm_form = ParadigmForm(request.POST or None, instance=pdm, prefix='pdm')
    pronoun_form = create_pronoun_formset(pdm, request.POST or None)
    
    # save if valid.
    if pronoun_formsets_are_valid(pronoun_form) and paradigm_form.is_valid():
        pdm = paradigm_form.save(commit=False)
        pdm.editor = request.user
        pdm.save()
        for pronoun, formset in pronoun_form:
            save_pronoun_formset(pdm, pronoun, formset, request.user)
        return redirect('pronouns:detail', paradigm_id=pdm.id)
        
    # the initial view and the error view
    return render_to_response('pronouns/edit.html', {
        'paradigm': pdm,
        'paradigm_form': paradigm_form,
        'pronouns': sort_formset(pronoun_form),
    }, context_instance=RequestContext(request))
Example #24
0
def edit(request, paradigm_id):
    pdm = get_object_or_404(Paradigm, pk=paradigm_id)
    paradigm_form = ParadigmForm(request.POST or None,
                                 instance=pdm,
                                 prefix='pdm')
    pronoun_form = create_pronoun_formset(pdm, request.POST or None)
    # save if valid.
    if pronoun_formsets_are_valid(pronoun_form) and paradigm_form.is_valid():
        pdm = paradigm_form.save(commit=False)
        pdm.editor = request.user
        pdm.save()
        for pronoun, formset in pronoun_form:
            save_pronoun_formset(pdm, pronoun, formset, request.user)
        return redirect('pronouns:detail', paradigm_id=pdm.id)

    # the initial view and the error view
    return render(
        request, 'pronouns/edit.html', {
            'paradigm': pdm,
            'paradigm_form': paradigm_form,
            'pronouns': sort_formset(pronoun_form),
        })
Example #25
0
 def test_change_is_valid(self):
     postdata = self._generate_post_data(self.pdm)
     postdata['1_1-0-entry'] = 'testing' # change something
     formsets = create_pronoun_formset(self.pdm, postdata)
     assert pronoun_formsets_are_valid(formsets)
Example #26
0
 def test_is_valid_with_addition(self):
     postdata = self._generate_post_data(self.pdm)
     postdata['1_1-1-entry'] = 'testing' # change something
     postdata['1_1-TOTAL_FORMS'] = u'2'
     formsets = create_pronoun_formset(self.pdm, postdata)
     assert pronoun_formsets_are_valid(formsets)
Example #27
0
 def test_valid(self):
     formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm))
     assert pronoun_formsets_are_valid(formsets)
Example #28
0
 def test_add_valid(self):
     self._add_extra_entry()
     formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm))
     assert pronoun_formsets_are_valid(formsets)
Example #29
0
 def test_change_is_valid(self):
     postdata = self._generate_post_data(self.pdm)
     postdata['1_1-0-entry'] = 'testing'  # change something
     formsets = create_pronoun_formset(self.pdm, postdata)
     assert pronoun_formsets_are_valid(formsets)
Example #30
0
 def test_add_valid(self):
     self._add_extra_entry()
     formsets = create_pronoun_formset(self.pdm,
                                       self._generate_post_data(self.pdm))
     assert pronoun_formsets_are_valid(formsets)
Example #31
0
 def test_number_of_rows(self):
     formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm))
     sortf = sort_formset(formsets)
     assert len(sortf) == 3
Example #32
0
 def test_tokens(self):
     formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm))
     rows = sort_formset(formsets)
     assert rows[0][0] == u'1st (excl) Person Singular'
     assert rows[1][0] == u'2nd Person Singular'
     assert rows[2][0] == u'3rd Person Singular'
Example #33
0
 def test_all_forms_get_created(self):
     """Do we get the right number of forms?"""
     formsets = create_pronoun_formset(self.pdm)
     assert len(formsets) == self.pdm.pronoun_set.count()
Example #34
0
 def test_is_valid_with_addition(self):
     postdata = self._generate_post_data(self.pdm)
     postdata['1_1-1-entry'] = 'testing'  # change something
     postdata['1_1-TOTAL_FORMS'] = u'2'
     formsets = create_pronoun_formset(self.pdm, postdata)
     assert pronoun_formsets_are_valid(formsets)
Example #35
0
 def test_formset_submssion(self):
     """Test POST data works"""
     postdata = self._generate_post_data(self.pdm)
     formsets = create_pronoun_formset(self.pdm, postdata)
     for formid, formset in formsets:
         assert not formset.has_changed()
Example #36
0
 def test_number_of_rows(self):
     formsets = create_pronoun_formset(self.pdm,
                                       self._generate_post_data(self.pdm))
     sortf = sort_formset(formsets)
     assert len(sortf) == 3
Example #37
0
 def test_valid(self):
     formsets = create_pronoun_formset(self.pdm,
                                       self._generate_post_data(self.pdm))
     assert pronoun_formsets_are_valid(formsets)
Example #38
0
 def test_formset_submssion(self):
     """Test POST data works"""
     postdata = self._generate_post_data(self.pdm)
     formsets = create_pronoun_formset(self.pdm, postdata)
     for formid, formset in formsets:
         assert not formset.has_changed()
Example #39
0
 def test_all_forms_get_created(self):
     """Do we get the right number of forms?"""
     formsets = create_pronoun_formset(self.pdm)
     assert len(formsets) == self.pdm.pronoun_set.count()