Exemple #1
0
    def setUp(self):
        # Add each other as friends
        for i in range(4):
            user_id1 = login.login(username='******'+str(i), password='******'+str(i)).user_id
            for j in range(i+1, 5):
                user_id2 = login.login(username='******'+str(j), password='******'+str(j)).user_id
                friend.add_friend(user_id=user_id1, friend_id=user_id2)

        self.saved_file_path = config.FILE_PATH
        self.saved_max_score_guessing = config.MAX_SCORE_GUESSING
        self.saved_min_score_guessing = config.MIN_SCORE_GUESSING
        self.saved_score_sending = config.SCORE_SENDING
        self.saved_score_guessing_time = config.SCORE_GUESSING_TIME
        self.saved_score_per_star = config.SCORE_PER_STAR
        self.saved_score_delta = config.SCORE_DELTA
        self.saved_tie_bonus_star = config.TIE_BONUS_STAR
        self.saved_winner_bonus_star = config.WINNER_BONUS_STAR
        self.saved_max_rounds = config.MAX_ROUNDS

        config.FILE_PATH = '/var/www/picturethis/media_test/'
        config.MAX_SCORE_GUESSING = 100
        config.MIN_SCORE_GUESSING = 50
        config.SCORE_SENDING = 25
        config.SCORE_GUESSING_TIME = 5000 # milliseconds
        config.SCORE_PER_STAR = 25
        config.SCORE_DELTA = 20
        config.TIE_BONUS_STAR = 1
        config.WINNER_BONUS_STAR = 2
        config.MAX_ROUNDS = 2
Exemple #2
0
    def testBlockFriends(self):
        user0 = User.objects.get(name='user0')
        user0_id = user0.obfuscated_id

        for i in range(1, 5):
            username = '******' + str(i)
            user_id = User.objects.get(name=username).obfuscated_id

            friend.add_friend(user_id=user0_id, friend_id=user_id)

            self.assertEqual(friend.get_friend_status(user_id1=user0_id, user_id2=user_id), config.FRIEND_STATUS_FRIEND)
            self.assertEqual(friend.get_friend_status(user_id1=user_id, user_id2=user0_id), config.FRIEND_STATUS_FRIEND)

            self.assertEqual(friend.get_friend_details(user_id=user0_id, friend_id=user_id).relation, config.FRIEND_STATUS_FRIEND)
            self.assertEqual(friend.get_friend_details(user_id=user_id, friend_id=user0_id).relation, config.FRIEND_STATUS_FRIEND)

            self.assertEqual(search.find_user(user_id=user0_id, username=username).relation, config.FRIEND_STATUS_FRIEND)
            self.assertEqual(search.find_user(user_id=user_id, username='******').relation, config.FRIEND_STATUS_FRIEND)

        user0_friends = friend.get_user_friends(user_id=user0_id)

        self.assertEqual(len(user0_friends.friends), 4)

        for i in range(1, 5):
            username = '******' + str(i)
            user_id = User.objects.get(name=username).obfuscated_id

            friend.block_friend(user_id=user0_id, friend_id=user_id)

            self.assertEqual(friend.get_friend_status(user_id1=user0_id, user_id2=user_id), config.FRIEND_STATUS_BLOCKED)
            self.assertEqual(friend.get_friend_status(user_id1=user_id, user_id2=user0_id), config.FRIEND_STATUS_REMOVED)

            self.assertEqual(friend.get_friend_details(user_id=user0_id, friend_id=user_id).relation, config.FRIEND_STATUS_BLOCKED)
            # the other user should not know that the first user exists
            self.assertRaises(RemoteException, friend.get_friend_details, user_id=user_id, friend_id=user0_id)

            self.assertEqual(search.find_user(user_id=user0_id, username=username).relation, config.FRIEND_STATUS_BLOCKED)
            # second user can't search for the first user
            self.assertRaises(RemoteException, search.find_user, user_id=user_id, username='******')

            # second user can't add first user as a friend
            self.assertRaises(RemoteException, friend.add_friend, user_id=user_id, friend_id=user0_id)

            # but if first user adds second user as a friend, they're friends again
            friend.add_friend(user_id=user0_id, friend_id=user_id)

            self.assertEqual(friend.get_friend_status(user_id1=user0_id, user_id2=user_id), config.FRIEND_STATUS_FRIEND)
            self.assertEqual(friend.get_friend_status(user_id1=user_id, user_id2=user0_id), config.FRIEND_STATUS_FRIEND)

            self.assertEqual(friend.get_friend_details(user_id=user0_id, friend_id=user_id).relation, config.FRIEND_STATUS_FRIEND)
            self.assertEqual(friend.get_friend_details(user_id=user_id, friend_id=user0_id).relation, config.FRIEND_STATUS_FRIEND)

            self.assertEqual(search.find_user(user_id=user0_id, username=username).relation, config.FRIEND_STATUS_FRIEND)
            self.assertEqual(search.find_user(user_id=user_id, username='******').relation, config.FRIEND_STATUS_FRIEND)
