def test_feed(self): test_user = self.user_model.objects.get(username='******') attachment = Attachment(title='Test attachment for get_previous') attachment.save() revision = AttachmentRevision( attachment=attachment, mime_type='text/plain', title=attachment.title, description='', comment='Initial revision.', created=datetime.datetime.now() - datetime.timedelta(seconds=30), creator=test_user, is_approved=True) revision.file.save('get_previous_test_file.txt', ContentFile('I am a test file for get_previous')) revision.save() revision.make_current() feed_url = reverse('attachments.feeds.recent_files', locale='en-US', args=(), kwargs={'format': 'json'}) response = self.client.get(feed_url) data = json.loads(response.content) assert len(data) == 1 assert data[0]['title'] == revision.title assert data[0]['link'] == revision.attachment.get_file_url() assert data[0]['author_name'] == test_user.username
def test_feed(self): test_user = self.user_model.objects.get(username="******") attachment = Attachment(title="Test attachment for get_previous") attachment.save() revision = AttachmentRevision( attachment=attachment, mime_type="text/plain", title=attachment.title, description="", comment="Initial revision.", created=datetime.datetime.now() - datetime.timedelta(seconds=30), creator=test_user, is_approved=True, ) revision.file.save( "get_previous_test_file.txt", ContentFile(b"I am a test file for get_previous"), ) revision.save() revision.make_current() feed_url = reverse("attachments.feeds.recent_files", kwargs={"format": "json"}) response = self.client.get(feed_url) assert_shared_cache_header(response) data = json.loads(response.content) assert len(data) == 1 assert data[0]["title"] == revision.title assert data[0]["link"] == revision.attachment.get_file_url() assert data[0]["author_name"] == test_user.username
def test_spam_submission_tags(self, mock_requests): admin = User.objects.get(username='******') flag, created = Flag.objects.get_or_create(name=SPAM_SUBMISSIONS_FLAG) flag.users.add(admin) revision = admin.created_revisions.all()[0] revision.tags = '"Banana" "Orange" "Apple"' revision.save() url = reverse('admin:wiki_revisionakismetsubmission_add') mock_requests.post(VERIFY_URL, content='valid') mock_requests.post(SPAM_URL, content=Akismet.submission_success) data = { 'revision': revision.id, 'type': 'spam', } self.client.login(username='******', password='******') url = reverse('admin:wiki_revisionakismetsubmission_add') response = self.client.post(url, data) self.assertEqual(response.status_code, 302) request_body = mock_requests.request_history[1].body submitted_data = dict(parse_qsl(request_body)) expected_content = ('Seventh revision of the article.\n' 'article-with-revisions\n' 'Seventh revision of the article.\n' 'Seventh revision of the article.\n' 'Apple\n' 'Banana\n' 'Orange') self.assertEqual(submitted_data['comment_content'], expected_content)
def test_spam_submission_tags(self, mock_requests): admin = User.objects.get(username='******') flag, created = Flag.objects.get_or_create(name=SPAM_SUBMISSIONS_FLAG) flag.users.add(admin) revision = admin.created_revisions.all()[0] revision.tags = '"Banana" "Orange" "Apple"' revision.save() url = reverse('admin:wiki_revisionakismetsubmission_add') mock_requests.post(VERIFY_URL, content='valid') mock_requests.post(SPAM_URL, content=Akismet.submission_success) data = { 'revision': revision.id, 'type': 'spam', } self.client.login(username='******', password='******') url = reverse('admin:wiki_revisionakismetsubmission_add') response = self.client.post(url, data) self.assertEqual(response.status_code, 302) request_body = mock_requests.request_history[1].body submitted_data = dict(parse_qsl(request_body)) expected_content = ( 'Seventh revision of the article.\n' 'article-with-revisions\n' 'Seventh revision of the article.\n' 'Seventh revision of the article.\n' 'Apple\n' 'Banana\n' 'Orange' ) self.assertEqual(submitted_data['comment_content'], expected_content)
def test_feed(self): test_user = self.user_model.objects.get(username='******') attachment = Attachment(title='Test attachment for get_previous') attachment.save() revision = AttachmentRevision(attachment=attachment, mime_type='text/plain', title=attachment.title, description='', comment='Initial revision.', created=datetime.datetime.now() - datetime.timedelta(seconds=30), creator=test_user, is_approved=True) revision.file.save('get_previous_test_file.txt', ContentFile('I am a test file for get_previous')) revision.save() revision.make_current() feed_url = reverse('attachments.feeds.recent_files', locale='en-US', args=(), kwargs={'format': 'json'}) response = self.client.get(feed_url) data = json.loads(response.content) self.assertEqual(len(data), 1) self.assertEqual(data[0]['title'], revision.title) self.assertEqual(data[0]['link'], revision.attachment.get_file_url()) self.assertEqual(data[0]['author_name'], test_user.username)