Ejemplo n.º 1
0
    def test_page(self):
        from dbas.views import review_history as d

        request = testing.DummyRequest()
        response = d(request)
        verify_dictionary_of_view(response)

        self.assertIn('history', response)
        self.assertTrue(len(response['history']) == 0)
Ejemplo n.º 2
0
    def test_page(self):
        request = testing.DummyRequest()
        response = settings(request)
        verify_dictionary_of_view(response)

        # check settings
        self.assertIn('send_notifications', response['settings'])
        self.assertIn('send_mails', response['settings'])
        self.assertIn('public_nick', response['settings'])
Ejemplo n.º 3
0
    def test_page(self):
        request = construct_dummy_request()
        response = discussion_overview(request)
        verify_dictionary_of_view(response)

        self.assertIn('title', response)
        self.assertIn('project', response)
        self.assertIn('extras', response)
        self.assertIn('issues', response)
Ejemplo n.º 4
0
    def test_page_other(self):
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)
        db_user = DBDiscussionSession.query(User).filter_by(nickname='Christian').first()

        request = construct_dummy_request(matchdict={'uid': db_user.uid})
        response = user(request)
        verify_dictionary_of_view(response)
        self.assertIn('user', response)
        self.assertIn('can_send_notification', response)
        self.assertTrue(response['can_send_notification'])
Ejemplo n.º 5
0
    def test_page(self):
        db_user = DBDiscussionSession.query(User).filter_by(
            nickname='Tobias').first()

        request = construct_dummy_request(match_dict={'uid': db_user.uid})
        response = user(request)
        verify_dictionary_of_view(response)
        self.assertIn('user', response)
        self.assertIn('can_send_notification', response)
        self.assertFalse(response['can_send_notification'])
Ejemplo n.º 6
0
    def test_page_logged_in(self):
        from dbas.views import review_history as d
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)

        request = testing.DummyRequest()
        response = d(request)
        verify_dictionary_of_view(response)

        self.assertIn('history', response)
        self.assertTrue(len(response['history']) != 0)
Ejemplo n.º 7
0
    def test_page(self):
        # check count of seen by statements
        len_db_seen1 = DBDiscussionSession.query(SeenStatement).count()

        request = construct_dummy_request(match_dict={'slug': 'cat-or-dog'})
        response = init(request)
        verify_dictionary_of_view(response)

        len_db_seen2 = DBDiscussionSession.query(SeenStatement).count()
        # not logged in, no change
        self.assertEqual(len_db_seen1, len_db_seen2)
Ejemplo n.º 8
0
    def test_page(self):
        from dbas.views import main_user as d
        db_user = DBDiscussionSession.query(User).filter_by(
            nickname='Tobias').first()

        request = testing.DummyRequest(matchdict={'uid': db_user.uid})
        response = d(request)
        verify_dictionary_of_view(response)
        self.assertIn('user', response)
        self.assertIn('can_send_notification', response)
        self.assertFalse(response['can_send_notification'])
Ejemplo n.º 9
0
    def test_page(self):
        from dbas.views import main_discussions_overview as d

        request = testing.DummyRequest()
        response = d(request)
        verify_dictionary_of_view(response)

        self.assertIn('title', response)
        self.assertIn('project', response)
        self.assertIn('extras', response)
        self.assertIn('issues', response)
Ejemplo n.º 10
0
    def test_page(self):
        from dbas.views import main_settings as d

        request = testing.DummyRequest()
        response = d(request)
        verify_dictionary_of_view(response)

        # check settings
        self.assertIn('send_notifications', response['settings'])
        self.assertIn('send_mails', response['settings'])
        self.assertIn('public_nick', response['settings'])
Ejemplo n.º 11
0
    def test_page_optimizations_logged_in(self):
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)
        from dbas.views import review_content as d

        request = testing.DummyRequest(matchdict={'queue': 'optimizations'})
        response = d(request)
        verify_dictionary_of_view(response)
        self.assertTrue(len(response['subpage']['elements']) > 0)
        self.assertFalse(response['subpage']['button_set']['is_delete'])
        self.assertFalse(response['subpage']['button_set']['is_edit'])
        self.assertTrue(response['subpage']['button_set']['is_optimize'])
Ejemplo n.º 12
0
    def test_page(self):
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)
        request = construct_dummy_request()
        response = index(request)
        verify_dictionary_of_view(response)

        self.assertIn('review', response)
        self.assertIn('privilege_list', response)
        self.assertIn('reputation_list', response)
        self.assertIn('reputation', response)
        self.assertTrue(response['reputation']['has_all_rights'])
        self.assertEqual(15, response['reputation']['count'])
