add Pabitra's citation test
@@ -129,3 +129,46 @@ class TestGetCitation(MockIRODSTestCaseMixin, TestCase):
name = "Smith Tanner, John Morley"
parsed_name = self.res.parse_citation_name(name)
self.assertEqual(parsed_name, 'J. M. Smith Tanner, ')
+
+ def test_author_ordering(self):
+ # add 4 creators element (so in total we will have 5 creators)
+ resource.create_metadata_element(self.res.short_id, 'creator', name='John Smith')
+ resource.create_metadata_element(self.res.short_id, 'creator', name='Lisa McWill')
+ resource.create_metadata_element(self.res.short_id, 'creator', name='Kelly Anderson')
+ resource.create_metadata_element(self.res.short_id, 'creator', name='Mark Miller')
+ for index, creator in enumerate(self.res.metadata.creators.all(), start=1):
+ self.assertEqual(index, creator.order)
+
+ # update the order of a creator
+ john = self.res.metadata.creators.filter(name="John Smith").first()
+ self.assertEqual(john.order, 2)
+ Creator.update(element_id=john.id, order=4)
+ john = self.res.metadata.creators.filter(name="John Smith").first()
+ self.assertEqual(john.order, 4)
+ first_author = self.res.metadata.creators.filter(order=1).first()
+ first_author.order = 2
+ first_author.save()
+ for index, creator in enumerate(self.res.metadata.creators.all(), start=1):
+ print(f"index:{index}, order:{creator.order}, {creator.name}")
+
+ first_author.order = 1
+ first_author.save()
+ print("-" * 30)
+ for index, creator in enumerate(self.res.metadata.creators.all(), start=1):
+ print(f"index:{index}, order:{creator.order}, {creator.name}")
+
+ citation_original = self.res.get_citation()
+ # fix the ordering
+ for index, creator in enumerate(self.res.metadata.creators.all(), start=1):
+ if index != creator.order:
+ creator.order = index
+ creator.save()
+
+ print("-" * 30)
+ for index, creator in enumerate(self.res.metadata.creators.all(), start=1):
+ print(f"index:{index}, order:{creator.order}, {creator.name}")
+
+ self.assertEqual(self.res.get_citation(), citation_original)
+
+ for index, creator in enumerate(self.res.metadata.creators.all(), start=1):
+ self.assertEqual(index, creator.order)
\ No newline at end of file
