Пример #1
0
    def test_saving_and_retrieving_final_choices_keeps_same_door_number(self):
        user_test = User.objects.create_user('george', '', 'somethingpassword')
        user_test.save()
        trial = Trial()
        trial.user = user_test
        trial.save()
        first_choice = Choice()
        first_choice.door_number = 3
        first_choice.first_or_second_choice = 1
        first_choice.trial = trial
        first_choice.save()

        # keeps same number
        final_choice = Choice()
        final_choice.door_number = 3
        final_choice.first_or_second_choice = 2
        final_choice.trial = trial
        final_choice.save()

        first_saved_choice = Choice.objects.get(trial=trial,
                                                first_or_second_choice=1)
        final_saved_choice = Choice.objects.get(trial=trial,
                                                first_or_second_choice=2)

        self.assertEqual(first_saved_choice.door_number, 3)
        self.assertEqual(first_saved_choice.first_or_second_choice, 1)
        self.assertEqual(final_saved_choice.door_number, 3)
        self.assertEqual(final_saved_choice.first_or_second_choice, 2)
    def test_two_users_use_at_same_time_two_choices_made_for_each_trial(self):
        self.login_temp()
        User = get_user_model()
        user_one = User.objects.get(username='******')
        
        trial_one = Trial()
        trial_one.user = user_one
        trial_one.save()

        response = self.client.post(
            '/user/temporary/door_page_one', {'door_chosen': 1}
        )
        self.assertEqual(Choice.objects.count(), 1)

        #!!---------------!!
        #Improve this test to check each choice corresdponds to the right choice

        user_two = User.objects.create_user('Dolores',
                                            '*****@*****.**',
                                            'por_su_abuela_catalan')
        self.client.login(username='******', password='******')
        
        trial_two = Trial()
        trial_two.user = user_two
        trial_two.save()

        response = self.client.post(
            '/user/Dolores/door_page_one', {'door_chosen': 2}
        )
        self.assertEqual(Choice.objects.count(), 2)
Пример #3
0
    def test_saving_and_retrieving_user_name_from_choices(self):
        user_test_one = User.objects.create_user('george', '',
                                                 'somethingpassword')
        user_test_one.save()
        first_trial = Trial()
        first_trial.user = user_test_one
        first_trial.save()
        first_choice = Choice()
        first_choice.door_number = 1
        first_choice.trial = first_trial
        first_choice.save()

        user_test_two = User.objects.create_user('brian', '',
                                                 'not-the-messiah')
        user_test_two.save()
        second_trial = Trial()
        second_trial.user = user_test_two
        second_trial.save()
        second_choice = Choice()
        second_choice.door_number = 2
        second_choice.trial = second_trial
        second_choice.save()

        saved_choices = Choice.objects.all()
        self.assertEqual(saved_choices.count(), 2)

        first_saved_choice = saved_choices[0]
        first_saved_trial = first_saved_choice.trial
        first_saved_user = first_saved_trial.user
        second_saved_choice = saved_choices[1]
        second_saved_trial = second_saved_choice.trial
        second_saved_user = second_saved_trial.user

        self.assertEqual(first_saved_user, user_test_one)
        self.assertEqual(second_saved_user, user_test_two)
Пример #4
0
    def test_saving_and_retrieving_trials(self):
        user_test = User.objects.create_user('george', '', 'somethingpassword')
        user_test.save()
        first_trial = Trial()
        first_trial.user = user_test
        first_trial.save()

        saved_trials = Trial.objects.all()
        self.assertEqual(saved_trials.count(), 1)
        first_saved_trial = saved_trials[0]
        first_saved_user = first_saved_trial.user
        self.assertEqual(first_saved_user, user_test)
