コード例 #1
0
    def test_get_move_unassociated(self):
        cohort = CohortFactory()
        topic = TopicFactory(cohort=cohort)

        self.assertEqual(topic.order, 1)

        r = self.client.get(
            reverse('topic_edit',
                    kwargs={
                        'cohort_pk': cohort.pk,
                        'pk': topic.pk,
                    }) + '?move=down')

        self.assertEqual(r.status_code, 403)
        self.assertEqual(topic.order, 1)

        r = self.client.get(reverse('topic_edit',
                                    kwargs={
                                        'cohort_pk': cohort.pk,
                                        'pk': topic.pk,
                                    }) + '?move=up',
                            follow=True)

        self.assertEqual(r.status_code, 403)

        topic.refresh_from_db()

        self.assertEqual(topic.order, 1)
コード例 #2
0
 def setUp(self):
     super().setUp()
     self.cohort = CohortFactory()
     self.cohort.instructors.add(self.u)
     TopicFactory(cohort=self.cohort)
     TopicFactory(cohort=self.cohort)
     self.topic = self.cohort.get_general_topic()
コード例 #3
0
 def setUp(self):
     super(TopicUpdateViewTest, 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)
コード例 #4
0
 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)
コード例 #5
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)
コード例 #6
0
    def test_post_unassociated(self):
        cohort = CohortFactory()
        topic = TopicFactory(cohort=cohort)
        original_topic_name = topic.name
        r = self.client.post(reverse('topic_edit',
                                     kwargs={
                                         'cohort_pk': cohort.pk,
                                         'pk': topic.pk,
                                     }), {'name': 'New Topic Name'},
                             follow=True)

        self.assertEqual(
            r.status_code, 403,
            "Can't update a topic of a cohort I'm not an instructor of.")

        topic.refresh_from_db()
        self.assertEqual(topic.name, original_topic_name)
コード例 #7
0
class TopicTest(TestCase):
    def setUp(self):
        self.x = TopicFactory()

    def test_is_valid_from_factory(self):
        self.x.full_clean()

    def test_can_delete_topics(self):
        # Verify that Topic.delete() still works
        cohort = CohortFactory()
        t = Topic.objects.create(name='Topic', order=2, cohort=cohort)
        t.delete()

    def test_can_delete_topics_qs(self):
        # Verify that the QuerySet delete method still works
        cohort = CohortFactory()
        Topic.objects.create(name='topic 1', order=2, cohort=cohort)
        Topic.objects.create(name='Topic 2', order=3, cohort=cohort)
        Topic.objects.all().delete()
コード例 #8
0
    def test_get_unassociated(self):
        cohort = CohortFactory()
        topic = TopicFactory(cohort=cohort)
        r = self.client.get(
            reverse('topic_delete',
                    kwargs={
                        'cohort_pk': cohort.pk,
                        'pk': topic.pk,
                    }))

        self.assertEqual(
            r.status_code, 403,
            "Can't delete a topic of a cohort I'm not an instructor of.")
コード例 #9
0
 def setUp(self):
     super(CohortDetailStudentViewTest, self).setUp()
     self.cohort = CohortFactory()
     self.t1 = TopicFactory(name='Topic A', cohort=self.cohort)
     self.t2 = TopicFactory(name='Topic B', cohort=self.cohort)
     self.t3 = TopicFactory(name='Empty Topic', cohort=self.cohort)
     self.t4 = TopicFactory(name='Topic with unpublished graph',
                            cohort=self.cohort)
     GraphFactory(title='Graph 1',
                  is_published=True,
                  featured=True,
                  topic=self.t1)
     GraphFactory(title='Demand-Supply',
                  is_published=True,
                  topic=self.t1,
                  featured=True)
     GraphFactory(title='abc', is_published=True, topic=self.t2)
     GraphFactory(title='Submittable graph',
                  needs_submit=True,
                  is_published=True,
                  topic=self.t1)
     GraphFactory(title='Draft graph', is_published=False, topic=self.t2)
     GraphFactory(title='Another draft', is_published=False, topic=self.t4)