Ejemplo n.º 13
0
 def test_dont_know_page(self):
     vote_dict = get_meta_clicks()
     request = construct_dummy_request(
         matchdict={
             'slug': 'cat-or-dog',
             'argument_id': 2,
             'attitude': Attitudes.DONT_KNOW.value,
         })
     response = dontknow_argument(request)
     self.assertNotIsInstance(response, httpexceptions.HTTPError)
     verify_dictionary_of_view(response)
     check_meta_clicks(self, vote_dict)
Ejemplo n.º 14
0
 def test_justify_statement_page(self):
     vote_dict = get_meta_clicks()
     request = construct_dummy_request()
     request.matchdict = {
         'slug': 'cat-or-dog',
         'statement_id': 2,
         'attitude': Attitudes.AGREE.value,
     }
     response = discussion_justify_statement(request)
     self.assertNotIsInstance(response, httpexceptions.HTTPError)
     verify_dictionary_of_view(response)
     check_meta_clicks(self, vote_dict)
Ejemplo n.º 15
0
    def test_page(self):
        from dbas.views import main_review as d

        request = testing.DummyRequest()
        response = d(request)
        verify_dictionary_of_view(response)

        self.assertIn('review', response)
        self.assertIn('privilege_list', response)
        self.assertIn('reputation_list', response)
        self.assertIn('reputation', response)
        self.assertTrue(response['reputation']['has_all_rights'])
        self.assertTrue(type(response['reputation']['count']) is int)
Ejemplo n.º 16
0
    def test_queue_pages_logged_in(self):
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)

        request = construct_dummy_request(matchdict={'queue': 'foobaar'})
        response = queue_details(request)
        self.assertEqual(400, response.status_code)

        for key in review_queues:
            request = construct_dummy_request(matchdict={'queue': key})
            response = queue_details(request)
            self.assertEqual(dict, type(response))
            verify_dictionary_of_view(response)
            self.assertTrue(response['subpage']['button_set']['is_' + key])
Ejemplo n.º 17
0
    def test_page(self):
        from dbas.views import discussion_init as d

        # check count of seen by statements
        len_db_seen1 = DBDiscussionSession.query(SeenStatement).count()

        request = testing.DummyRequest(matchdict={'slug': 'cat-or-dog'})
        response = d(request)
        verify_dictionary_of_view(response)

        len_db_seen2 = DBDiscussionSession.query(SeenStatement).count()
        # not logged in, no change
        self.assertEqual(len_db_seen1, len_db_seen2)
Ejemplo n.º 18
0
    def test_page(self):
        len_db_seen1 = DBDiscussionSession.query(SeenStatement).count()

        request = construct_dummy_request(matchdict={
            'slug': 'cat-or-dog',
            'pgroup_ids': [self.pgroup_uid],
        })
        response = choose(request)
        verify_dictionary_of_view(response)

        len_db_seen2 = DBDiscussionSession.query(SeenStatement).count()
        # not logged in, no change
        self.assertEqual(len_db_seen1, len_db_seen2)
Ejemplo n.º 19
0
 def test_page(self):
     argument_uid = 10
     request = construct_dummy_request(match_dict={
         'argument_id': argument_uid,
         'slug': 'cat-or-dog'
     })
     request.registry.notify = mock.Mock()
     response = finish(request)
     verify_dictionary_of_view(response)
     anonymous_user: User = DBDiscussionSession.query(User).get(1)
     argument: Argument = DBDiscussionSession.query(Argument).filter(
         Argument.uid == argument_uid).first()
     request.registry.notify.assert_called_with(
         UserArgumentAgreement(anonymous_user, argument))
Ejemplo n.º 20
0
    def test_page_failure(self):
        request = construct_dummy_request(params={
            'form.passwordchange.submitted': '',
            'passwordold': 'tobia',
            'password': '******',
            'passwordconfirm': 'tobias'
        })
        response = settings(request)
        verify_dictionary_of_view(response)

        # check settings
        self.assertTrue(len(response['settings']['passwordold']) != 0)
        self.assertTrue(len(response['settings']['password']) != 0)
        self.assertTrue(len(response['settings']['passwordconfirm']) != 0)
Ejemplo n.º 21
0
    def test_page_failure(self):
        from dbas.views import main_settings as d

        request = testing.DummyRequest(
            params={
                'form.passwordchange.submitted': '',
                'passwordold': 'tobia',
                'password': '******',
                'passwordconfirm': 'tobias'
            })
        response = d(request)
        verify_dictionary_of_view(response)

        # check settings
        self.assertTrue(len(response['settings']['passwordold']) != 0)
        self.assertTrue(len(response['settings']['password']) != 0)
        self.assertTrue(len(response['settings']['passwordconfirm']) != 0)
