Ejemplo n.º 1
0
    def setUp(self):
        super(UpdateCommentTests, self).setUp()

        self.user = UserFactory.create()
        self.comment = CommentFactory.create(user=self.user)
        self.path = reverse('publisher_comments:api:comments', kwargs={'pk': self.comment.id})
        self.data = {'comment': 'updated comment'}
Ejemplo n.º 2
0
    def setUp(self):
        super(UpdateCommentTests, self).setUp()

        self.user = UserFactory.create()
        self.comment = CommentFactory.create(user=self.user)
        self.path = reverse('publisher_comments:api:comments', kwargs={'pk': self.comment.id})
        self.data = {'comment': 'updated comment'}
Ejemplo n.º 3
0
 def create_comment(self,
                    content_object,
                    comment_type=CommentTypeChoices.Default):
     """ DRY method to create the comment for a given content type."""
     return CommentFactory(content_object=content_object,
                           user=self.user,
                           site=self.site,
                           comment_type=comment_type)
Ejemplo n.º 4
0
 def setUp(self):
     super(AdminTests, self).setUp()
     self.user = UserFactory(is_staff=True, is_superuser=True)
     self.client.login(username=self.user.username, password=USER_PASSWORD)
     self.course = factories.CourseFactory()
     self.comment = CommentFactory(content_object=self.course,
                                   user=self.user,
                                   site=self.site)
Ejemplo n.º 5
0
    def test_data(self):
        """ Verify that CommentsSerializer serialize the comment object. """

        comment = CommentFactory.create(comment='test comment')
        serializer = CommentSerializer(comment)
        expected = {'comment': 'test comment',
                    'modified': comment.modified.strftime("%Y-%m-%dT%H:%M:%S.%fZ")}

        self.assertDictEqual(serializer.data, expected)
Ejemplo n.º 6
0
    def test_data(self):
        """ Verify that CommentsSerializer serialize the comment object. """

        comment = CommentFactory.create(comment='test comment')
        serializer = CommentSerializer(comment)
        expected = {
            'comment': 'test comment',
            'modified': comment.modified.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
        }

        self.assertDictEqual(serializer.data, expected)
Ejemplo n.º 7
0
 def setUp(self):
     super(IsOwnerTests, self).setUp()
     self.permissions_class = IsOwner()
     self.user = UserFactory.create()
     self.comment = CommentFactory.create(user=self.user, comment='test comment')
Ejemplo n.º 8
0
    def test_handle_with_comments(self, mock_salesforce):
        config = MigrateCommentsToSalesforceFactory(partner=self.partner)
        config.orgs.add(self.org_1)
        SalesforceConfigurationFactory(partner=self.partner)
        course_comment = CommentFactory(
            user=self.user_1,
            content_type_id=ContentType.objects.get_for_model(PublisherCourse),
            object_pk=self.publisher_course_1.id,
        )
        course_comment.content_type_id = ContentType.objects.get_for_model(PublisherCourse)
        course_comment.object_pk = self.publisher_course_1.id
        course_comment.save()

        course_run_comment = CommentFactory(
            user=self.user_1,
            content_type_id=ContentType.objects.get_for_model(PublisherCourseRun),
            object_pk=self.publisher_course_run_1.id,
        )
        course_run_comment.content_type_id = ContentType.objects.get_for_model(PublisherCourseRun)
        course_run_comment.object_pk = self.publisher_course_run_1.id
        course_run_comment.save()

        # Set return values for all of the Salesforce methods that get called
        mock_salesforce().Publisher_Organization__c.create.return_value = {'id': 'SomePubOrgId'}
        mock_salesforce().Course__c.create.return_value = {'id': 'SomeCourseId'}
        mock_salesforce().Case.create.return_value = {'id': 'SomeCaseId'}
        mock_salesforce().Course_Run__c.create.return_value = {'id': 'SomeCourseRunId'}

        with mock.patch(self.LOGGER_PATH) as mock_logger:
            Command().handle()
            self.org_1.refresh_from_db()
            self.course_1.refresh_from_db()
            self.course_run_1.refresh_from_db()

            self.assertEqual(self.org_1.salesforce_id, 'SomePubOrgId')
            self.assertEqual(self.course_1.salesforce_id, 'SomeCourseId')
            self.assertEqual(self.course_1.salesforce_case_id, 'SomeCaseId')
            self.assertEqual(self.course_run_1.salesforce_id, 'SomeCourseRunId')

            mock_logger.info.assert_called_with('Inserted 2 comments for {}'.format(self.course_1.title))
 def setUp(self):
     super(IsOwnerTests, self).setUp()
     self.permissions_class = IsOwner()
     self.user = UserFactory.create()
     self.comment = CommentFactory.create(user=self.user, comment='test comment')
Ejemplo n.º 10
0
 def _generate_comment(self, content_object, user):
     """ DRY method to generate the comment."""
     return CommentFactory(content_object=content_object, user=user, site=self.site)
Ejemplo n.º 11
0
 def create_comment(self, content_object):
     """ DRY method to create the comment for a given content type."""
     return CommentFactory(content_object=content_object,
                           user=self.user,
                           site=self.site)