コード例 #10
0
    def test_create_with_lines(self):
        topic = TopicFactory()
        response = self.client.post(
            '/api/graphs/',
            {
                'title': 'Graph with lines',
                'instructions': 'Graph instructions',
                'instructor_notes': 'notes',
                'author': self.u.pk,
                'graph_type': 0,
                'topic': topic.pk,
                'line_1_slope': 0,
                'line_2_slope': 0,
                'line_1_offset_y': 0.5,
                'line_2_offset_y': 0.7,
                'lines': [
                    {
                        'number': 1,
                        'transformations': []
                    },
                    {
                        'number': 2,
                    },
                ]
                # DRF needs format='json' here, because nesting doesn't
                # work with the default renderer used in testing:
                # MultiPartRenderer
                # http://www.django-rest-framework.org/api-guide/renderers/#multipartrenderer
            },
            format='json')

        self.assertEqual(response.status_code, 201)
        self.assertEqual(Graph.objects.count(), 1)
        self.assertEqual(JXGLine.objects.count(), 2)
        self.assertEqual(JXGLineTransformation.objects.count(), 0)

        g = Graph.objects.first()
        self.assertEqual(g.title, 'Graph with lines')
        self.assertEqual(g.instructions, 'Graph instructions')
        self.assertEqual(g.instructor_notes, 'notes')
        self.assertEqual(g.author, self.u)

        self.assertEqual(g.lines.count(), 2)
        line1 = g.lines.first()
        line2 = g.lines.last()
        self.assertEqual(line1.transformations.count(), 0)
        self.assertEqual(line2.transformations.count(), 0)
コード例 #11
0
    def test_create(self):
        topic = TopicFactory()
        response = self.client.post(
            '/api/graphs/', {
                'title': 'Graph title',
                'instructions': 'Graph instructions',
                'instructor_notes': 'notes',
                'author': self.u.pk,
                'graph_type': 0,
                'topic': topic.pk,
                'line_1_slope': 0,
                'line_2_slope': 0,
                'line_1_offset_y': 0.5,
                'line_2_offset_y': 0.7,
            })
        self.assertEqual(response.status_code, 201)
        self.assertEqual(Graph.objects.count(), 1)

        g = Graph.objects.first()
        self.assertEqual(g.title, 'Graph title')
        self.assertEqual(g.instructions, 'Graph instructions')
        self.assertEqual(g.instructor_notes, 'notes')
        self.assertEqual(g.author, self.u)
        self.assertEqual(g.lines.count(), 0)
コード例 #12
0
    def test_create_with_lines_and_transformations_invalid(self):
        topic = TopicFactory()
        response = self.client.post(
            '/api/graphs/',
            {
                'title':
                'Graph with lines',
                'instructions':
                'Graph instructions',
                'instructor_notes':
                'notes',
                'author':
                self.u.pk,
                'topic':
                topic.pk,
                'graph_type':
                0,
                'line_1_slope':
                0,
                'line_2_slope':
                0,
                'line_1_offset_y':
                0.5,
                'line_2_offset_y':
                0.7,
                'lines': [
                    {
                        'number':
                        1,
                        'transformations': [
                            {
                                # Assert that this can be broken with one
                                # type error.
                                'z2': 'a',
                                'x2': 2,
                                'y2': 3,
                            },
                            {
                                'z3': -1,
                                'x3': -2,
                                'y3': -3,
                            }
                        ]
                    },
                    {
                        'number':
                        2,
                        'transformations': [{
                            'z2': 4,
                            'x2': 5,
                            'y2': 6.0006,
                        }, {
                            'z3': -4,
                            'x3': -5,
                            'y3': -6.0006,
                        }]
                    },
                ]
                # DRF needs format='json' here, because nesting doesn't
                # work with the default renderer used in testing:
                # MultiPartRenderer
                # http://www.django-rest-framework.org/api-guide/renderers/#multipartrenderer
            },
            format='json')

        self.assertEqual(response.status_code, 400)
        self.assertEqual(Graph.objects.count(), 0)
        self.assertEqual(JXGLine.objects.count(), 0)
        self.assertEqual(JXGLineTransformation.objects.count(), 0)