Ejemplo n.º 22
0
    def test_page(self):
        len_db_seen_s1 = DBDiscussionSession.query(SeenStatement).count()
        len_db_votes_s1 = DBDiscussionSession.query(ClickedStatement).count()
        len_db_seen_a1 = DBDiscussionSession.query(SeenArgument).count()
        len_db_votes_a1 = DBDiscussionSession.query(ClickedArgument).count()

        response = discussion_reaction(self.default_request)
        verify_dictionary_of_view(response)

        len_db_seen_s2 = DBDiscussionSession.query(SeenStatement).count()
        len_db_votes_s2 = DBDiscussionSession.query(ClickedStatement).count()
        len_db_seen_a2 = DBDiscussionSession.query(SeenArgument).count()
        len_db_votes_a2 = DBDiscussionSession.query(ClickedArgument).count()
        self.assertEqual(len_db_seen_s1, len_db_seen_s2)  # no more cause we are not logged in
        self.assertEqual(len_db_votes_s1, len_db_votes_s2)
        self.assertEqual(len_db_seen_a1, len_db_seen_a2)
        self.assertEqual(len_db_votes_a1, len_db_votes_a2)
Ejemplo n.º 23
0
    def test_page_logged_in(self):
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)
        DBDiscussionSession.query(User).filter_by(
            nickname='Tobias').first().update_last_login()
        len_db_seen1 = DBDiscussionSession.query(SeenStatement).count()

        request = construct_dummy_request(matchdict={
            'slug': 'cat-or-dog',
            'pgroup_ids': [self.pgroup_uid],
        })
        response = choose(request)
        verify_dictionary_of_view(response)

        len_db_seen2 = DBDiscussionSession.query(SeenStatement).count()

        count = DBDiscussionSession.query(Premise).filter_by(
            premisegroup_uid=self.pgroup_uid).count()
        self.assertEqual(len_db_seen1 + count, len_db_seen2)
Ejemplo n.º 24
0
    def test_page_logged_in(self):
        from dbas.views import discussion_init as d
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)

        # check count of seen by statements
        db_user = DBDiscussionSession.query(User).filter_by(nickname='Tobias').first()
        len_db_seen1 = DBDiscussionSession.query(SeenStatement).filter_by(user_uid=db_user.uid).count()

        request = testing.DummyRequest(matchdict={'slug': 'cat-or-dog'})
        response = d(request)
        verify_dictionary_of_view(response)

        # elements, which were seen
        self.assertIn('elements', response['items'])
        el_count = len(response['items']['elements']) - 1  # -1 for login / add
        len_db_seen2 = DBDiscussionSession.query(SeenStatement).filter_by(user_uid=db_user.uid).count()
        self.assertEqual(len_db_seen1 + el_count, len_db_seen2)
        transaction.commit()  # normally pyramid_tm does this
Ejemplo n.º 25
0
    def test_justify_argument_page_no_rep(self):
        vote_dict = get_meta_clicks()
        len_db_reputation1 = DBDiscussionSession.query(
            ReputationHistory).count()
        request = construct_dummy_request()
        request.matchdict = {
            'slug': 'cat-or-dog',
            'argument_id': 4,
            'attitude': Attitudes.AGREE.value,
            'relation': Relations.UNDERMINE.value,
        }
        response = discussion_justify_argument(request)
        self.assertNotIsInstance(response, httpexceptions.HTTPError)
        verify_dictionary_of_view(response)

        len_db_reputation2 = DBDiscussionSession.query(
            ReputationHistory).count()
        check_meta_clicks(self, vote_dict)
        self.assertEqual(len_db_reputation1, len_db_reputation2)
Ejemplo n.º 26
0
    def test_page_logged_in(self):
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)

        # check count of seen by statements
        db_user = DBDiscussionSession.query(User).filter_by(
            nickname='Tobias').first()
        len_db_seen1 = DBDiscussionSession.query(SeenStatement).filter_by(
            user_uid=db_user.uid).count()

        request = construct_dummy_request(match_dict={'slug': 'cat-or-dog'})
        response = init(request)
        verify_dictionary_of_view(response)

        # elements, which were seen
        self.assertIn('elements', response['items'])
        el_count = len(response['items']['elements']) - 1  # -1 for login / add
        len_db_seen2 = DBDiscussionSession.query(SeenStatement).filter_by(
            user_uid=db_user.uid).count()
        self.assertEqual(len_db_seen1 + el_count, len_db_seen2)
