class DMDiffTest(TestCase):
    def setUp(self):
        self.dmd = DMDiffs()

    def test_get_404(self):
        self.assertIsNone(self.dmd.get('lablab', 'oldold', 'newnew'))

    def test_get_success(self):
        Diff(label='lablab', old_version='oldold', new_version='newnew',
             diff={"some": "body"}).save()

        self.assertEqual({"some": 'body'},
                         self.dmd.get('lablab', 'oldold', 'newnew'))

    def test_put(self):
        """We can insert and replace a diff"""
        self.dmd.put('lablab', 'oldold', 'newnew', {"some": "structure"})

        expected = {"label": "lablab", "old_version": "oldold",
                    "new_version": "newnew", "diff": {"some": "structure"}}
        fields = expected.keys()
        six.assertCountEqual(self, Diff.objects.all().values(*fields),
                             [expected])

        self.dmd.put('lablab', 'oldold', 'newnew', {"other": "structure"})
        expected['diff'] = {'other': 'structure'}
        six.assertCountEqual(self, Diff.objects.all().values(*fields),
                             [expected])
    def test_put(self):
        dmd = DMDiffs()
        dmd.put('lablab', 'oldold', 'newnew', {"some": "structure"})

        diffs = Diff.objects.all()
        self.assertEqual(1, len(diffs))

        self.assertEqual('lablab', diffs[0].label)
        self.assertEqual('oldold', diffs[0].old_version)
        self.assertEqual('newnew', diffs[0].new_version)
        self.assertEqual({'some': 'structure'}, diffs[0].diff)
Exemple #3
0
class SplitterDiffs(object):
    """Implementation of Django+Elastic Search as regulations backend"""
    def __init__(self):
        self.dm = DMDiffs()
        self.es = ESDiffs()

        self.get = self.dm.get

    def put(self, label, old_version, new_version, diff):
        """Write to both"""
        self.dm.put(label, old_version, new_version, diff)
        self.es.put(label, old_version, new_version, diff)
    def test_put_overwrite(self):
        dmd = DMDiffs()
        dmd.put('lablab', 'oldold', 'newnew', {"some": "structure"})

        diffs = Diff.objects.all()
        self.assertEqual(1, len(diffs))
        self.assertEqual({'some': 'structure'}, diffs[0].diff)

        dmd.put('lablab', 'oldold', 'newnew', {"other": "structure"})
        diffs = Diff.objects.all()
        self.assertEqual(1, len(diffs))
        self.assertEqual({'other': 'structure'}, diffs[0].diff)
class DMDiffTest(TestCase):
    def setUp(self):
        self.dmd = DMDiffs()

    def test_get_404(self):
        self.assertIsNone(self.dmd.get('lablab', 'oldold', 'newnew'))

    def test_get_success(self):
        Diff(label='lablab',
             old_version='oldold',
             new_version='newnew',
             diff={
                 "some": "body"
             }).save()

        self.assertEqual({"some": 'body'},
                         self.dmd.get('lablab', 'oldold', 'newnew'))

    def test_put(self):
        """We can insert and replace a diff"""
        self.dmd.put('lablab', 'oldold', 'newnew', {"some": "structure"})

        expected = {
            "label": "lablab",
            "old_version": "oldold",
            "new_version": "newnew",
            "diff": {
                "some": "structure"
            }
        }
        fields = expected.keys()
        six.assertCountEqual(self,
                             Diff.objects.all().values(*fields), [expected])

        self.dmd.put('lablab', 'oldold', 'newnew', {"other": "structure"})
        expected['diff'] = {'other': 'structure'}
        six.assertCountEqual(self,
                             Diff.objects.all().values(*fields), [expected])