def test_save(self): updated_user_name = self.test_user_name + ' updated' user1 = users.find(self.test_user_id) user1.name = updated_user_name users.save(user1) user2 = users.find(self.test_user_id) self.assertEqual(user2.name, updated_user_name)
def test_commit(self): video = videos.find('5129e49971eeccbbcaf90802') video._duration = 0 user = users.find(self.user_id) watchtran.begin(user, video) service_url = '/player/commit.json' data = dict(video_id=video.sysid) with self.app.test_client() as client: with client.session_transaction() as sess: sess['account'] = self.user_id response = post_json(service_url, data, client) response_chances = response['chances'] user = users.find(user.sysid) self.assertEqual(response_chances, 223) self.assertEqual(user.chances, 223)
def test_commit(self): user = users.find(self.test_user_id) video = videos.find(self.video_id) video._duration = 0 watchtran.begin(user, video) result = watchtran.commit(user, video) self.assertIsNotNone(result)
def test_begin(self): user = users.find(self.test_user_id) video = videos.find(self.video_id) watchtran.begin(user, video) key = self.prefix + self.test_user_id val = self.redis.get(key) self.assertIsNotNone(val)
def test_screening_log(self): video = videos.find(self.video_id) user1 = users.find(self.test_user_id) points = user1.chances screening_id = users.screening_log(user1, video) user2 = users.find(self.test_user_id) screening_id = ObjectId(screening_id) found = self.database.screening.find_one(screening_id) removed = self.database.screening.remove(screening_id) self.assertEqual(user2.chances, points+1) self.assertIsNotNone(found) self.assertEqual(str(found['video']['id']), video.sysid) self.assertEqual(str(found['user']['id']), user1.sysid) self.assertIsNotNone(removed) self.assertTrue(removed['ok']) self.assertEqual(removed['n'], 1)
def test_like(self): user = users.find(self.user_id) comment1 = comments.find(self.comment_id) likes = comment1.likes comments.like(comment1, user) comment2 = comments.find(self.comment_id) self.assertIsNot(comment1, comment2) self.assertEqual(comment1.likes, likes+1) self.assertEqual(comment2.likes, likes+1)
def test_find_or_new(self): user1 = users.find_or_new(self.test_user_id) new_user_id = str(ObjectId()) user2 = users.find_or_new(new_user_id) user3 = users.find(new_user_id) self.assertIsNotNone(user1) self.assertIsNotNone(user2) self.assertIsNone(user3) self.assertEqual(user1.name, self.test_user_name) self.assertEqual(user2.name, '(new unnamed)')
def test_unlike(self): user = users.find(self.user_id) comment1 = comments.find(self.comment_id) comments.like(comment1, user) comment2 = comments.find(self.comment_id) likes = comment2.likes comments.unlike(comment2, user) comment3 = comments.find(self.comment_id) self.assertIsNot(comment2, comment3) self.assertEqual(comment2.likes, likes-1) self.assertEqual(comment3.likes, likes-1)
def test_new_comment(self): video = videos.find(self.video_id) user = users.find(self.user_id) text = 'This is a new comment from {0}'.format(repr(self)) time = float(video.duration) / 3 comment1 = comments.new_comment(video, user, text, time) comment2 = comments.find(comment1.sysid) removed = self.database.comments.remove(ObjectId(comment1.sysid)) self.assertIsNot(comment1, comment2) self.assertEqual(comment1.text, text) self.assertEqual(comment2.text, text) self.assertEqual(removed['n'], 1)
def setUp(self): self.database = connection() user = { 'name': 'test user: {0}'.format(repr(self)), 'chances': 123 } video = { 'duration' : 65, 'random' : 0.31461311114729994, 'vimeoid' : 24879869, 'description' : 'The story of a cartoon character', 'title' : 'Overcast' } user_id = str(self.database.accounts.insert(user)) video_id = str(self.database.videos.insert(video)) self.video = videos.find(video_id) self.user = users.find(user_id)
def test_commit_too_early(self): user = users.find(self.test_user_id) video = videos.find(self.video_id) watchtran.begin(user, video) result = watchtran.commit(user, video) self.assertIsNone(result)
def test_commit_without_begin(self): user = users.find(self.test_user_id) video = videos.find(self.video_id) result = watchtran.commit(user, video) self.assertIsNone(result)
def test_find(self): user = users.find(self.test_user_id) self.assertIsNotNone(user)