Пример #5
0
 def test_trial_make(self):
     # set up the users
     user_test_one = User.objects.create_user('Acho', '', 'tu_ajedrez')
     user_test_one.save()
     trial = Trial()
     trial.user = user_test_one
     trial.save()
     trials_for_this_user = Trial.objects.filter(user=user_test_one)
     self.assertEqual(len(trials_for_this_user), 1)
     trial_two = Trial()
     trial_two.user = user_test_one
     trial_two.save()
     new_trials_for_this_user = Trial.objects.filter(user=user_test_one)
     self.assertEqual(len(new_trials_for_this_user), 2)
Пример #6
0
    def test_result_saves_trial(self):
        user_test = User.objects.create_user('george', '', 'somethingpassword')
        user_test.save()
        first_trial = Trial()
        first_trial.user = user_test
        first_trial.save()
        first_result = Result()
        first_result.trial = first_trial
        first_result.save()

        saved_results = Result.objects.all()
        self.assertEqual(saved_results.count(), 1)
        first_saved_result = saved_results[0]
        first_saved_trial = first_saved_result.trial
        self.assertEqual(first_saved_trial, first_trial)
Пример #7
0
    def test_choice_saves_trial(self):
        user_test = User.objects.create_user('george', '', 'somethingpassword')
        user_test.save()
        first_trial = Trial()
        first_trial.user = user_test
        first_trial.save()

        first_choice = Choice()
        first_choice.trial = first_trial
        first_choice.save()

        saved_choices = Choice.objects.all()
        self.assertEqual(saved_choices.count(), 1)
        first_saved_choice = saved_choices[0]
        first_saved_trial = first_saved_choice.trial
        self.assertEqual(first_saved_trial, first_trial)
 def test_can_choose_final_patten(self):
     self.login_temp()
     User = get_user_model()
     user_one = User.objects.get(username='******')
     trial = Trial()
     trial.user = user_one
     trial.save()
     response = self.client.post(
         '/final_pattern',
         {
             'box_1': False,
             'box_2': True,
             'trial': trial,
         }
     )
     self.assertEqual(MemoryGame.objects.count(), 1)
     saved_memory_game = MemoryGame.objects.get()
     self.assertEqual(False, saved_memory_game.box_1)
     self.assertEqual(True, saved_memory_game.box_2)
Пример #9
0
    def test_trial_saves_number(self):
        user_test = User.objects.create_user('george', '', 'somethingpassword')
        user_test.save()
        first_trial = Trial()
        first_trial.user = user_test
        first_trial.number_of_trial = 1
        first_trial.save()

        saved_trials = Trial.objects.all()
        self.assertEqual(saved_trials.count(), 1)
        first_saved_trial = saved_trials[0]
        first_saved_number_of_trial = first_saved_trial.number_of_trial
        self.assertEqual(first_saved_number_of_trial, 1)
    def test_home_page_gives_trial_number_two_for_second_trial(self):
        user_test = User.objects.create_user('george', '', 'somethingpassword')
        user_test.save()
        first_trial = Trial()
        first_trial.user = user_test
        first_trial.number_of_trial = 1
        first_trial.save()

        #User = get_user_model()
        self.client.login(username='******', password='******')
        response = self.client.get('/user', follow=True)

        html = response.content.decode('utf8')
        self.assertIn('Trial number 2', html)
