def test_multiple_votes(self): vote = Vote(vote_type=0, reputation_change=-2).save() question = Question(object_uuid=str(uuid1()), title=str(uuid1()), owner_username=self.pleb.username).save() question.owned_by.connect(self.pleb) question.last_votes.connect(vote) question.first_votes.connect(vote) vote.vote_on.connect(question) vote.owned_by.connect(self.pleb) task_data = { 'node_id': str(uuid1()), 'voter': self.pleb.username, 'parent_object': question.object_uuid, 'vote_type': 1 } res = create_vote_node.apply_async(kwargs=task_data) while not res.ready(): time.sleep(1) self.assertTrue(res.result) test_vote = Vote.nodes.get(object_uuid=task_data['node_id']) self.assertEqual(test_vote.reputation_change, 5) self.assertTrue(question.first_votes.is_connected(vote)) self.assertFalse(question.last_votes.is_connected(vote)) self.assertTrue(question.last_votes.is_connected(test_vote))
def test_owner_does_not_exist(self): question = Question(object_uuid=str(uuid1()), title=str(uuid1()), owner_username=str(uuid1())).save() question.owned_by.connect(self.pleb) task_data = { 'node_id': str(uuid1()), 'voter': self.pleb.username, 'parent_object': question.object_uuid, 'vote_type': 1 } res = create_vote_node.apply_async(kwargs=task_data) while not res.ready(): time.sleep(1) self.assertIsInstance(res.result, Exception)
def test_vote_private(self): post = Post(object_uuid=str(uuid1()), owner_username=self.pleb.username).save() post.owned_by.connect(self.pleb) task_data = { 'node_id': str(uuid1()), 'voter': self.pleb.username, 'parent_object': post.object_uuid, 'vote_type': 0 } res = create_vote_node.apply_async(kwargs=task_data) while not res.ready(): time.sleep(1) self.assertTrue(res.result) test_vote = Vote.nodes.get(object_uuid=task_data['node_id']) self.assertEqual(test_vote.reputation_change, 0) self.assertTrue(post.first_votes.is_connected(test_vote)) self.assertTrue(post.last_votes.is_connected(test_vote))