Exemple #3
0
    def testRemoveFriends(self):
        user0 = User.objects.get(name='user0')
        user0_id = user0.obfuscated_id

        for i in range(1, 5):
            username = '******' + str(i)
            user_id = User.objects.get(name=username).obfuscated_id

            friend.add_friend(user_id=user0_id, friend_id=user_id)

            self.assertEqual(friend.get_friend_status(user_id1=user0_id, user_id2=user_id), config.FRIEND_STATUS_FRIEND)
            self.assertEqual(friend.get_friend_status(user_id1=user_id, user_id2=user0_id), config.FRIEND_STATUS_FRIEND)

            self.assertEqual(friend.get_friend_details(user_id=user0_id, friend_id=user_id).relation, config.FRIEND_STATUS_FRIEND)
            self.assertEqual(friend.get_friend_details(user_id=user_id, friend_id=user0_id).relation, config.FRIEND_STATUS_FRIEND)

            self.assertEqual(search.find_user(user_id=user0_id, username=username).relation, config.FRIEND_STATUS_FRIEND)
            self.assertEqual(search.find_user(user_id=user_id, username='******').relation, config.FRIEND_STATUS_FRIEND)

        user0_friends = friend.get_user_friends(user_id=user0_id)

        self.assertEqual(len(user0_friends.friends), 4)

        for i in range(1, 5):
            username = '******' + str(i)
            user_id = User.objects.get(name=username).obfuscated_id

            friend.remove_friend(user_id=user0_id, friend_id=user_id)

            self.assertEqual(friend.get_friend_status(user_id1=user0_id, user_id2=user_id), config.FRIEND_STATUS_REMOVED)
            self.assertEqual(friend.get_friend_status(user_id1=user_id, user_id2=user0_id), config.FRIEND_STATUS_REMOVED)

            self.assertEqual(friend.get_friend_details(user_id=user0_id, friend_id=user_id).relation, config.FRIEND_STATUS_REMOVED)
            self.assertEqual(friend.get_friend_details(user_id=user_id, friend_id=user0_id).relation, config.FRIEND_STATUS_REMOVED)

            self.assertEqual(search.find_user(user_id=user0_id, username=username).relation, config.FRIEND_STATUS_REMOVED)
            self.assertEqual(search.find_user(user_id=user_id, username='******').relation, config.FRIEND_STATUS_REMOVED)

            # They can add each other as friends again
            friend.add_friend(user_id=user_id, friend_id=user0_id)

            self.assertEqual(friend.get_friend_status(user_id1=user0_id, user_id2=user_id), config.FRIEND_STATUS_FRIEND)
            self.assertEqual(friend.get_friend_status(user_id1=user_id, user_id2=user0_id), config.FRIEND_STATUS_FRIEND)

            self.assertEqual(friend.get_friend_details(user_id=user0_id, friend_id=user_id).relation, config.FRIEND_STATUS_FRIEND)
            self.assertEqual(friend.get_friend_details(user_id=user_id, friend_id=user0_id).relation, config.FRIEND_STATUS_FRIEND)

            self.assertEqual(search.find_user(user_id=user0_id, username=username).relation, config.FRIEND_STATUS_FRIEND)
            self.assertEqual(search.find_user(user_id=user_id, username='******').relation, config.FRIEND_STATUS_FRIEND)
Exemple #4
0
    def testGetAllFriends(self):
        user0_id = User.objects.get(name='user0').obfuscated_id
        user1_id = User.objects.get(name='user1').obfuscated_id
        user2_id = User.objects.get(name='user2').obfuscated_id
        user3_id = User.objects.get(name='user3').obfuscated_id
        user4_id = User.objects.get(name='user4').obfuscated_id

        friend.add_friend(user_id=user0_id, friend_id=user1_id)
        friend.add_friend(user_id=user2_id, friend_id=user0_id)
        friend.add_friend(user_id=user0_id, friend_id=user3_id)
        friend.add_friend(user_id=user4_id, friend_id=user0_id)

        self.assertEqual(len(friend.get_user_friends(user0_id).friends), 4)