Пример #11
0
def memory_game_start(request, trial_completed):
    user_logged_in = request.user
    username_logged_in = request.user.username

    #trials_completed = user_logged_in.profile.trials_completed

    # if trials_completed >= TRIAL_LIMIT:
    #    return final_completion()

    number_of_trial = int(trial_completed) + 1
    if number_of_trial > TRIAL_LIMIT:
        return final_completion()

    #number_of_trial = trials_completed + 1

    new_trial = Trial()
    new_trial.user = user_logged_in
    new_trial.number_of_trial = number_of_trial
    new_trial.save()

    very_hard_setting = user_logged_in.profile.low_medium_or_high_dots_setting

    if very_hard_setting in four_by_four_setting_list:
        MemoryGameToGet = MemoryGameHigh
    else:
        MemoryGameToGet = MemoryGame

    memory_game_list_from_setup = MemoryGameList.objects.get(
        user=user_logged_in)

    memory_game = MemoryGameToGet.objects.get(
        memory_game_list=memory_game_list_from_setup,
        number_of_trial=number_of_trial
    )
    memory_game.trial = new_trial
    memory_game.save()

    if very_hard_setting in four_by_four_setting_list:
        home_page_string = 'home_four_by_four.html'

    else:
        home_page_string = 'home.html'

    return render(request, home_page_string, {
        "username": username_logged_in,
        "number_of_trial": number_of_trial,
        "memory_game": memory_game,
    })
    def test_saves_user_in_post_request(self):
        self.login_temp()
        user = User.objects.get(username='******')
        trial = Trial()
        trial.user = user
        trial.number_of_trial = 1
        trial.save()

        response = self.client.post('/user/temporary/door_page_one', {
            'door_chosen': 2,
        })

        self.assertEqual(Choice.objects.count(), 1)
        new_choice = Choice.objects.last()
        self.assertEqual(new_choice.door_number, 2)
        trial = new_choice.trial
        self.assertEqual(trial.user, user)
Пример #13
0
def home_page_memory_game(request, username):

    # logout_if_reached_the_limit(request)
    user_logged_in = request.user
    if user_logged_in.profile.trials_completed >= TRIAL_LIMIT:
        return final_completion(request)

    trials_for_this_user = Trial.objects.filter(user=user_logged_in)
    if len(trials_for_this_user) != 0:
        latest_trial = trials_for_this_user.last()

        if latest_trial.number_of_trial >= TRIAL_LIMIT:
            return final_completion(request)

        else:
            pass

    username_logged_in = request.user.username
    user_logged_in = request.user

    if request.method == 'POST':
        # insert method to remember pattern here (if necessary)
        return redirect('/user/' + username_logged_in + '/door-page-one')

    else:

        memory_game_list_prelim = MemoryGameList.objects.filter(
            user=user_logged_in)
        print(f'first instance of memory game list {memory_game_list_prelim}')
        if len(memory_game_list_prelim) == 0:
            print('len of memory game list was 0, so creating new memory_game_list model')
            memory_game_list = MemoryGameList()
            memory_game_list.user = user_logged_in
            memory_game_list.save()

            # find whether user is registered as easy or hard dot list
            if user_logged_in.profile:
                hard_or_easy_dot_list = user_logged_in.profile.hard_or_easy_dots
                very_hard_dot_list_setting = user_logged_in.profile.low_medium_or_high_dots_setting

                print(f'setting:{very_hard_dot_list_setting}')

                if very_hard_dot_list_setting == "very_hard":
                    print('very_hard_setting_activated in home_page_memory_game')
                    add_four_by_four_memory_games(
                        memory_game_list, dot_list="very_hard")
                elif very_hard_dot_list_setting == "medium":
                    print('4 by 4 medium setting activated in home_page_memory_game')
                    add_four_by_four_memory_games(
                        memory_game_list, dot_list="medium")
                elif very_hard_dot_list_setting == "very_easy":
                    print('4 by 4 very_easy setting activated in home_page_memory_game')
                    add_four_by_four_memory_games(
                        memory_game_list, dot_list="very_easy")

                elif hard_or_easy_dot_list == "easy":
                    add_memory_games(memory_game_list, "easy")
                elif hard_or_easy_dot_list == "hard":
                    add_memory_games(memory_game_list, "hard")
                else:
                    print(
                        "Error: hard_or_easy_dots setting in incorrect format in Profile model")
                    print("Adding hard list")
                    add_memory_games(memory_game_list, dot_list="hard")
            else:
                add_memory_games(memory_game_list, dot_list="hard")
            memory_game_list = [memory_game_list]
        else:
            memory_game_list = memory_game_list_prelim

        trial = Trial()
        trial.user = request.user

        trials_for_this_user = Trial.objects.filter(user=user_logged_in)
        latest_trial = trials_for_this_user.last()
        if len(trials_for_this_user) != 0:
            number_of_trial = latest_trial.number_of_trial + 1
        else:
            number_of_trial = 0
        trial.number_of_trial = number_of_trial
        trial.save()

        # !!!!!----- This is the bit I need to change so
        # that it's seeing the different patterns
        # insert some method here to generate the pattern

        if len(memory_game_list) != 0:

            very_hard_setting = user_logged_in.profile.low_medium_or_high_dots_setting

            if very_hard_setting in four_by_four_setting_list:
                MemoryGameToSave = MemoryGameHigh
            else:
                MemoryGameToSave = MemoryGame

            memory_game_list_end = MemoryGameToSave.objects.filter(
                memory_game_list=memory_game_list[0],
                number_of_trial=number_of_trial
            )
            if len(memory_game_list_end) != 0:
                memory_game = memory_game_list_end[0]
            else:
                # This is a bit of a hack to stop it crashing when
                # people log in after completing everything.
                return final_completion(request)
            memory_game.trial = trial
            memory_game.save()

    # find if prelim has been completed
    prelim_completed_bool = user_logged_in.profile.prelim_completed 


    if number_of_trial == 0 or prelim_completed_bool == False:
        return render(request, 'terms_and_conditions.html', {
            "username": username_logged_in,
            "number_of_trial": number_of_trial,
            "memory_game": memory_game,
        }
        )

    return render(request, 'home.html', {
        "username": username_logged_in,
        "number_of_trial": number_of_trial,
        "memory_game": memory_game,
    })
