コード例 #1
0
 def test_get(self):
     GraphFactory(author=self.u)
     GraphFactory(author=self.u)
     GraphFactory(author=self.u)
     response = self.client.get('/api/graphs/')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 3)
コード例 #2
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)
コード例 #3
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)
コード例 #4
0
 def setUp(self):
     super(MyLTILandingPageTest, self).setUp()
     self.factory = RequestFactory()
     g1 = GraphFactory(title='Graph 1')
     g2 = GraphFactory(title='Demand-Supply')
     g3 = GraphFactory(title='abc')
     self.g = GraphFactory(title='Submittable graph', needs_submit=True)
     SubmissionFactory(graph=g1)
     SubmissionFactory(graph=g2)
     SubmissionFactory(graph=g2)
     SubmissionFactory(graph=g3)
     SubmissionFactory(graph=self.g)
     self.submission = SubmissionFactory(graph=self.g, user=self.u)
コード例 #5
0
    def test_get_detail(self):
        GraphFactory(author=self.u)

        g = GraphFactory(author=self.u)
        line = JXGLineFactory(graph=g)
        JXGLineFactory(graph=g, number=2)
        JXGLineTransformationFactory(line=line)
        JXGLineTransformationFactory(line=line)

        GraphFactory(author=self.u)

        response = self.client.get('/api/graphs/{}/'.format(g.pk))
        self.assertEqual(response.status_code, 200)

        data = response.data
        self.assertEqual(len(data['lines']), 2)
コード例 #6
0
    def test_delete(self):
        g = GraphFactory(author=self.u)

        response = self.client.delete('/api/graphs/{}/'.format(g.pk))

        self.assertEqual(response.status_code, 204)
        self.assertEqual(Graph.objects.count(), 0)
コード例 #7
0
    def test_clone(self):
        g = GraphFactory(topic=self.topic)

        self.assertEqual(Graph.objects.count(), 1)

        r = self.client.get(
            reverse('cohort_graph_clone',
                    kwargs={
                        'cohort_pk': self.cohort.pk,
                        'pk': g.pk
                    }))
        self.assertEqual(r.status_code, 200)
        self.assertContains(r, 'Cloning <strong>{}</strong>'.format(g.title))

        # Clone it to this cohort.
        r = self.client.post(reverse('cohort_graph_clone',
                                     kwargs={
                                         'cohort_pk': self.cohort.pk,
                                         'pk': g.pk,
                                     }), {'course': self.cohort.pk},
                             follow=True)
        self.assertEqual(r.status_code, 200)
        self.assertContains(r, g.title)
        self.assertContains(r, 'copied to')
        self.assertContains(r, self.cohort.title)

        new_graph = Graph.objects.filter(topic=self.topic,
                                         title='{} (clone)'.format(
                                             g.title)).first()

        self.assertEqual(new_graph.title, g.title + ' (clone)')
        self.assertEqual(new_graph.topic, self.topic)
        self.assertEqual(new_graph.author, self.u)

        self.assertEqual(Graph.objects.count(), 2)

        # Clone it to a new cohort.
        new_cohort = CohortFactory()
        new_cohort.instructors.add(self.u)
        new_topic = new_cohort.get_general_topic()

        r = self.client.post(reverse('cohort_graph_clone',
                                     kwargs={
                                         'cohort_pk': new_cohort.pk,
                                         'pk': g.pk,
                                     }), {'course': new_cohort.pk},
                             follow=True)
        self.assertEqual(r.status_code, 200)
        self.assertContains(r, g.title)
        self.assertContains(r, 'copied to')
        self.assertContains(r, new_cohort.title)

        self.assertEqual(Graph.objects.count(), 3)

        new_graph = Graph.objects.filter(topic=new_topic,
                                         title=g.title).first()

        self.assertEqual(new_graph.title, g.title)
        self.assertEqual(new_graph.topic, new_topic)
        self.assertEqual(new_graph.author, self.u)
