예제 #1
0
    def setUp(self):
        self.registry = Registry()

        vals = {
            'a': 'Lorem',
            'b': 'Ipsum',
            'c': datetime.datetime.now(),
            'd': 123
        }
        m1 = M1.objects.create(**vals)
예제 #2
0
파일: tests.py 프로젝트: mivanov/editkit
    def setUp(self):
        self.registry = Registry()

        vals = {'a': 'Lorem', 'b': 'Ipsum',
                'c': datetime.datetime.now(), 'd': 123}
        m1 = Diff_M1.objects.create(**vals)
예제 #3
0
파일: tests.py 프로젝트: mivanov/editkit
class DiffRegistryTest(TestCase):
    def setUp(self):
        self.registry = Registry()

        vals = {'a': 'Lorem', 'b': 'Ipsum',
                'c': datetime.datetime.now(), 'd': 123}
        m1 = Diff_M1.objects.create(**vals)

    def test_can_handle_any_field(self):
        """
        Out of the box, the registry should offer diff utils for any field.
        """
        r = self.registry
        field_types = [db.models.CharField, db.models.TextField,
                       db.models.BooleanField]
        for t in field_types:
            d = r.get_diff_util(t)
            self.assertTrue(issubclass(d, BaseFieldDiff))

    def test_can_handle_any_model(self):
        """
        Out of the box, the registry should offer diff utils for any model.
        """
        r = self.registry
        for t in TEST_MODELS:
            d = r.get_diff_util(t)
            self.assertTrue(issubclass(d, BaseModelDiff))

    def test_fallback_diff(self):
        class AwesomeImageField(db.models.ImageField):
            pass
        """
        If we don't have a diff util for the exact field type, we should fall
        back to the diff util for the base class, until we find a registered
        util.
        """
        self.registry.register(db.models.FileField, FileFieldDiff)
        d = self.registry.get_diff_util(AwesomeImageField)
        self.assertTrue(issubclass(d, FileFieldDiff))

    def test_register_model(self):
        """
        If we register a diff for a model, we should get that and not
        BaseModelDiff.
        """
        self.registry.register(Diff_M1, Diff_M1Diff)
        self.failUnlessEqual(self.registry.get_diff_util(Diff_M1), Diff_M1Diff)

    def test_register_field(self):
        """
        If we register a fielddiff for a model, we should get that and not
        BaseFieldDiff.
        """
        self.registry.register(db.models.CharField, Diff_M1FieldDiff)
        self.failUnlessEqual(self.registry.get_diff_util(db.models.CharField),
                             Diff_M1FieldDiff)

    def test_cannot_diff_something_random(self):
        """
        If we try to diff something that is neither a model nor a field,
        raise exception.
        """
        self.failUnlessRaises(diff.diffutils.DiffUtilNotFound,
                              self.registry.get_diff_util, DiffRegistryTest)
예제 #4
0
class DiffRegistryTest(TestCase):
    def setUp(self):
        self.registry = Registry()

        vals = {
            'a': 'Lorem',
            'b': 'Ipsum',
            'c': datetime.datetime.now(),
            'd': 123
        }
        m1 = M1.objects.create(**vals)

    def test_can_handle_any_field(self):
        """
        Out of the box, the registry should offer diff utils for any field.
        """
        r = self.registry
        field_types = [
            db.models.CharField, db.models.TextField, db.models.BooleanField
        ]
        for t in field_types:
            d = r.get_diff_util(t)
            self.assertTrue(issubclass(d, BaseFieldDiff))

    def test_can_handle_any_model(self):
        """
        Out of the box, the registry should offer diff utils for any model.
        """
        r = self.registry
        for t in TEST_MODELS:
            d = r.get_diff_util(t)
            self.assertTrue(issubclass(d, BaseModelDiff))

    def test_fallback_diff(self):
        class AwesomeImageField(db.models.ImageField):
            pass

        """
        If we don't have a diff util for the exact field type, we should fall
        back to the diff util for the base class, until we find a registered
        util.
        """
        self.registry.register(db.models.FileField, FileFieldDiff)
        d = self.registry.get_diff_util(AwesomeImageField)
        self.assertTrue(issubclass(d, FileFieldDiff))

    def test_register_model(self):
        """
        If we register a diff for a model, we should get that and not
        BaseModelDiff.
        """
        self.registry.register(M1, M1Diff)
        self.failUnlessEqual(self.registry.get_diff_util(M1), M1Diff)

    def test_register_field(self):
        """
        If we register a fielddiff for a model, we should get that and not
        BaseFieldDiff.
        """
        self.registry.register(db.models.CharField, M1FieldDiff)
        self.failUnlessEqual(self.registry.get_diff_util(db.models.CharField),
                             M1FieldDiff)

    def test_cannot_diff_something_random(self):
        """
        If we try to diff something that is neither a model nor a field,
        raise exception.
        """
        self.failUnlessRaises(diff.diffutils.DiffUtilNotFound,
                              self.registry.get_diff_util, DiffRegistryTest)