def test_merge_fragments(self): logic.add(self.av, 'xml->json', {'title': 'foo'}, update=True) logic.add(self.msid, 'frag1', {'body': 'bar'}) logic.add(self.msid, 'frag2', {'foot': 'baz'}) expected = {'title': 'foo', 'body': 'bar', 'foot': 'baz'} self.assertEqual(expected, logic.merge(self.av))
def test_merge_overwrite_fragments(self): logic.add(self.av, 'xml->json', {'title': 'foo'}, update=True) # destroys original article json logic.add(self.msid, 'frag1', {'title': 'bar'}) logic.add(self.msid, 'frag2', {'title': 'baz'}) expected = {'title': 'baz'} self.assertEqual(expected, logic.merge(self.av))
def test_fragment_ordering_explicit(self): logic.add(self.av, 'xml->json', {'title': 'foo'}, update=True) # implicit pos=1 logic.add(self.msid, 'frag1', {'title': 'bar'}, pos=2) # explicit pos=2 logic.add(self.msid, 'frag2', {'title': 'baz'}, pos=1) # explicit pos=1 # order of insertion is preserved + explicit ordering expected_order = ['xml->json', 'frag2', 'frag1'] for given, expected in zip(models.ArticleFragment.objects.all(), expected_order): self.assertEqual(given.type, expected) expected = {'title': 'bar'} self.assertEqual(expected, logic.merge(self.av))