def write(request): user = request.user context = {} if not user.is_authenticated: raise Http404('None') if request.method == 'GET': context['types'] = ArticleType.objects.all() response = render(request, 'write.html', context) return response if request.method == 'POST': title = request.POST.get('title', '') content = request.POST.get('content', '') type = request.POST.get('type', '') if not type: context = {'status': 'NONE'} return JsonResponse(context) if title and content: new_article = Article() new_article.type = get_object_or_404(ArticleType, title=type) new_article.author = user new_article.title = title new_article.content = content new_article.save() context = {'status': 'SUCCESS'} else: context = {'status': 'NULL'} return JsonResponse(context)
def post(request): now=time.localtime() article =Article() if request.POST.has_key('content'): article.author = cgi.escape(request.POST['author'].decode('utf-8')) article.content = request.POST['content'].decode('utf-8') article.tags = request.POST['tags'].decode('utf-8') article.title = cgi.escape(request.POST['title'].decode('utf-8')) now_date = datetime.datetime.now()+timedelta(hours=+8) s = now_date.ctime() article.date = str(now_date)[:-7] article.gmtdate = "%s, %s %s %s %s GMT" % (s[:3] ,s[8:10], s[4:7] ,s[-4:] ,s[11:19]) article.year = str(datetime.datetime.now()+timedelta(hours=+8))[:4] article.month = str(datetime.datetime.now()+timedelta(hours=+8))[5:7] if not article.title: if len(article.content) > 11: article.title = article.content[:12] + '...' else: article.title=article.content article.id=time.strftime('%Y%m%d%H%M%S',now) if article.content: article.put() for tag_name in filter(None,article.tags.split(' ')): tag = Tag() tag.tag = tag_name tag.article_id = article.id tag.put() return HttpResponseRedirect("/blog/")
def test_validate_register(self): self.assertEquals( 0, len(BlogUser.objects.filter(email='*****@*****.**'))) response = self.client.post( reverse('account:register'), { 'username': '******', 'email': '*****@*****.**', 'password1': 'password123!q@wE#R$T', 'password2': 'password123!q@wE#R$T', }) self.assertEquals( 1, len(BlogUser.objects.filter(email='*****@*****.**'))) user = BlogUser.objects.filter(email='*****@*****.**')[0] sign = get_md5(get_md5(settings.SECRET_KEY + str(user.id))) path = reverse('accounts:result') url = '{path}?type=validation&id={id}&sign={sign}'.format(path=path, id=user.id, sign=sign) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.client.login(username='******', password='******') user = BlogUser.objects.filter(email='*****@*****.**')[0] user.is_superuser = True user.is_staff = True user.save() delete_sidebar_cache(user.username) category = Category() category.name = "categoryaaa" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() article = Article() article.category = category article.title = "nicetitle333" article.body = "nicecontentttt" article.author = user article.type = 'a' article.status = 'p' article.save() response = self.client.get(article.get_admin_url()) self.assertEqual(response.status_code, 200) response = self.client.get(reverse('account:logout')) self.assertIn(response.status_code, [301, 302, 200]) response = self.client.get(article.get_admin_url()) self.assertIn(response.status_code, [301, 302, 200]) response = self.client.post(reverse('account:login'), { 'username': '******', 'password': '******' }) self.assertIn(response.status_code, [301, 302, 200]) response = self.client.get(article.get_admin_url()) self.assertIn(response.status_code, [301, 302, 200])
def post(self, request, format=None): try: ser = SubmitAricleSerializer(data=request.data) if ser._valid(): title = ser.data.get('title') cover = request.FILES['cover'] content = ser.data.get('content') category_id = ser.data.get('category_id') author_id = ser.data.get('author_id') promote = ser.data.get('promote') else: return Response({'status':'Bad request ...', status=status.HTTP_200_OK}) user = User.objects.get(id=author_id) author = UserProfile.objects.get(user=user) category = Category.objects.get(id=category_id) article = Article() article.title = title article.cover = cover article.content = content article.category = category article.author = author article.promote = promote article.save() return Response('status':'OK', status = status.HTTP_200_OK) except: return Response({'status': 'server error .....'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def test_validate_account(self): site = get_current_site().domain user = BlogUser.objects.create_superuser( email="*****@*****.**", username="******", password="******") testuser = BlogUser.objects.get(username='******') loginresult = self.client.login(username='******', password='******') self.assertEqual(loginresult, True) response = self.client.get('/admin/') self.assertEqual(response.status_code, 200) category = Category() category.name = "categoryaaa" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() article = Article() article.title = "nicetitleaaa" article.body = "nicecontentaaa" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() response = self.client.get(article.get_admin_url()) self.assertEqual(response.status_code, 200)
def test_validate_comment(self): site = Site.objects.get_current().domain user = BlogUser.objects.create_superuser(email="*****@*****.**", username="******", password="******") self.client.login(username='******', password='******') c = Category() c.name = "categoryccc" c.created_time = datetime.datetime.now() c.last_mod_time = datetime.datetime.now() c.save() article = Article() article.title = "nicetitleccc" article.body = "nicecontentccc" article.author = user article.category = c article.type = 'a' article.status = 'p' article.save() s = TextMessage([]) s.content = "nicetitleccc" rsp = search(s, None) self.assertTrue(rsp != '没有找到相关文章。') rsp = category(None, None) self.assertIsNotNone(rsp) rsp = recents(None, None) self.assertTrue(rsp != '暂时还没有文章') cmd = commands() cmd.title = "test" cmd.command = "ls" cmd.describe = "test" cmd.save() cmdhandler = CommandHandler() rsp = cmdhandler.run('test') self.assertIsNotNone(rsp) s.source = 'u' s.content = 'test' msghandler = MessageHandler(s, {}) #msghandler.userinfo.isPasswordSet = True #msghandler.userinfo.isAdmin = True msghandler.handler() s.content = 'y' msghandler.handler() s.content = 'idcard:12321233' msghandler.handler() s.content = 'weather:上海' msghandler.handler() s.content = 'admin' msghandler.handler() s.content = '123' msghandler.handler() s.content = 'exit' msghandler.handler()
def test_validate_account(self): site = Site.objects.get_current().domain user = BlogUser.objects.create_superuser(email="*****@*****.**", username="******", password="******") self.client.login(username='******', password='******') response = self.client.get('/admin/') self.assertEqual(response.status_code, 200) category = Category() category.name = "categoryaaa" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() article = Article() article.title = "nicetitleaaa" article.body = "nicecontentaaa" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() response = self.client.get(article.get_admin_url()) self.assertEqual(response.status_code, 200)
def handle(self, *args, **options): superuser_username = options["superuser_username"] try: superuser = User.objects.get(username=superuser_username) except ObjectDoesNotExist: raise (CommandError( "Can't found the superuser with username '{}'!" .format(superuser_username))) legacy_articles = LegacyArticle.objects.all() for legacy_article in legacy_articles: article = Article() article.pk = legacy_article.pk article.author = superuser # MySQL returns `long` type for all `IntegerField`s. article.created = (datetime .fromtimestamp(int(legacy_article.created))) # Field `last_updated` is not set always. if legacy_article.last_updated: article.modified = (datetime.fromtimestamp( int(legacy_article.last_updated))) article.title = legacy_article.title article.content = legacy_article.content article.slug = defaultfilters.slugify(legacy_article.title) if legacy_article.tweet_id: article.tweet_id = int(legacy_article.tweet_id) article.save() (self.stdout.write( "Import was successful! Total of {} articles were imported.\n" .format(legacy_articles.count())))
def test_validate_article(self): from accounts.models import BlogUser site = Site.objects.get_current().domain user = BlogUser() user.email = "*****@*****.**" user.username = "******" user.password = "******" user.set_password("liangliangyy") user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200)
def test_validate_comment(self): site = Site.objects.get_current().domain user = BlogUser.objects.create_superuser(email="*****@*****.**", username="******", password="******") self.client.login(username='******', password='******') c = Category() c.name = "categoryccc" c.created_time = datetime.datetime.now() c.last_mod_time = datetime.datetime.now() c.save() article = Article() article.title = "nicetitleccc" article.body = "nicecontentccc" article.author = user article.category = c article.type = 'a' article.status = 'p' article.save() s = TextMessage([]) s.content = "nicetitleccc" rsp = search(s, None) self.assertTrue(rsp != '没有找到相关文章。') rsp = category(None, None) self.assertIsNotNone(rsp) rsp = recents(None, None) self.assertTrue(rsp != '暂时还没有文章') cmd = commands() cmd.title = "test" cmd.command = "ls" cmd.describe = "test" cmd.save() cmdhandler = CommandHandler() rsp = cmdhandler.run('test') self.assertIsNotNone(rsp) s.source = 'u' s.content = 'test' msghandler = MessageHandler(s, {}) #msghandler.userinfo.isPasswordSet = True #msghandler.userinfo.isAdmin = True msghandler.handler() s.content = 'y' msghandler.handler() s.content='idcard:12321233' msghandler.handler() s.content='weather:上海' msghandler.handler() s.content='admin' msghandler.handler() s.content='123' msghandler.handler() s.content = 'exit' msghandler.handler()
def post(self): from blog.forms import AddContentModalForm from auth.models import User self._form = AddContentModalForm(request.form) from blog.models import Article a = Article() self._form.populate_obj(a) a.author = User.query.filter(User.email==session.get('email',None)).first() a.save() return self.redirect('blog.index')
def post(self): from blog.forms import AddContentModalForm from auth.models import User self._form = AddContentModalForm(request.form) from blog.models import Article a = Article() self._form.populate_obj(a) a.author = User.query.filter( User.email == session.get('email', None)).first() a.save() return self.redirect('blog.index')
def test_validate_register(self): self.assertEquals( 0, len(BlogUser.objects.filter(email='*****@*****.**'))) response = self.client.post( reverse('account:register'), { 'username': '******', 'email': '*****@*****.**', 'password1': 'password123!q@wE#R$T', 'password2': 'password123!q@wE#R$T', }) self.assertEquals( 1, len(BlogUser.objects.filter(email='*****@*****.**'))) self.client.login(username='******', password='******') user = BlogUser.objects.filter(email='*****@*****.**')[0] user.is_superuser = True user.is_staff = True user.save() delete_view_cache(user.username) category = Category() category.name = "categoryaaa" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() article = Article() article.category = category article.title = "nicetitle333" article.body = "nicecontentttt" article.author = user article.type = 'a' article.status = 'p' article.save() response = self.client.get(article.get_admin_url()) self.assertEqual(response.status_code, 200) response = self.client.get(reverse('account:logout')) self.assertIn(response.status_code, [301, 302, 200]) response = self.client.get(article.get_admin_url()) self.assertIn(response.status_code, [301, 302, 200]) response = self.client.post(reverse('account:login'), { 'username': '******', 'password': '******' }) self.assertIn(response.status_code, [301, 302, 200]) response = self.client.get(article.get_admin_url()) self.assertIn(response.status_code, [301, 302, 200])
def test_validate_comment(self): site = get_current_site().domain user = BlogUser.objects.create_superuser( email="*****@*****.**", username="******", password="******") self.client.login(username='******', password='******') c = Category() c.name = "categoryccc" c.created_time = timezone.now() c.last_mod_time = timezone.now() c.save() article = Article() article.title = "nicetitleccc" article.body = "nicecontentccc" article.author = user article.category = c article.type = 'a' article.status = 'p' article.save() s = TextMessage([]) s.content = "nice" rsp = search(s, None) rsp = category(None, None) self.assertIsNotNone(rsp) rsp = recents(None, None) self.assertTrue(rsp != 'No articles yet') cmd = commands() cmd.title = "test" cmd.command = "ls" cmd.describe = "test" cmd.save() cmdhandler = CommandHandler() rsp = cmdhandler.run('test') self.assertIsNotNone(rsp) s.source = 'u' s.content = 'test' msghandler = MessageHandler(s, {}) # msghandler.userinfo.isPasswordSet = True # msghandler.userinfo.isAdmin = True msghandler.handler() s.content = 'y' msghandler.handler() s.content = 'idcard:12321233' msghandler.handler() s.content = 'weather:
def save(contents): for content in contents: b = Article() b.cateid = 1 b.catename = '绘画' b.title = content['title'] b.content = content['content'] b.url = content['url'] b.author = content['author'] b.abstract = content['abstract'] b.pubtime = datetime.utcnow() b.status = 0 b.save()
def test_article(self): # 这里就简单的测试创建5篇文章 for i in range(1, 6): article = Article() article.category = self.category article.author = self.superuser article.title = 'title' + str(i) article.content = 'content' + str(i) article.save() self.assertEqual(len(Article.objects.all()), 5 + 1) article_detail_res = self.client.get( Article.objects.first().get_absolute_url()) self.assertEqual(article_detail_res.status_code, 200)
def test_validate_register(self): self.assertEquals(0, len(BlogUser.objects.filter(email='*****@*****.**'))) response = self.client.post(reverse('account:register'), { 'username': '******', 'email': '*****@*****.**', 'password1': 'password123', 'password2': 'password123', }) self.assertEquals(1, len(BlogUser.objects.filter(email='*****@*****.**'))) self.client.login(username='******', password='******') user = BlogUser.objects.filter(email='*****@*****.**')[0] user.is_superuser = True user.is_staff = True user.save() category = Category() category.name = "categoryaaa" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() article = Article() article.category = category article.title = "nicetitle333" article.body = "nicecontentttt" article.author = user article.type = 'a' article.status = 'p' article.save() response = self.client.get(article.get_admin_url()) self.assertEqual(response.status_code, 200) response = self.client.get(reverse('account:logout')) self.assertIn(response.status_code, [301, 302]) response = self.client.get(article.get_admin_url()) self.assertIn(response.status_code, [301, 302]) response = self.client.post(reverse('account:login'), { 'username': '******', 'password': '******' }) self.assertIn(response.status_code, [301, 302]) response = self.client.get(article.get_admin_url()) self.assertEqual(response.status_code, 200)
def test_validate_article(self): site = Site.objects.get_current().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("liangliangyy") user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()])
def test_validate_comment(self): site = Site.objects.get_current().domain user = BlogUser.objects.create_superuser( email="*****@*****.**", username="******", password="******") self.client.login(username='******', password='******') category = Category() category.name = "categoryccc" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() article = Article() article.title = "nicetitleccc" article.body = "nicecontentccc" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() commenturl = reverse('comments:postcomment', kwargs={'article_id': article.id}) response = self.client.post(commenturl, {'body': '123ffffffffff'}) self.assertEqual(response.status_code, 200) article = Article.objects.get(pk=article.pk) self.assertEqual(len(article.comment_list()), 0) response = self.client.post(commenturl, { 'body': '123ffffffffff', 'email': user.email, 'name': user.username }) self.assertEqual(response.status_code, 302) article = Article.objects.get(pk=article.pk) self.assertEqual(len(article.comment_list()), 1)
def test_validate_register(self): self.assertEquals(0, len(BlogUser.objects.filter(email='*****@*****.**'))) response = self.client.post(reverse('account:register'), { 'username': '******', 'email': '*****@*****.**', 'password1': 'password123', 'password2': 'password123', }) self.assertEquals(1, len(BlogUser.objects.filter(email='*****@*****.**'))) self.client.login(username='******', password='******') user = BlogUser.objects.filter(email='*****@*****.**')[0] user.is_superuser = True user.is_staff = True user.save() article = Article() article.title = "nicetitle333" article.body = "nicecontentttt" article.author = user article.type = 'a' article.status = 'p' article.save() response = self.client.get(article.get_admin_url()) self.assertEqual(response.status_code, 200) response = self.client.get(reverse('account:logout')) self.assertIn(response.status_code, [301, 302]) response = self.client.get(article.get_admin_url()) self.assertIn(response.status_code, [301, 302]) response = self.client.post(reverse('account:login'), { 'username': '******', 'password': '******' }) self.assertIn(response.status_code, [301, 302]) response = self.client.get(article.get_admin_url()) self.assertEqual(response.status_code, 200)
def createAritcle(request): if request.method == 'POST': username = request.session.get('name') user = User.objects.get(name=username) article = Article() title = request.POST.get('title') author = request.POST.get('author') content = request.POST.get('content') columnname = request.POST.get('column') column = Column.objects.get(name=columnname) article.author = author article.title = title article.content = content article.column = column article.user = user article.save() articles = mdToHtml([article]) try: comments = Comment.objects.filter(article=article) # comments.objects.order_by('pubTime') i = 1 for comment in comments: comment.floor = i i += 1 comments = mdToHtml(comments) except: comments = None context = {'config': configList, 'articles': articles, 'comments': comments, 'user': user, 'message': '新增文章成功,你今天的每份努力,明天都会获得更多,加油!'} return render(request, 'blogs.html', context=context) else: username = request.session.get('name') try: user = User.objects.get(name=username) except: user = None columns = getAllColumn() context = {'config': configList, 'user': user, 'columns': columns, } return render(request, 'createArticle.html', context=context)
def test_validate_article(self): site = Site.objects.get_current().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("systemsgt.cn") user.is_staff = True user.is_superuser = True user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.notify(article.get_absolute_url()) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) p = Paginator(Article.objects.all(), 2) s = load_pagination_info(p.page(1), '', '') self.assertIsNotNone(s) p = Paginator(Tag.objects.all(), 2) s = load_pagination_info(p.page(1), '分类标签归档', 'tagname') self.assertIsNotNone(s) p = Paginator(BlogUser.objects.all(), 2) s = load_pagination_info(p.page(1), '作者文章归档', 'username') self.assertIsNotNone(s) p = Paginator(Category.objects.all(), 2) s = load_pagination_info(p.page(1), '分类目录归档', 'categoryname') self.assertIsNotNone(s) f = BlogSearchForm() f.search() self.client.login(username='******', password='******') from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()]) rsp = self.client.get('/refresh/') self.assertEqual(rsp.status_code, 200) from blog.templatetags.blog_tags import gravatar_url, gravatar u = gravatar_url('*****@*****.**') u = gravatar('*****@*****.**')
def test_validate_article(self): site = get_current_site().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("superstrongz") user.is_staff = True user.is_superuser = True user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('admin/admin/logentry/') s = SideBar() s.sequence = 1 s.name = 'test' s.content = 'test content' s.is_enable = True s.save() category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) for i in range(20): article = Article() article.title = "nicetitle" + str(i) article.body = "nicetitle" + str(i) article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() article.tags.add(tag) article.save() response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.notify(article.get_absolute_url()) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 302) self.client.login(username='******', password='******') rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 200) response = self.client.get(reverse('blog:archives')) self.assertEqual(response.status_code, 200) p = Paginator(Article.objects.all(), 2) self.__check_pagination__(p, '', '') p = Paginator(Article.objects.filter(tags=tag), 2) self.__check_pagination__(p, '分类标签归档', tag.slug) p = Paginator(Article.objects.filter(author__username='******'), 2) self.__check_pagination__(p, '作者文章归档', 'superstrongz') p = Paginator(Article.objects.filter(category=category), 2) self.__check_pagination__(p, '分类目录归档', category.slug) f = BlogSearchForm() f.search() self.client.login(username='******', password='******') from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()]) from blog.templatetags.blog_tags import gravatar_url, gravatar u = gravatar_url('*****@*****.**') u = gravatar('*****@*****.**')
def test_validate_article(self): site = Site.objects.get_current().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("liangliangyy") user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) p = Paginator(Article.objects.all(), 2) s = load_pagination_info(p.page(1), '', '') self.assertIsNotNone(s) p = Paginator(Tag.objects.all(), 2) s = load_pagination_info(p.page(1), '分类标签归档', 'tagname') self.assertIsNotNone(s) p = Paginator(BlogUser.objects.all(), 2) s = load_pagination_info(p.page(1), '作者文章归档', 'username') self.assertIsNotNone(s) p = Paginator(Category.objects.all(), 2) s = load_pagination_info(p.page(1), '分类目录归档', 'categoryname') self.assertIsNotNone(s) f = BlogSearchForm() f.search() from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()])
def test_validate_comment(self): site = get_current_site().domain user = BlogUser.objects.create_superuser( email="*****@*****.**", username="******", password="******") self.client.login(username='******', password='******') category = Category() category.name = "categoryccc" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() article = Article() article.title = "nicetitleccc" article.body = "nicecontentccc" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() commenturl = reverse('comments:postcomment', kwargs={'article_id': article.id}) response = self.client.post(commenturl, {'body': '123ffffffffff'}) self.assertEqual(response.status_code, 200) article = Article.objects.get(pk=article.pk) self.assertEqual(len(article.comment_list()), 0) response = self.client.post(commenturl, { 'body': '123ffffffffff', 'email': user.email, 'name': user.username }) self.assertEqual(response.status_code, 302) article = Article.objects.get(pk=article.pk) self.assertEqual(len(article.comment_list()), 1) parent_comment_id = article.comment_list()[0].id response = self.client.post( commenturl, { 'body': ''' # Title1 ```python import os ``` [url](https://www.lylinux.net/) [ddd](http://www.baidu.com) ''', 'email': user.email, 'name': user.username, 'parent_comment_id': parent_comment_id }) self.assertEqual(response.status_code, 302) article = Article.objects.get(pk=article.pk) self.assertEqual(len(article.comment_list()), 2) comment = Comment.objects.get(id=parent_comment_id) tree = parse_commenttree(article.comment_list(), comment) self.assertEqual(len(tree), 1) data = show_comment_item(comment, True) self.assertIsNotNone(data) s = get_max_articleid_commentid() self.assertIsNotNone(s)
def test_validate_article(self): site = Site.objects.get_current().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("liangliangyy") user.is_staff = True user.is_superuser = True user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) s = SideBar() s.sequence = 1 s.name = 'test' s.content = 'test content' s.is_enable = True s.save() category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) for i in range(20): article = Article() article.title = "nicetitle" + str(i) article.body = "nicetitle" + str(i) article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() article.tags.add(tag) article.save() response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.notify(article.get_absolute_url()) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 302) self.client.login(username='******', password='******') rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 200) response = self.client.get(reverse('blog:archives')) self.assertEqual(response.status_code, 200) p = Paginator(Article.objects.all(), 2) self.__check_pagination__(p, '', '') p = Paginator(Article.objects.filter(tags=tag), 2) self.__check_pagination__(p, '分类标签归档', tag.slug) p = Paginator(Article.objects.filter(author__username='******'), 2) self.__check_pagination__(p, '作者文章归档', 'liangliangyy') p = Paginator(Article.objects.filter(category=category), 2) self.__check_pagination__(p, '分类目录归档', category.slug) f = BlogSearchForm() f.search() self.client.login(username='******', password='******') from DjangoBlog.spider_notify import SpiderNotify SpiderNotify.baidu_notify([article.get_full_url()]) from blog.templatetags.blog_tags import gravatar_url, gravatar u = gravatar_url('*****@*****.**') u = gravatar('*****@*****.**')
def test_validate_article(self): # site = get_current_site().domain user = BlogUser.objects.get_or_create(email="*****@*****.**", username="******")[0] user.set_password("liangliangyy") user.is_staff = True user.is_superuser = True user.save() response = self.client.get(user.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/admin/servermanager/emailsendlog/') response = self.client.get('admin/admin/logentry/') s = SideBar() s.sequence = 1 s.name = 'test' s.content = 'test content' s.is_enable = True s.save() category = Category() category.name = "category" category.created_time = datetime.datetime.now() category.last_mod_time = datetime.datetime.now() category.save() tag = Tag() tag.name = "nicetag" tag.save() article = Article() article.title = "nicetitle" article.body = "nicecontent" article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() self.assertEqual(0, article.tags.count()) article.tags.add(tag) article.save() self.assertEqual(1, article.tags.count()) for i in range(20): article = Article() article.title = "nicetitle" + str(i) article.body = "nicetitle" + str(i) article.author = user article.category = category article.type = 'a' article.status = 'p' article.save() article.tags.add(tag) article.save() response = self.client.get(article.get_absolute_url()) self.assertEqual(response.status_code, 200) SpiderNotify.notify(article.get_absolute_url()) response = self.client.get(tag.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get(category.get_absolute_url()) self.assertEqual(response.status_code, 200) response = self.client.get('/search', {'q': 'django'}) self.assertEqual(response.status_code, 200) s = load_articletags(article) self.assertIsNotNone(s) rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 302) self.client.login(username='******', password='******') rsp = self.client.get('/refresh') self.assertEqual(rsp.status_code, 200) response = self.client.get(reverse('blog:archives')) self.assertEqual(response.status_code, 200) p = Paginator(Article.objects.all(), 2) self.__check_pagination__(p, '', '') p = Paginator(Article.objects.filter(tags=tag), 2) self.__check_pagination__(p, '分类标签归档', tag.slug) p = Paginator(Article.objects.filter(author__username='******'), 2) self.__check_pagination__(p, '作者文章归档', 'liangliangyy') p = Paginator(Article.objects.filter(category=category), 2) self.__check_pagination__(p, '分类目录归档', category.slug) f = BlogSearchForm() f.search() self.client.login(username='******', password='******') SpiderNotify.baidu_notify([article.get_full_url()]) # u = gravatar_url('*****@*****.**') u = gravatar('*****@*****.**') link = Links(sequence=1, name="lylinux", link='https://wwww.lylinux.net') link.save() response = self.client.get('/links.html') self.assertEqual(response.status_code, 200)