BVB Source Codes

isso Show test_vote.py Source code

Return Download isso: download test_vote.py Source code - Download isso Source code - Type:.py
  1.  
  2. from __future__ import unicode_literals
  3.  
  4. import os
  5. import json
  6. import tempfile
  7.  
  8. try:
  9.     import unittest2 as unittest
  10. except ImportError:
  11.     import unittest
  12.  
  13. from werkzeug.wrappers import Response
  14.  
  15. from isso import Isso, core, config, dist
  16. from isso.utils import http
  17.  
  18. from fixtures import curl, loads, FakeIP, JSONClient
  19. http.curl = curl
  20.  
  21.  
  22. class TestVote(unittest.TestCase):
  23.  
  24.     def setUp(self):
  25.         self.path = tempfile.NamedTemporaryFile().name
  26.  
  27.     def makeClient(self, ip):
  28.  
  29.         conf = config.load(os.path.join(dist.location, "share", "isso.conf"))
  30.         conf.set("general", "dbpath", self.path)
  31.         conf.set("guard", "enabled", "off")
  32.         conf.set("hash", "algorithm", "none")
  33.  
  34.         class App(Isso, core.Mixin):
  35.             pass
  36.  
  37.         app = App(conf)
  38.         app.wsgi_app = FakeIP(app.wsgi_app, ip)
  39.  
  40.         return JSONClient(app, Response)
  41.  
  42.     def testZeroLikes(self):
  43.  
  44.         rv = self.makeClient("127.0.0.1").post("/new?uri=test", data=json.dumps({"text": "..."}))
  45.         self.assertEqual(loads(rv.data)['likes'], 0)
  46.         self.assertEqual(loads(rv.data)['dislikes'], 0)
  47.  
  48.     def testSingleLike(self):
  49.  
  50.         self.makeClient("127.0.0.1").post("/new?uri=test", data=json.dumps({"text": "..."}))
  51.         rv = self.makeClient("0.0.0.0").post("/id/1/like")
  52.  
  53.         self.assertEqual(rv.status_code, 200)
  54.         self.assertEqual(loads(rv.data)["likes"], 1)
  55.  
  56.     def testSelfLike(self):
  57.  
  58.         bob = self.makeClient("127.0.0.1")
  59.         bob.post("/new?uri=test", data=json.dumps({"text": "..."}))
  60.         rv = bob.post('/id/1/like')
  61.  
  62.         self.assertEqual(rv.status_code, 200)
  63.         self.assertEqual(loads(rv.data)["likes"], 0)
  64.  
  65.     def testMultipleLikes(self):
  66.  
  67.         self.makeClient("127.0.0.1").post("/new?uri=test", data=json.dumps({"text": "..."}))
  68.         for num in range(15):
  69.             rv = self.makeClient("1.2.%i.0" % num).post('/id/1/like')
  70.             self.assertEqual(rv.status_code, 200)
  71.             self.assertEqual(loads(rv.data)["likes"], num + 1)
  72.  
  73.     def testVoteOnNonexistentComment(self):
  74.         rv = self.makeClient("1.2.3.4").post('/id/1/like')
  75.         self.assertEqual(rv.status_code, 200)
  76.         self.assertEqual(loads(rv.data), None)
  77.  
  78.     def testTooManyLikes(self):
  79.  
  80.         self.makeClient("127.0.0.1").post("/new?uri=test", data=json.dumps({"text": "..."}))
  81.         for num in range(256):
  82.             rv = self.makeClient("1.2.%i.0" % num).post('/id/1/like')
  83.             self.assertEqual(rv.status_code, 200)
  84.  
  85.             if num >= 142:
  86.                 self.assertEqual(loads(rv.data)["likes"], 142)
  87.             else:
  88.                 self.assertEqual(loads(rv.data)["likes"], num + 1)
  89.  
  90.     def testDislike(self):
  91.         self.makeClient("127.0.0.1").post("/new?uri=test", data=json.dumps({"text": "..."}))
  92.         rv = self.makeClient("1.2.3.4").post('/id/1/dislike')
  93.  
  94.         self.assertEqual(rv.status_code, 200)
  95.         self.assertEqual(loads(rv.data)['likes'], 0)
  96.         self.assertEqual(loads(rv.data)['dislikes'], 1)
  97.  
downloadtest_vote.py Source code - Download isso Source code
Related Source Codes/Software:
hologram - A markdown based documentation system for style gu... 2017-05-12
www.html5rocks.com - ....a top-notch resource for web developer 2017-05-12
MTStatusBarOverlay - A custom iOS status bar overlay seen in Apps like ... 2017-05-12
blueprint - Reverse engineer server configuration ... 2017-05-12
PullToRefresh - A simple iPhone TableViewController for adding the... 2017-05-12
python3-cookbook - "The Python Cookbook" 3 rd Edition Translatio 2017-05-12
TSA-Travel-Sentry-master-keys - 3D reproduction of TSA Master key 2017-05-12
fatfree - A powerful yet easy-to-use PHP micro-framework des... 2017-05-13
rolify - Role management library with the resource scoping 2017-05-13
jquery-mockjax - The jQuery Mockjax Plugin provides a simple and ex... 2017-05-13
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top