Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

articles/show increases hits

  • Loading branch information...
commit 700a92d6b9e6dcaad837fac6b72c354ce8431222 1 parent 5d84307
@danggo danggo authored
View
5 apiprj/api1_app/models.py
@@ -110,7 +110,10 @@ def dec_comment_count(self):
self._fix_notice_deadline()
def __unicode__(self):
- return ",".join((str(self.id), self.title, self.name))
+ return ",".join((str(self.id), self.title, self.name))
+
+ def inc_hit_count(self):
+ self.count += 1
class AbstractComment(models.Model):
id = models.AutoField(primary_key=True)
View
4 apiprj/api1_app/modelwrap.py
@@ -190,6 +190,10 @@ def get(self, board_id, article_id, user_id):
article_model = board_model.objects.get(id=article_id)
comments = Comment.get(board_id, article_id)
article = Article.pack(article_model, board_id, comments)
+
+ article_model.inc_hit_count()
+ article_model.save()
+
return article
@classmethod
View
20 autotest/apitest.py
@@ -208,6 +208,26 @@ def test_delete(self):
self.assertEqual(resp['status'], '200')
self.assertEqual(obj['status'], 'ok')
+ def test_hits_count(self):
+ 'GET articles/show/ hits increasement'
+
+ # before show article
+ resp, content = self.oauth_get('articles/show/board_alumni99/100',
+ self.consumer, self.access_token)
+ self.assertEqual(resp['status'], '200')
+ obj = json.loads(content)
+ before_show = obj['hits']
+
+ # after show article
+ resp, content = self.oauth_get('articles/show/board_alumni99/100',
+ self.consumer, self.access_token)
+ self.assertEqual(resp['status'], '200')
+ obj = json.loads(content)
+ after_show = obj['hits']
+
+ # differences must be 1
+ self.assertEqual(before_show+1, after_show)
+
class BoardsTest(ApiTestCase):
def test_lookup(self):
Please sign in to comment.
Something went wrong with that request. Please try again.