Exemplo n.º 1
0
def handle_vote(parent_object_uuid, status, username, now):
    vote_data = {
        "parent_object": parent_object_uuid,
        "user": username,
        "status": status,
        "time": now
    }
    res = get_vote(parent_object_uuid, user=username)

    if not res:
        add_object_to_table('votes', vote_data)
    else:
        update_vote(parent_object_uuid, username, status, now)
    return True
Exemplo n.º 2
0
 def test_determine_vote_type_with_vote_none(self):
     vote_data = {
         "status": 2,
         "parent_object": self.question.object_uuid,
         "user": self.pleb.username
     }
     res1 = add_object_to_table("votes", vote_data)
     self.assertTrue(res1)
     res2 = determine_vote_type(self.question.object_uuid,
                                self.pleb.username)
     self.assertIsNone(res2)
Exemplo n.º 3
0
 def test_handle_vote_already_voted(self):
     vote_data = {
         "status": 1,
         "parent_object": self.question.object_uuid,
         "user": self.pleb.username
     }
     res1 = add_object_to_table("votes", vote_data)
     self.assertTrue(res1)
     res = handle_vote(self.question.object_uuid, 1, self.user.username,
                       str(datetime.datetime.now(pytz.utc)))
     self.assertTrue(res)
Exemplo n.º 4
0
    def test_get_vote_count(self):
        uuid = str(uuid1())
        now = unicode(datetime.now(pytz.utc))
        vote_data = {
            'parent_object': uuid,
            'user': self.pleb.username,
            'status': 1,
            'created': now
        }
        res = add_object_to_table('votes', vote_data)
        self.assertTrue(res)

        res = get_vote_count(uuid, 1)

        self.assertEqual(res, 1)
Exemplo n.º 5
0
    def test_update_vote(self):
        uuid = str(uuid1())
        now = unicode(datetime.now(pytz.utc))
        vote_data = {
            'parent_object': uuid,
            'user': self.pleb.username,
            'status': 1,
            'created': now
        }
        res = add_object_to_table('votes', vote_data)
        self.assertTrue(res)

        res, _ = update_vote(uuid, self.pleb.username, 0, now)
        self.assertNotEqual(res, False)
        self.assertFalse(isinstance(res, Exception))
Exemplo n.º 6
0
    def test_spawn_user_updates_with_votes(self):
        now = unicode(datetime.now(pytz.utc))

        vote_data = {
            'parent_object': self.question.object_uuid,
            'user': self.pleb.username,
            'status': 1,
            'created': now
        }
        data = {
            "username": self.pleb.username,
            "object_uuid": self.question.object_uuid
        }
        res = add_object_to_table('votes', vote_data)
        self.assertTrue(res)

        res = spawn_user_updates.apply_async(kwargs=data)
        while not res.ready():
            time.sleep(1)
        self.assertTrue(res.result)