コード例 #8
0
    def test_delete(self):
        g = GraphFactory()

        response = self.client.delete('/api/graphs/{}/'.format(g.pk))

        self.assertNotEqual(response.status_code, 200,
                            'Anonymous users shouldn\'t delete graphs.')
        self.assertEqual(Graph.objects.count(), 1)
コード例 #9
0
    def test_update_with_lines(self):
        g = GraphFactory(author=self.u)
        line = JXGLineFactory(graph=g)
        JXGLineTransformationFactory(line=line)

        response = self.client.put('/api/graphs/{}/'.format(g.pk), {
            'title':
            'New title',
            'author':
            self.u.pk,
            'line_1_slope':
            1,
            'line_2_slope':
            -1,
            'lines': [
                {
                    'number':
                    1,
                    'transformations': [{
                        'z2': 1,
                        '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,
                    }]
                },
            ]
        },
                                   format='json')
        self.assertEqual(response.status_code, 200)

        self.assertEqual(JXGLine.objects.count(), 2)
        self.assertEqual(JXGLineTransformation.objects.count(), 4)

        self.assertEqual(response.data.get('title'), 'New title')
        self.assertEqual(response.data.get('author'), self.u.pk)
        self.assertEqual(Decimal(response.data.get('line_1_slope')),
                         Decimal(1))
        self.assertEqual(Decimal(response.data.get('line_2_slope')),
                         Decimal(-1))
コード例 #10
0
    def test_get(self):
        g = GraphFactory()
        r = self.client.get(reverse('graph_embed', kwargs={'pk': g.pk}))
        self.assertEqual(r.status_code, 302)

        r = self.client.get(
            reverse('cohort_graph_embed',
                    kwargs={
                        'cohort_pk': g.topic.cohort.pk,
                        'pk': g.pk,
                    }))
        self.assertEqual(r.status_code, 302)
コード例 #11
0
    def test_get(self):
        g = GraphFactory()
        r = self.client.get(reverse('graph_embed_public', kwargs={'pk': g.pk}))
        self.assertEqual(r.status_code, 200)
        self.assertContains(r, g.title)

        r = self.client.get(
            reverse('cohort_graph_embed_public',
                    kwargs={
                        'cohort_pk': g.topic.cohort.pk,
                        'pk': g.pk,
                    }))
        self.assertEqual(r.status_code, 200)
        self.assertContains(r, g.title)
コード例 #12
0
    def test_clone(self):
        GraphFactory(topic=self.x.get_general_topic())
        GraphFactory(topic=self.x.get_general_topic())

        self.assertEqual(Graph.objects.count(), 2)
        self.assertEqual(Topic.objects.count(), 2)
        self.assertEqual(Cohort.objects.count(), 2)
        self.assertEqual(self.x.graph_count(), 2)
        cloned = self.x.clone()
        self.assertNotEqual(cloned.pk, self.x.pk)
        self.assertEqual(cloned.graph_count(), 2)
        self.assertEqual(Graph.objects.count(), 4)
        self.assertEqual(Topic.objects.count(), 3)
        self.assertEqual(Cohort.objects.count(), 3)

        # Test that cloning the sample course works too.
        sample = CohortFactory(is_sample=True)
        cloned = sample.clone()
        self.assertNotEqual(cloned.pk, sample.pk)
        self.assertFalse(cloned.is_sample)
        self.assertEqual(cloned.graph_count(), 0)
        self.assertEqual(Graph.objects.count(), 4)
        self.assertEqual(Topic.objects.count(), 5)
        self.assertEqual(Cohort.objects.count(), 5)
コード例 #13
0
    def test_update(self):
        u = UserFactory()
        g = GraphFactory(author=u)
        title = g.title

        response = self.client.put(
            '/api/graphs/{}/'.format(g.pk), {
                'title': 'New title',
                'author': u.pk,
                'line_1_slope': 1,
                'line_2_slope': -1,
            })
        self.assertEqual(response.status_code, 403,
                         'Anonymous users shouldn\'t update graphs.')
        self.assertEqual(g.title, title)
