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)
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)
def test_diff_get_success(): Diff.objects.create(label='lablab', old_version='oldold', new_version='newnew', diff={"some": "body"}) assert DMDiffs().get('lablab', 'oldold', 'newnew') == {'some': 'body'}
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_diff_insert_delete(): """We can insert and replace a diff""" dmd = DMDiffs() dmd.insert('lablab', 'oldold', 'newnew', {"some": "structure"}) expected = {"label": "lablab", "old_version": "oldold", "new_version": "newnew", "diff": {"some": "structure"}} assert list(Diff.objects.all().values(*expected.keys())) == [expected] dmd.delete('lablab', 'oldold', 'newnew') dmd.insert('lablab', 'oldold', 'newnew', {"other": "structure"}) expected['diff'] = {'other': 'structure'} assert list(Diff.objects.all().values(*expected.keys())) == [expected]
def test_diff_insert_delete(): """We can insert and replace a diff""" dmd = DMDiffs() dmd.insert('lablab', 'oldold', 'newnew', {"some": "structure"}) expected = { "label": "lablab", "old_version": "oldold", "new_version": "newnew", "diff": { "some": "structure" } } assert list(Diff.objects.all().values(*expected.keys())) == [expected] dmd.delete('lablab', 'oldold', 'newnew') dmd.insert('lablab', 'oldold', 'newnew', {"other": "structure"}) expected['diff'] = {'other': 'structure'} assert list(Diff.objects.all().values(*expected.keys())) == [expected]
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_insert_delete(self): """We can insert and replace a diff""" self.dmd.insert('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.delete('lablab', 'oldold', 'newnew') self.dmd.insert('lablab', 'oldold', 'newnew', {"other": "structure"}) expected['diff'] = {'other': 'structure'} six.assertCountEqual(self, Diff.objects.all().values(*fields), [expected])
def setUp(self): self.dmd = DMDiffs()
def __init__(self): self.dm = DMDiffs() self.es = ESDiffs() self.get = self.dm.get
def test_diff_get_404(): assert DMDiffs().get('lablab', 'oldold', 'newnew') is None