def test_given_aAdminReviewerTryingToReviewAsAdmin_ItShouldSucceedAndDeclareNonAgreeingConflictingReviewerAsCheaters(self): setReviewTimeUnit(0) score = {'score' : 99, 'proof' : "sdsd", 'time' : 0} playerId = "test" createPlayer(playerId, playerId) service.start(playerId) service.setScore(playerId, score) playerKey = Key.from_path('Player', playerId) createReviewerAndReview("test2", playerKey, {'score':3, 'time': 0}) createReviewerAndReview("test3", playerKey, {'score':999, 'time': 0}) createReviewerAndReview("test4", playerKey, {'score':3, 'time': 0}, True) verifiedScore = VerifiedScore.get_by_key_name("verified", parent=playerKey) playerRecord = Record.get_by_key_name('record', parent=playerKey) self.assertTrue(verifiedScore is None or verifiedScore.value == 0) self.assertEqual(playerRecord.numCheat, 1) playerKey = Key.from_path('Player', 'test3') playerRecord = Record.get_by_key_name('record', parent=playerKey) self.assertEqual(playerRecord.numCheat, 1) playerKey = Key.from_path('Player', 'test2') playerRecord = Record.get_by_key_name('record', parent=playerKey) self.assertEqual(playerRecord.numCheat, 0)
def test_given_aReviewerReviewingTwoTimesTooQuickly_ItShouldBeAskedToRetryLater(self): setReviewTimeUnit(2000) score = {'score' : 3, 'proof' : "sdsd", 'time' : 0} playerId = "test1" createPlayer(playerId, playerId) service.start(playerId) service.setScore(playerId, score) score = {'score' : 3, 'proof' : "sdsd", 'time' : 0} playerId = "test2" createPlayer(playerId, playerId) service.start(playerId) service.setScore(playerId, score) createPlayer("reviewer1", "reviewer1") sleep(3) service.getRandomScore("reviewer1") service.reviewScore("reviewer1", {'score':3, 'time': 0}) response= service.getRandomScore("reviewer1") self.assertTrue('result' in response and response['result']['retry'] > 0)
def test_given_aAdminReviewerTryingToReviewAsAdmin_ItShouldSucceed(self): setReviewTimeUnit(0) score = {'score' : 3, 'proof' : "sdsd", 'time' : 0} playerId = "test1" createPlayer(playerId, playerId) service.start(playerId) service.setScore(playerId, score) createPlayer("reviewer1", "reviewer1") admin = getAdmin() admin.playerList.append('reviewer1') setAdmin(admin) service.getRandomScore("reviewer1") response = service.reviewScore("reviewer1", {'score':3, 'time': 0}, True) self.assertTrue('result' in response) playerKey = Key.from_path('Player', playerId) verifiedScoreWrapper = VerifiedScoreWrapper.get_by_key_name('verifiedScore', parent=playerKey) verifiedScore = verifiedScoreWrapper.verified self.assertEqual(verifiedScore.value, 3) self.assertEqual(verifiedScore.approvedByAdmin, True)
def forceReviewTimeUnit(playerId, value): admin = getAdmin() try: admin.playerList.index(playerId) except ValueError: return getErrorResponse(ADMIN_ONLY) oldReviewTimeUnit = getReviewTimeUnit() setReviewTimeUnit(value) return {'result' : { 'oldReviewTimeUnit' : oldReviewTimeUnit} }
def forceReviewTimeUnit(playerId, value): admin = getAdmin() try: admin.playerList.index(playerId) except ValueError: return getErrorResponse(ADMIN_ONLY) oldReviewTimeUnit = getReviewTimeUnit() setReviewTimeUnit(value) return {'result': {'oldReviewTimeUnit': oldReviewTimeUnit}}
def test_userSetScoreOtherDoNotRetrieveItIfTimeUnitNotPassed(self): setReviewTimeUnit(5000) seed = self.executeGoogleUserSecureService("*****@*****.**", "player1", "score.service.start") score = {'score' : 3, 'proof' : "sdsd", 'time' : 0} #set score (score, actions) self.executeGoogleUserSecureService("*****@*****.**", "player1", "score.service.setScore", score) ## get a random score (seed, score, actions) and it should not match answer = self.executeGoogleUserSecureService("*****@*****.**", "player2", "score.service.getRandomScore") self.assertFalse('proof' in answer and score['proof'] == answer['proof'] and 'seed' in answer and seed == answer['seed'])
def test_given_aAdminReviewerDisapprovingAnAlreadyVerifiedScore_ItShouldDeclareVerifierAsACheaterAndOtherAsNonCheaters(self): setReviewTimeUnit(0) score = {'score' : 99, 'proof' : "sdsd", 'time' : 0} playerId = "test" createPlayer(playerId, playerId) service.start(playerId) service.setScore(playerId, score) playerKey = Key.from_path('Player', playerId) createReviewerAndReview("test2", playerKey, {'score':3, 'time': 0}) createReviewerAndReview("test3", playerKey, {'score':999, 'time': 0}) createReviewerAndReview("test4", playerKey, {'score':99, 'time': 0}) # verified verifiedScoreWrapper = VerifiedScoreWrapper.get_by_key_name('verifiedScore', parent=playerKey) verifiedScore = verifiedScoreWrapper.verified playerRecord = Record.get_by_key_name('record', parent=playerKey) self.assertTrue(verifiedScore.value == 99) self.assertEqual(playerRecord.numCheat, 0) createPlayer('admin1', 'admin1') admin = getAdmin() admin.playerList.append('admin1') setAdmin(admin) service.getHighestNonApprovedScore('admin1') service.approveScore('admin1', {'score':3, 'time': 0}) verifiedScoreWrapper = VerifiedScoreWrapper.get_by_key_name('verifiedScore', parent=playerKey) playerRecord = Record.get_by_key_name('record', parent=playerKey) self.assertTrue(verifiedScoreWrapper is None) self.assertEqual(playerRecord.numCheat, 1) playerKey = Key.from_path('Player', 'test3') playerRecord = Record.get_by_key_name('record', parent=playerKey) self.assertEqual(playerRecord.numCheat, 0) playerKey = Key.from_path('Player', 'test2') playerRecord = Record.get_by_key_name('record', parent=playerKey) self.assertEqual(playerRecord.numCheat, 0) playerKey = Key.from_path('Player', 'test4') playerRecord = Record.get_by_key_name('record', parent=playerKey) self.assertEqual(playerRecord.numCheat, 1)
def test_given_aReviewerTryingToReviewAsAdmin_ItShouldBeGivenAnError(self): setReviewTimeUnit(0) score = {'score' : 3, 'proof' : "sdsd", 'time' : 0} playerId = "test1" createPlayer(playerId, playerId) service.start(playerId) service.setScore(playerId, score) createPlayer("reviewer1", "reviewer1") service.getRandomScore("reviewer1") response = service.reviewScore("reviewer1", {'score':3, 'time': 0}, True) self.assertTrue('error' in response and response['error']['code'] == ADMIN_ONLY['code'])
def test_userSetScoreOtherRetrieveItIfTimeUnitPassed(self): setReviewTimeUnit(3000) response = self.executeGoogleUserSecureService("*****@*****.**", "player1", "score.service.start") result = response['result'] seed= result['seed'] score = {'score' : 3, 'proof' : "sdsd", 'time' : 0} #set score (score, actions) self.executeGoogleUserSecureService("*****@*****.**", "player1", "score.service.setScore", score) time.sleep(3) ## get a random score (seed, score, actions) and it should match answer = self.executeGoogleUserSecureService("*****@*****.**", "player2", "score.service.getRandomScore") result = answer['result'] self.assertTrue('proof' in result and score['proof'] == result['proof'] and 'seed' in result and seed == result['seed'])
def test_whetherTimeUnitIsUpdatedProperly(self): setReviewTimeUnit(0) for i in range(0,10): playerId = 'test' + str(i) createPlayer(playerId, playerId) service.start(playerId) service.setScore(playerId, {'score' : 3, 'proof' : "sdsd", 'time' : 0}) for i in range(10,20): playerId = 'test' + str(i) createPlayer(playerId, playerId) service.getRandomScore(playerId) service.reviewScore(playerId, {'score' : 3, 'time' : 0}) config.nbPlayerPerTimeUnit = 10 setCurrentUser('*****@*****.**', 'test', True) response = self.updateReviewTimeUnitApp.get('/cron/updateReviewTimeUnit') responseValue = int(response.body) self.assertTrue(responseValue > 0 and responseValue < 10000)
def test_given_aReviewerGettingRandomScoreQuickly_ItShouldNotBeAskedToRetryLater(self): setReviewTimeUnit(2000) score = {'score' : 3, 'proof' : "sdsd", 'time' : 0} playerId = "test1" createPlayer(playerId, playerId) service.start(playerId) service.setScore(playerId, score) score = {'score' : 3, 'proof' : "sdsd", 'time' : 0} playerId = "test2" createPlayer(playerId, playerId) service.start(playerId) service.setScore(playerId, score) createPlayer("reviewer1", "reviewer1") sleep(3) service.getRandomScore("reviewer1") response= service.getRandomScore("reviewer1") # TODO : expect a KeyError for retry self.assertFalse('result' in response and response['result']['retry'] > 0)