def test_clone(self): original = GraphFactory(title='cloned graph') cloned_pk = original.clone().pk cloned = Graph.objects.get(pk=cloned_pk) self.assertNotEqual(original.pk, cloned.pk) self.assertEqual(original.title, 'cloned graph') self.assertEqual(cloned.title, 'cloned graph') cloned.title = 'new title' original.save() cloned.save() original.refresh_from_db() cloned.refresh_from_db() original.full_clean() cloned.full_clean() self.assertNotEqual(original.pk, cloned.pk) self.assertNotEqual( cloned.assessment.pk, original.assessment.pk, 'The clone operation clones the assessment as well.') self.assertIsInstance(cloned.assessment, Assessment) self.assertEqual(original.title, 'cloned graph') self.assertEqual(cloned.title, 'new title') self.assertEqual(original.graph_type, cloned.graph_type) self.assertEqual(original.author, cloned.author) self.assertEqual(original.topic, cloned.topic) self.assertEqual(original.a1, cloned.a1) self.assertEqual(original.a1_name, cloned.a1_name)
def test_save_ordering(self): # Assert that newly created items are placed in the # expected order g1 = GraphFactory(title="g1", featured=True, topic=self.topic) g2 = GraphFactory(title="g2", featured=True, topic=self.topic) self.assertEqual(g1.order, 0) self.assertEqual(g2.order, 1) # Assert that an existing item is ordered correctly # when featured is toggled g3 = GraphFactory(title="g3", featured=False, topic=self.topic) g4 = GraphFactory(title="g4", featured=False, topic=self.topic) self.assertEqual(g3.order, 0) self.assertEqual(g4.order, 1) # Verify that the other items are still correctly ordered self.assertEqual(g1.order, 0) self.assertEqual(g2.order, 1) g3.featured = True g3.save() g1.refresh_from_db() g2.refresh_from_db() g3.refresh_from_db() g4.refresh_from_db() self.assertEqual(g1.order, 0) self.assertEqual(g2.order, 1) self.assertEqual(g3.order, 0) # Check that when save is called on a graph whose featured val # has been toggled, that ordering is condensed self.assertEqual(Graph.objects.get(title="g4").order, 1) g2.featured = False g2.save() g1.refresh_from_db() g2.refresh_from_db() g3.refresh_from_db() g4.refresh_from_db() # Check order of featured = True self.assertEqual(g1.order, 0) self.assertEqual(g3.order, 0) # Check order of featured = False self.assertEqual(g4.order, 1) self.assertEqual(g2.order, 1)