def test_get_move_unassociated(self): cohort = CohortFactory() topic = TopicFactory(cohort=cohort) graph = GraphFactory(topic=topic, featured=True) self.assertEqual(graph.order, 0) r = self.client.get( reverse('cohort_graph_edit', kwargs={ 'cohort_pk': cohort.pk, 'pk': graph.pk, }) + '?move=down') self.assertEqual(r.status_code, 403) self.assertEqual(graph.order, 0) r = self.client.get(reverse('cohort_graph_edit', kwargs={ 'cohort_pk': cohort.pk, 'pk': graph.pk, }) + '?move=up', follow=True) self.assertEqual(r.status_code, 403) graph.refresh_from_db() self.assertEqual(graph.order, 0)
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_post(self): self.assertEqual( Topic.objects.filter(cohort=self.cohort).count(), 2, 'Topics are: General, and a custom topic.') cohort = self.topic.cohort graph = GraphFactory(topic=self.topic) self.assertEqual(graph.topic, self.topic) r = self.client.post(reverse('topic_delete', kwargs={ 'cohort_pk': cohort.pk, 'pk': self.topic.pk, }), follow=True) self.assertEqual(r.status_code, 200) self.assertContains(r, 'deleted') with self.assertRaises(Topic.DoesNotExist): Topic.objects.get(pk=self.topic.pk) graph.refresh_from_db() self.assertEqual(graph.topic, cohort.get_general_topic())
class FeaturedGraphUpdateViewTest(LoggedInTestInstructorMixin, TestCase): def setUp(self): super(FeaturedGraphUpdateViewTest, self).setUp() self.cohort = CohortFactory() self.cohort.instructors.add(self.u) TopicFactory(cohort=self.cohort) self.topic = TopicFactory(cohort=self.cohort) TopicFactory(cohort=self.cohort) TopicFactory(cohort=self.cohort) self.graph = GraphFactory(topic=self.topic, featured=True) GraphFactory(topic=self.topic, featured=True) GraphFactory(topic=self.topic, featured=True) GraphFactory(topic=self.topic, featured=False) GraphFactory(topic=self.topic, featured=False) def test_get(self): r = self.client.get( reverse('cohort_graph_edit', kwargs={ 'cohort_pk': self.cohort.pk, 'pk': self.topic.pk, })) self.assertEqual(r.status_code, 403) def test_get_move(self): self.assertEqual(self.graph.order, 0) r = self.client.get( reverse('cohort_graph_edit', kwargs={ 'cohort_pk': self.cohort.pk, 'pk': self.graph.pk, }) + '?move=down') self.assertEqual(r.status_code, 302) self.assertEqual(self.graph.order, 0) r = self.client.get(reverse('cohort_graph_edit', kwargs={ 'cohort_pk': self.cohort.pk, 'pk': self.graph.pk, }) + '?move=up', follow=True) self.assertEqual(r.status_code, 200) self.assertContains(r, 'Manage Featured Graphs') self.graph.refresh_from_db() # TODO: self.assertEqual(self.graph.order, 0) def test_get_move_unassociated(self): cohort = CohortFactory() topic = TopicFactory(cohort=cohort) graph = GraphFactory(topic=topic, featured=True) self.assertEqual(graph.order, 0) r = self.client.get( reverse('cohort_graph_edit', kwargs={ 'cohort_pk': cohort.pk, 'pk': graph.pk, }) + '?move=down') self.assertEqual(r.status_code, 403) self.assertEqual(graph.order, 0) r = self.client.get(reverse('cohort_graph_edit', kwargs={ 'cohort_pk': cohort.pk, 'pk': graph.pk, }) + '?move=up', follow=True) self.assertEqual(r.status_code, 403) graph.refresh_from_db() self.assertEqual(graph.order, 0)
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)