Ejemplo n.º 27
0
    def test_page_logged_in_again(self):
        from dbas.views import discussion_init as d
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)

        # check count of seen by statements
        db_user = DBDiscussionSession.query(User).filter_by(nickname='Tobias').first()
        len_db_seen1 = DBDiscussionSession.query(SeenStatement).filter_by(user_uid=db_user.uid).count()

        request = testing.DummyRequest(matchdict={'slug': 'cat-or-dog'})
        response = d(request)
        verify_dictionary_of_view(response)

        # elements, which were seen are now equals the first, cause we have seen them already
        len_db_seen2 = DBDiscussionSession.query(SeenStatement).filter_by(user_uid=db_user.uid).count()
        self.assertEqual(len_db_seen1, len_db_seen2)

        # remove seen statements
        db_user = DBDiscussionSession.query(User).filter_by(nickname='Tobias').first()
        DBDiscussionSession.query(SeenStatement).filter_by(user_uid=db_user.uid).delete()
        transaction.commit()
Ejemplo n.º 28
0
    def test_page_success(self):
        db_user = DBDiscussionSession.query(User).filter_by(nickname='Tobias').first()
        db_user.password = get_hashed_password('tobias')
        transaction.commit()

        request = construct_dummy_request(params={
            'form.passwordchange.submitted': '',
            'passwordold': 'tobias',
            'password': '******',
            'passwordconfirm': 'tobiass'
        })
        response = settings(request)
        verify_dictionary_of_view(response)

        # check settings
        self.assertTrue(len(response['settings']['passwordold']) == 0)
        self.assertTrue(len(response['settings']['password']) == 0)
        self.assertTrue(len(response['settings']['passwordconfirm']) == 0)

        db_user = DBDiscussionSession.query(User).filter_by(nickname='Tobias').first()
        db_user.password = get_hashed_password('tobias')
        transaction.commit()
Ejemplo n.º 29
0
    def __call_function_and_count_seen_clicked_arguments(self):
        request = construct_dummy_request()
        request.matchdict = {
            'slug': 'cat-or-dog',
            'argument_id': 15,
            'attitude': Attitudes.DISAGREE.value,
            'relation': Relations.UNDERCUT.value,
        }
        seen_arguments_before = DBDiscussionSession.query(SeenArgument).count()
        clicked_arguments_before = DBDiscussionSession.query(
            ClickedArgument).count()

        response = discussion_justify_argument(request)
        self.assertNotIsInstance(response, httpexceptions.HTTPError)
        verify_dictionary_of_view(response)

        self.assertGreater(
            DBDiscussionSession.query(SeenArgument).count(),
            seen_arguments_before)
        self.assertEqual(
            DBDiscussionSession.query(ClickedArgument).count(),
            clicked_arguments_before)
Ejemplo n.º 30
0
    def __check_standard_counting(self, view_fn, db_user):
        count_seen_stmts_before = DBDiscussionSession.query(
            SeenStatement).count()
        count_clicked_stmts_before = DBDiscussionSession.query(
            ClickedStatement).count()
        count_seen_args_before = DBDiscussionSession.query(
            SeenArgument).count()
        count_clicked_args_before = DBDiscussionSession.query(
            ClickedArgument).count()
        count_clicked_args_for_arg_2_before = \
            DBDiscussionSession.query(ClickedArgument).filter(ClickedArgument.author_uid == db_user.uid,
                                                              ClickedArgument.argument_uid == 2,
                                                              ClickedArgument.is_valid == True,
                                                              ClickedArgument.is_up_vote == True).count()

        response = view_fn(self.default_request)
        verify_dictionary_of_view(response)

        count_seen_stmts_after = DBDiscussionSession.query(
            SeenStatement).count()
        count_clicked_stmts_after = DBDiscussionSession.query(
            ClickedStatement).count()
        count_seen_args_after = DBDiscussionSession.query(SeenArgument).count()
        count_clicked_args_after = DBDiscussionSession.query(
            ClickedArgument).count()
        count_clicked_args_for_arg_2_after = \
            DBDiscussionSession.query(ClickedArgument).filter(ClickedArgument.author_uid == db_user.uid,
                                                              ClickedArgument.argument_uid == 2,
                                                              ClickedArgument.is_valid == True,
                                                              ClickedArgument.is_up_vote == True).count()

        self.assertEqual(count_seen_stmts_after, count_seen_stmts_before)
        self.assertGreater(count_clicked_stmts_after,
                           count_clicked_stmts_before)
        self.assertGreater(count_seen_args_after, count_seen_args_before)
        self.assertGreater(count_clicked_args_after, count_clicked_args_before)
        self.assertEqual(count_clicked_args_for_arg_2_before + 1,
                         count_clicked_args_for_arg_2_after)