コード例 #14
0
    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())
コード例 #15
0
 def test_update(self):
     g = GraphFactory(author=self.u)
     response = self.client.put(
         '/api/graphs/{}/'.format(g.pk), {
             'title': 'New title',
             'author': self.u.pk,
             'line_1_slope': 1,
             'line_2_slope': -1,
         })
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data.get('title'), 'New title')
     self.assertEqual(response.data.get('author'), self.u.pk)
     self.assertEqual(Decimal(response.data.get('line_1_slope')),
                      Decimal(1))
     self.assertEqual(Decimal(response.data.get('line_2_slope')),
                      Decimal(-1))
コード例 #16
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)
コード例 #17
0
    def test_get(self):
        g = GraphFactory()

        self.assertEqual(Graph.objects.count(), 1)

        r = self.client.get(
            reverse('cohort_graph_clone',
                    kwargs={
                        'cohort_pk': g.topic.cohort.pk,
                        'pk': g.pk
                    }))
        self.assertEqual(r.status_code, 403)

        r = self.client.post(
            reverse('cohort_graph_clone',
                    kwargs={
                        'cohort_pk': g.topic.cohort.pk,
                        'pk': g.pk,
                    }))
        self.assertEqual(r.status_code, 403)

        self.assertEqual(Graph.objects.count(), 1)
コード例 #18
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)
コード例 #19
0
    def test_update_with_lines_invalid_nested(self):
        g = GraphFactory(author=self.u)
        line = JXGLineFactory(graph=g, number=5)
        JXGLineTransformationFactory(line=line)

        response = self.client.put('/api/graphs/{}/'.format(g.pk), {
            'title':
            'New title',
            'author':
            self.u.pk,
            'line_1_slope':
            1,
            'line_2_slope':
            -1,
            'abc':
            'abc',
            'lines': [
                {
                    'abc':
                    7,
                    'whatever': [{
                        'uuu': 1,
                        'x': 2,
                        'y': 3,
                    }, {
                        'z': -1,
                        'x': -2,
                        'y': -3,
                    }]
                },
                {
                    'number':
                    2,
                    'transformations': [{
                        'z': 4,
                        'x': 5,
                        'y': 6.0006,
                    }, {
                        'z': -4,
                        'x': -5,
                        'y': -6.0006,
                    }]
                },
            ]
        },
                                   format='json')
        self.assertEqual(response.status_code, 200)

        self.assertEqual(JXGLine.objects.count(), 2)

        self.assertFalse(JXGLine.objects.filter(number=5).exists())
        self.assertFalse(JXGLine.objects.filter(number=7).exists())
        self.assertTrue(JXGLine.objects.filter(number=1).exists())
        self.assertTrue(JXGLine.objects.filter(number=2).exists())

        self.assertEqual(JXGLineTransformation.objects.count(), 2)

        self.assertEqual(response.data.get('title'), 'New title')
        self.assertEqual(response.data.get('author'), self.u.pk)
        self.assertEqual(Decimal(response.data.get('line_1_slope')),
                         Decimal(1))
        self.assertEqual(Decimal(response.data.get('line_2_slope')),
                         Decimal(-1))
コード例 #20
0
 def test_get(self):
     GraphFactory()
     GraphFactory()
     GraphFactory()
     response = self.client.get('/api/graphs/')
     self.assertEqual(response.status_code, 200)
コード例 #21
0
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)
コード例 #22
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)
コード例 #23
0
 def setUp(self):
     super(SubmissionSetTest, self).setUp()
     self.g = GraphFactory()
     self.g2 = GraphFactory()
コード例 #24
0
 def setUp(self):
     self.x = GraphFactory()
コード例 #25
0
 def setUp(self):
     super(CohortPasswordGraphDetailViewTest, self).setUp()
     cohort = CohortFactory(password='******')
     topic = TopicFactory(cohort=cohort)
     self.g = GraphFactory(topic=topic)