示例#1
0
def chat_event():
    karma_app = KarmaApp()
    karma_response = karma_app.process_request(request.data.decode('utf-8'))
    if karma_response is None:
        raise ExpectationFailed
    response = {"bot": settings.BOT_NAME, "text": karma_response}
    return app.make_response((json.dumps(response), 201, {
        'Content-Type': 'application/json; charset=utf-8'
    }))
示例#2
0
 def test_decr(self):
     app = KarmaApp()
     self.assertEqual(app.get("joe"), 0)
     app.decr("joe")
     app.decr("joe")
     self.assertEqual(app.get("joe"), -2)
     app.decr("joe")
     self.assertEqual(app.get("joe"), -3)
     self.assertEqual(app.get("joe2"), 0)
示例#3
0
 def test_top(self):
     app = KarmaApp({"joe": 5, "bob": 10, "alice": 7})
     self.assertEqual(
         app.top(10), OrderedDict([
             ['bob', 10],
             ['alice', 7],
             ['joe', 5],
         ]))
     self.assertEqual(app.top(2), OrderedDict([
         ['bob', 10],
         ['alice', 7],
     ]))
     self.assertEqual(app.top(1), OrderedDict([
         ['bob', 10],
     ]))
示例#4
0
 def _mock_karma_app_factory(*args, **kwargs):
     karma_app = KarmaApp(*args, **kwargs)
     karma_app.redis = g_mock_redis
     return karma_app
示例#5
0
 def test_incr(self):
     app = KarmaApp()
     self.assertEqual(app.get("joe"), 0)
     self.assertEqual(app.get("joe2"), 0)
     app.incr("joe")
     app.incr("joe")
     self.assertEqual(app.get("joe"), 2)
     self.assertEqual(app.get("joe2"), 0)
     app.incr("joe2")
     self.assertEqual(app.get("joe2"), 1)
     app.incr("joe2")
     app.incr("joe2")
     app.incr("joe2")
     self.assertEqual(app.get("joe2"), 4)
示例#6
0
 def test_get(self):
     app = KarmaApp({"joe": 5, "bob": 10})
     self.assertEqual(app.get("joe"), 5)
     self.assertEqual(app.get("bob"), 10)
     self.assertEqual(app.get("joe2"), 0)
     self.assertEqual(app.get("joe3"), 0)