def test_error_on_no_relationship_value(self):
     "ValueError on no relationship value"
     with self.assertRaises(ValueError):
         rules = extract_rule({
             'person_one': u'1',
             'person_two': u'12',
         })
 def test_error_on_no_operand_two(self):
     "ValueError on no operand (i.e. nothing in rule[1] or rule[2])"
     with self.assertRaises(ValueError):
         rules = extract_rule({
             'person_one': u'12',
             'relationship': u'---'
         })
Exemple #3
0
def process_rule(request, paradigm_id):
    p = get_object_or_404(Paradigm, pk=paradigm_id)
    # do we have do_identicals? 
    if 'process_identicals' in request.POST:
        # 1. process form
        members = find_identicals(p)
        
        # 2. implement rule
        if len(members) > 0:
            # 3. save rule to rule table.
            rule = Rule.objects.create(
                paradigm = p,
                rule="Identical Entries set to Total Syncretism",
                editor=request.user
            )
            for m1, m2 in members:
                # Ignore anything we've already set
                if not Relationship.objects.has_relationship_between(m1[0], m2[0]):
                    rel = Relationship.objects.create(
                        paradigm = p, 
                        pronoun1_id=m1[0], pronoun2_id=m2[0], 
                        relationship='TS',
                        editor=request.user
                    )
                    rule.relationships.add(rel)
        
        return redirect('pronouns:edit_relationships', p.id)
        
    elif 'process_rule' in request.POST:
        # 1. process form
        rule_form = RuleForm(request.POST or None)
        if rule_form.is_valid():
            # 2. implement rule
            try:
                rule = extract_rule(ruleform.clean())
            except ValueError:
                # form is broken - go away.
                return redirect('pronouns:edit_relationships', p.id)
                
            # members = process_rule(rule, p.pronoun_set.all())
            
            # 3. save rule to rule table.
            # rule = Rule.objects.create(
            #     paradigm = p,
            #     rule="Identical Entries set to Total Syncretism",
            #     editor=request.user
            # )
            # for p1, p2 in members:
            #     # Ignore anything we've already set
            #     if Relationship.objects.has_relationship_between(p1, p2) == False:
            #         rel = Relationship.objects.create(
            #             paradigm = p, pronoun1=p1, pronoun2=p2, relationship='TS',
            #             editor=request.user
            #         )
            #         rule.relationships.add(rel)
        
        # Note: Invalid forms are IGNORED
        return redirect('pronouns:edit_relationships', p.id)
    else:
        return redirect('pronouns:detail', p.id)
 def test_ignore_extra_fields(self):
     "Empty Ignore Irrelevant Fields"
     rules = extract_rule({
         'fudge_one': u'1',
         'fudge_two': u'2',
         'person_one': u'1',
         'person_two': u'12',
         'relationship': u'FO'
     })
     assert rules['one'].keys() == ['person']
     assert rules['two'].keys() == ['person']
 def test_empty_fields_get_ignored(self):
     "Empty fields don't get processed"
     rules = extract_rule({
         'alignment_one': u'---',
         'alignment_two': u'---',
         'gender_one': u'---',
         'gender_two': u'---',
         'number_one': u'---',
         'number_two': u'---',
         'person_one': u'1',
         'person_two': u'12',
         'relationship': u'FO'
     })
     assert rules['one'].keys() == ['person']
     assert rules['two'].keys() == ['person']