コード例 #13
0
class TopicUpdateViewTest(LoggedInTestInstructorMixin, TestCase):
    def setUp(self):
        super(TopicUpdateViewTest, 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)

    def test_get(self):
        r = self.client.get(
            reverse('topic_edit',
                    kwargs={
                        'cohort_pk': self.cohort.pk,
                        'pk': self.topic.pk,
                    }))

        self.assertEqual(r.status_code, 200)
        self.assertContains(r, 'Save')
        self.assertContains(r, 'Cancel')

    def test_post(self):
        r = self.client.post(reverse('topic_edit',
                                     kwargs={
                                         'cohort_pk': self.cohort.pk,
                                         'pk': self.topic.pk,
                                     }), {'name': 'New Topic Name'},
                             follow=True)

        self.assertEqual(r.status_code, 200)
        self.assertContains(r, 'Manage Topics: {}'.format(self.cohort.title))
        self.assertContains(r, 'New Topic Name')
        self.topic.refresh_from_db()
        self.assertEqual(self.topic.name, 'New Topic Name')

    def test_post_unassociated(self):
        cohort = CohortFactory()
        topic = TopicFactory(cohort=cohort)
        original_topic_name = topic.name
        r = self.client.post(reverse('topic_edit',
                                     kwargs={
                                         'cohort_pk': cohort.pk,
                                         'pk': topic.pk,
                                     }), {'name': 'New Topic Name'},
                             follow=True)

        self.assertEqual(
            r.status_code, 403,
            "Can't update a topic of a cohort I'm not an instructor of.")

        topic.refresh_from_db()
        self.assertEqual(topic.name, original_topic_name)

    def test_get_move(self):
        self.assertEqual(self.topic.order, 2)

        r = self.client.get(
            reverse('topic_edit',
                    kwargs={
                        'cohort_pk': self.cohort.pk,
                        'pk': self.topic.pk,
                    }) + '?move=down')

        self.assertEqual(r.status_code, 302)
        self.assertEqual(self.topic.order, 2)

        r = self.client.get(reverse('topic_edit',
                                    kwargs={
                                        'cohort_pk': self.cohort.pk,
                                        'pk': self.topic.pk,
                                    }) + '?move=up',
                            follow=True)

        self.assertEqual(r.status_code, 200)
        self.assertContains(r, 'Manage Topics')

        self.topic.refresh_from_db()

        # TODO: why isn't the new order 3? or 1?
        self.assertEqual(self.topic.order, 2)

    def test_get_move_unassociated(self):
        cohort = CohortFactory()
        topic = TopicFactory(cohort=cohort)

        self.assertEqual(topic.order, 1)

        r = self.client.get(
            reverse('topic_edit',
                    kwargs={
                        'cohort_pk': cohort.pk,
                        'pk': topic.pk,
                    }) + '?move=down')

        self.assertEqual(r.status_code, 403)
        self.assertEqual(topic.order, 1)

        r = self.client.get(reverse('topic_edit',
                                    kwargs={
                                        'cohort_pk': cohort.pk,
                                        'pk': topic.pk,
                                    }) + '?move=up',
                            follow=True)

        self.assertEqual(r.status_code, 403)

        topic.refresh_from_db()

        self.assertEqual(topic.order, 1)
コード例 #14
0
 def setUp(self):
     super(CohortPasswordGraphDetailViewTest, self).setUp()
     cohort = CohortFactory(password='******')
     topic = TopicFactory(cohort=cohort)
     self.g = GraphFactory(topic=topic)
コード例 #15
0
 def setUp(self):
     super(GraphOrderTest, self).setUp()
     self.topic = TopicFactory()
コード例 #16
0
 def setUp(self):
     self.x = TopicFactory()