Example #1
0
    def test_form_update(self):
        instance = BitFieldTestModel.objects.create(flags=0)
        for k in BitFieldTestModel.flags:
            self.assertFalse(bool(getattr(instance.flags, k)))

        data = {'flags': ['FLAG_0', 'FLAG_1']}
        form = BitFieldTestModelForm(data=data, instance=instance)
        self.failUnless(form.is_valid())
        instance = form.save()
        for k in BitFieldTestModel.flags:
            self.assertEquals(bool(getattr(instance.flags, k)), k in data['flags'])
        
        data = {'flags': ['FLAG_2', 'FLAG_3']}
        form = BitFieldTestModelForm(data=data, instance=instance)
        self.failUnless(form.is_valid())
        instance = form.save()
        for k in BitFieldTestModel.flags:
            self.assertEquals(bool(getattr(instance.flags, k)), k in data['flags'])
        
        data = {'flags': []}
        form = BitFieldTestModelForm(data=data, instance=instance)
        self.failUnless(form.is_valid())
        instance = form.save()
        for k in BitFieldTestModel.flags:
            self.assertFalse(bool(getattr(instance.flags, k)))
Example #2
0
    def test_form_update(self):
        instance = BitFieldTestModel.objects.create(flags=0)
        for k in BitFieldTestModel.flags:
            self.assertFalse(bool(getattr(instance.flags, k)))

        data = {'flags': ['FLAG_0', 'FLAG_1']}
        form = BitFieldTestModelForm(data=data, instance=instance)
        self.failUnless(form.is_valid())
        instance = form.save()
        for k in BitFieldTestModel.flags:
            self.assertEquals(bool(getattr(instance.flags, k)), k
                              in data['flags'])

        data = {'flags': ['FLAG_2', 'FLAG_3']}
        form = BitFieldTestModelForm(data=data, instance=instance)
        self.failUnless(form.is_valid())
        instance = form.save()
        for k in BitFieldTestModel.flags:
            self.assertEquals(bool(getattr(instance.flags, k)), k
                              in data['flags'])

        data = {'flags': []}
        form = BitFieldTestModelForm(data=data, instance=instance)
        self.failUnless(form.is_valid())
        instance = form.save()
        for k in BitFieldTestModel.flags:
            self.assertFalse(bool(getattr(instance.flags, k)))
Example #3
0
 def test_form_new_invalid(self):
     invalid_data_dicts = [
         {'flags': ['FLAG_0', 'FLAG_FLAG']},
         {'flags': ['FLAG_4']},
         {'flags': [1, 2]}
     ]
     for invalid_data in invalid_data_dicts:
         form = BitFieldTestModelForm(data=invalid_data)
         self.assertFalse(form.is_valid())
Example #4
0
 def test_form_new_invalid(self):
     invalid_data_dicts = [{
         'flags': ['FLAG_0', 'FLAG_FLAG']
     }, {
         'flags': ['FLAG_4']
     }, {
         'flags': [1, 2]
     }]
     for invalid_data in invalid_data_dicts:
         form = BitFieldTestModelForm(data=invalid_data)
         self.assertFalse(form.is_valid())
Example #5
0
 def test_form_new(self):
     data_dicts = [
         {'flags': ['FLAG_0', 'FLAG_1']},
         {'flags': ['FLAG_3']},
         {'flags': []},
         {}
     ]
     for data in data_dicts:
         form = BitFieldTestModelForm(data=data)
         self.failUnless(form.is_valid())
         instance = form.save()
         flags = data['flags'] if 'flags' in data else []
         for k in BitFieldTestModel.flags:
             self.assertEquals(bool(getattr(instance.flags, k)), k in flags)
Example #6
0
 def test_form_new(self):
     data_dicts = [{
         'flags': ['FLAG_0', 'FLAG_1']
     }, {
         'flags': ['FLAG_3']
     }, {
         'flags': []
     }, {}]
     for data in data_dicts:
         form = BitFieldTestModelForm(data=data)
         self.failUnless(form.is_valid())
         instance = form.save()
         flags = data['flags'] if 'flags' in data else []
         for k in BitFieldTestModel.flags:
             self.assertEquals(bool(getattr(instance.flags, k)), k in flags)