Exemple #5
0
    def testUpdate(self):
        user0_id = User.objects.get(name='user0').obfuscated_id
        user1_id = User.objects.get(name='user1').obfuscated_id
        user2_id = User.objects.get(name='user2').obfuscated_id
        user3_id = User.objects.get(name='user3').obfuscated_id
        user4_id = User.objects.get(name='user4').obfuscated_id

        friend.add_friend(user_id=user0_id, friend_id=user1_id)
        friend.add_friend(user_id=user2_id, friend_id=user0_id)
        friend.add_friend(user_id=user0_id, friend_id=user3_id)
        friend.add_friend(user_id=user4_id, friend_id=user0_id)

        self.assertEqual(len(poll.update(user_id=user0_id).friends), 4)

        friend.remove_friend(user_id=user2_id, friend_id=user0_id)
        friend.block_friend(user_id=user0_id, friend_id=user3_id)
        friend.block_friend(user_id=user4_id, friend_id=user0_id)

        self.assertEqual(len(poll.update(user_id=user0_id).friends), 1)

        self.assertRaises(poll.update, user_id=-1)
    hrline()
    userChoice = input('Option: ')
    return userChoice


menuLoop = 'true'
while (menuLoop == 'true'):
    userChoice = user_menu()
    if userChoice == '3':
        display_post_file(), hrline()
    if userChoice == '4':
        new_post(), hrline()
    if userChoice == '5':
        delete_post(), hrline()
    if userChoice == '6':
        add_post_from_user()
    if userChoice == '7':
        display_list_of_friend()
    if userChoice == '8':
        add_friend()
    if userChoice == '9':
        remove_friend_from_list()
    if userChoice == 'R' or userChoice == 'r':
        reset_data()
    if userChoice == 'E' or userChoice == 'e':
        export_to_txt()
    if userChoice == 'i' or userChoice == 'i':
        import_to_csv()
    if userChoice == 'X' or userChoice == 'x':
        exit()
Exemple #7
0
    def testStartNewGame(self):
        user1_id = User.objects.get(name='user1').obfuscated_id
        user2_id = User.objects.get(name='user2').obfuscated_id
        game_remote = game.start_new_game(user_id=user1_id, friend_id=user2_id)

        try:
            game_model = Game.objects.get(user_id1=user1_id, user_id2=user2_id)
        except Game.DoesNotExist:
            self.fail("Game not found")

        self.assertTrue(game_remote.active)
        self.assertTrue(game_model.active)

        self.assertEqual(game_remote.curr_round, 1)
        self.assertEqual(game_model.curr_round, 1)

        self.assertEqual(game_remote.is_photographer, 1)
        self.assertEqual(game_remote.is_turn, 1)

        self.assertRaises(RemoteException, game.start_new_game, user_id=user1_id, friend_id=user1_id)
        self.assertRaises(RemoteException, game.start_new_game, user_id=user1_id, friend_id=user2_id)
        self.assertRaises(RemoteException, game.start_new_game, user_id=user2_id, friend_id=user1_id)

        # Assert game is active
        self.assertTrue(game._is_active_game(user_id1=user1_id, user_id2=user2_id))

        # Remove friend
        friend.remove_friend(user_id=user1_id, friend_id=user2_id)

        # No active game between users now
        self.assertFalse(game._is_active_game(user_id1=user1_id, user_id2=user2_id))

        # Add friend back
        friend.add_friend(user_id=user1_id, friend_id=user2_id)

        # Game is not reactivated
        self.assertFalse(game._is_active_game(user_id1=user1_id, user_id2=user2_id))

        # Start a new game
        game_remote = game.start_new_game(user_id=user1_id, friend_id=user2_id)

        self.assertTrue(game_remote.active)
        self.assertTrue(game_model.active)

        self.assertEqual(game_remote.curr_round, 1)
        self.assertEqual(game_model.curr_round, 1)

        self.assertEqual(game_remote.is_photographer, 1)
        self.assertEqual(game_remote.is_turn, 1)

        # Assert game is active
        self.assertTrue(game._is_active_game(user_id1=user1_id, user_id2=user2_id))

        # Block friend
        friend.block_friend(user_id=user1_id, friend_id=user2_id)

        # No active game between users now
        self.assertFalse(game._is_active_game(user_id1=user1_id, user_id2=user2_id))

        # Add friend back
        friend.add_friend(user_id=user1_id, friend_id=user2_id)

        # Game is not reactivated
        self.assertFalse(game._is_active_game(user_id1=user1_id, user_id2=user2_id))