Пример #14
0
    def test_two_users_create_models_at_same_time(self):
        # set up the users
        user_test_one = User.objects.create_user('Acho', '', 'tu_ajedrez')
        user_test_one.save()
        user_test_two = User.objects.create_user('Darren', '',
                                                 'just_a_sea_between_us')
        user_test_two.save()

        # set up a trial for each user
        trial_user_one = Trial()
        trial_user_one.user = user_test_one
        trial_user_one.save()
        trial_user_two = Trial()
        trial_user_two.user = user_test_two
        trial_user_two.save()

        # assign a first choice for each trial of each user
        choice_one_user_one = Choice()
        choice_one_user_one.trial = trial_user_one
        choice_one_user_one.first_or_second_choice = 1
        choice_one_user_one.door_number = 1
        choice_one_user_one.save()

        choice_one_user_two = Choice()
        choice_one_user_two.trial = trial_user_two
        choice_one_user_two.first_or_second_choice = 1
        choice_one_user_two.door_number = 2
        choice_one_user_two.save()

        # save a result for each user
        result_user_one = Result()
        result_user_one.trial = trial_user_one
        result_user_one.door_number = 3
        result_user_one.save()

        result_user_two = Result()
        result_user_two.trial = trial_user_two
        result_user_two.door_number = 1
        result_user_two.save()

        # save a second choice for each user
        final_choice_user_one = Choice()
        final_choice_user_one.trial = trial_user_one
        final_choice_user_one.first_or_second_choice = 2
        final_choice_user_one.door_number = 4
        final_choice_user_one.save()

        final_choice_user_two = Choice()
        final_choice_user_two.trial = trial_user_two
        final_choice_user_two.first_or_second_choice = 2
        final_choice_user_two.door_number = 5
        final_choice_user_two.save()

        # check results are consistent
        # check trials saved correctly
        saved_trial_user_one = Trial.objects.get(user=user_test_one)
        self.assertEqual(saved_trial_user_one, trial_user_one)
        saved_trial_user_two = Trial.objects.get(user=user_test_two)
        self.assertEqual(saved_trial_user_two, trial_user_two)

        # check first choices saved correctly
        saved_choice_one_user_one = Choice.objects.get(
            trial=saved_trial_user_one,
            first_or_second_choice=1,
        )
        saved_choice_one_user_two = Choice.objects.get(
            trial=saved_trial_user_two,
            first_or_second_choice=1,
        )
        self.assertEqual(saved_choice_one_user_one, choice_one_user_one)
        self.assertEqual(saved_choice_one_user_two, choice_one_user_two)

        # check second choices saved correctly
        saved_final_choice_user_one = Choice.objects.get(
            trial=saved_trial_user_one, first_or_second_choice=2)
        saved_final_choice_user_two = Choice.objects.get(
            trial=saved_trial_user_two, first_or_second_choice=2)

        self.assertEqual(saved_final_choice_user_one, final_choice_user_one)
        self.assertEqual(saved_final_choice_user_two, final_choice_user_two)

        saved_result_one = Result.objects.get(trial=saved_trial_user_one)
        saved_result_two = Result.objects.get(trial=saved_trial_user_two)
        self.assertEqual(saved_result_one, result_user_one)
        self.assertEqual(saved_result_two, result_user_two)
    def test_two_users_use_at_same_time_make_initial_choice(self):
        self.login_temp()
        User = get_user_model()
        user_one = User.objects.get(username='******')

        trial_user_one = Trial()
        trial_user_one.user = user_one
        trial_user_one.number_of_trial = 1
        trial_user_one.save()

        response = self.client.post(
            '/user/temporary/door_page_one', {'door_chosen': 1}
        )


        user_two = User.objects.create_user('Dolores',
                                            '*****@*****.**',
                                            'por_su_abuela_catalan')
        trial_user_two = Trial()
        trial_user_two.user = user_two
        trial_user_two.number_of_trial = 1
        trial_user_two.save()
        self.client.login(username='******', password='******')
        response = self.client.post(
            '/user/Dolores/door_page_one', {'door_chosen': 2}
        )

        saved_trial_user_one = Trial.objects.get(
            user=user_one)
        saved_trial_user_two = Trial.objects.get(
            user=user_two)

        saved_choice_user_one = Choice.objects.get(
            trial=saved_trial_user_one)
        saved_choice_user_two = Choice.objects.get(
            trial=saved_trial_user_two)
        self.assertEqual(saved_choice_user_one.door_number, 1)
        self.assertEqual(saved_choice_user_two.door_number, 2)
    def test_two_users_at_same_time_make_second_choice(self):
        # set up inital saved data on db
        # set up the users
        user_test_one = User.objects.create_user(
            'Acho',
            '',
            'tu_ajedrez')
        user_test_one.save()
        user_test_two = User.objects.create_user(
            'Darren',
            '',
            'just_a_sea_between_us')
        user_test_two.save()

        # set up a trial for each user
        trial_user_one = Trial()
        trial_user_one.user = user_test_one
        trial_user_one.save()
        trial_user_two = Trial()
        trial_user_two.user = user_test_two
        trial_user_two.save()

        # assign a first choice for each trial of each user
        choice_one_user_one = Choice()
        choice_one_user_one.trial = trial_user_one
        choice_one_user_one.first_or_second_choice = 1
        choice_one_user_one.door_number = 1
        choice_one_user_one.save()

        choice_one_user_two = Choice()
        choice_one_user_two.trial = trial_user_two
        choice_one_user_two.first_or_second_choice = 1
        choice_one_user_two.door_number = 2
        choice_one_user_two.save()

        # save a result for each user
        result_user_one = Result()
        result_user_one.trial = trial_user_one
        result_user_one.door_number = 3
        result_user_one.save()

        result_user_two = Result()
        result_user_two.trial = trial_user_two
        result_user_two.door_number = 1
        result_user_two.save()

        self.client.login(username='******', password='******')
        response_one = self.client.post(
            '/user/Acho/door-result', {'door_chosen': 4}
        )
        self.client.login(username='******',
                          password='******'
                          )
        response_two = self.client.post(
            '/user/Darren/door-result', {'door_chosen': 5}
        )

        # check has saved 2 choices for each user
        saved_choices = Choice.objects.all()
        username_list = []
        for choice in saved_choices:
            username_list.append(choice.trial.user.username)
        self.assertEqual(username_list.count('Acho'), 2)
        self.assertEqual(username_list.count('Darren'), 2)

        # retrieve saved second choices
        '''
Пример #17
0
def memory_game_initial_turn(request):
    user_logged_in = request.user
    username_logged_in = request.user.username

    memory_game_list_prelim = MemoryGameList.objects.filter(
        user=user_logged_in)
    print(f'first instance of memory game list {memory_game_list_prelim}')

    # check so it doesn't run this script again
    if len(memory_game_list_prelim) == 0:
        print('len of memory game list was 0, so creating new memory_game_list model')
        memory_game_list = MemoryGameList()
        memory_game_list.user = user_logged_in
        memory_game_list.save()

        # find whether user is registered as easy or hard dot list
        if user_logged_in.profile:
            hard_or_easy_dot_list = user_logged_in.profile.hard_or_easy_dots
            very_hard_dot_list_setting = user_logged_in.profile.low_medium_or_high_dots_setting
            print(f'setting:{very_hard_dot_list_setting}')

            if very_hard_dot_list_setting == "very_hard":
                print('very_hard_setting_activated in memory_game_initial_turn')
                add_four_by_four_memory_games(
                    memory_game_list, dot_list == "very_hard")
            elif very_hard_dot_list_setting == "medium":
                print('4 by 4 medium setting activated in memory_game_initial_turn')
                add_four_by_four_memory_games(
                    memory_game_list, dot_list == "medium")
            elif very_hard_dot_list_setting == "very_easy":
                print('4 by 4 very_easy setting activated in memory_game_initial_turn')
                add_four_by_four_memory_games(
                    memory_game_list, dot_list == "very_easy")
            elif hard_or_easy_dot_list == "easy":
                add_memory_games(memory_game_list, "easy")
            elif hard_or_easy_dot_list == "hard":
                print("hard setting activated")
                add_memory_games(memory_game_list, "hard")
            else:
                print(
                    "Error: hard_or_easy_dots setting in incorrect format in Profile model")
                print("Adding hard list")
                add_memory_games(memory_game_list, dot_list="hard")
        else:
            print("profile not logged in, so hard setting activated as backup")
            add_memory_games(memory_game_list, dot_list="hard")
        memory_game_list = [memory_game_list]
    else:
        memory_game_list = memory_game_list_prelim

    trial = Trial()
    trial.user = request.user

    trials_for_this_user = Trial.objects.filter(user=user_logged_in)
    latest_trial = trials_for_this_user.last()
    if len(trials_for_this_user) != 0:
        number_of_trial = latest_trial.number_of_trial + 1
    else:
        number_of_trial = 1
    trial.number_of_trial = number_of_trial
    trial.save()

    very_hard_setting = user_logged_in.profile.low_medium_or_high_dots_setting

    if very_hard_setting in four_by_four_setting_list:
        home_page_string = 'home_four_by_four.html'
        MemoryGameToSave = MemoryGameHigh
    else:
        home_page_string = 'home.html'
        MemoryGameToSave = MemoryGame

    if len(memory_game_list) != 0:
        memory_game_list_end = MemoryGameToSave.objects.filter(
            memory_game_list=memory_game_list[0],
            number_of_trial=number_of_trial
        )
        memory_game = memory_game_list_end[0]
        memory_game.trial = trial
        memory_game.save()


    return render(request, home_page_string, {
        "username": username_logged_in,
        "number_of_trial": number_of_trial,
        "memory_game": memory_game,
    })