예제 #1
0
    def test_set_user_setting_no_service(self):
        from dbas.views import set_user_settings as ajax
        request = construct_dummy_request(json_body={'ui_locales': 'en'})
        response = ajax(request)
        self.assertEqual(response.status_code, 400)

        self.config.testing_securitypolicy(userid='Tobias', permissive=True)
        request = construct_dummy_request(json_body={'service': 'oha', 'settings_value': False})
        response = ajax(request)
        self.assertIn('error', response)
        self.assertIn('public_nick', response)
        self.assertIn('public_page_url', response)
        self.assertIn('gravatar_url', response)
        self.assertTrue(response['error'] != '')
        self.assertTrue(response['public_nick'] != '')
        self.assertTrue(response['public_page_url'] != '')
        self.assertTrue(response['gravatar_url'] != '')
예제 #2
0
 def test_provided_empty_string_should_fail(self):
     request = construct_dummy_request(json_body={'foo': ''})
     fn = spec_keyword_in_json_body(
         (str, 'foo',
          lambda foo, varType: isinstance(foo, varType) and foo != ''))
     response = fn(request)
     self.assertIsInstance(response, bool)
     self.assertFalse(response)
예제 #3
0
    def test_valid_new_issue(self):
        request = construct_dummy_request()
        response = discussion.valid_new_issue(request)
        self.assertFalse(response)
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(
            json_body={
                'title': self.issue_cat_or_dog.title,
                'info': 'some info',
                'long_info': 'some longer info'
            })
        response = discussion.valid_new_issue(request)
        self.assertFalse(response)
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(
            json_body={
                'title': 'some title',
                'info': self.issue_cat_or_dog.info,
                'long_info': 'some longer info'
            })
        response = discussion.valid_new_issue(request)
        self.assertFalse(response)
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(
            json_body={
                'title': 'some title',
                'info': 'some info',
                'long_info': self.issue_cat_or_dog.long_info
            })
        response = discussion.valid_new_issue(request)
        self.assertFalse(response)
        self.assertIsInstance(response, bool)

        request = construct_dummy_request(
            json_body={
                'title': 'some title',
                'info': 'some info',
                'long_info': 'some longer info'
            })
        response = discussion.valid_new_issue(request)
        self.assertTrue(response)
        self.assertIsInstance(response, bool)
예제 #4
0
 def test_valid_login_attempt(self):
     request = construct_dummy_request(json_body={
         'nickname': 'Walter',
         'password': '******'
     })
     response = apiviews.user_login(request)
     self.assertIn('nickname', request.validated)
     self.assertIn('token', response)
     self.assertIn('nickname', response)
예제 #5
0
 def test_valid_user_has_review_access(self):
     db_user = DBDiscussionSession.query(User).filter_by(
         nickname='Tobias').first()
     request = construct_dummy_request(validated={
         'queue': key_split,
         'user': db_user
     })
     response = valid_user_has_review_access(request)
     self.assertTrue(response)
예제 #6
0
 def test_invalid_relation_should_fail(self):
     request = construct_dummy_request(matchdict={
         'slug': self.issue_cat_or_dog.slug,
         'arg_id_user': 2,
         'arg_id_sys': 3
     })
     response = discussion.valid_support(request)
     self.assertFalse(response)
     self.assertIsInstance(response, bool)
예제 #7
0
    def test_page(self):
        db_user = DBDiscussionSession.query(User).filter_by(nickname='Tobias').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.assertFalse(response['can_send_notification'])
예제 #8
0
 def test_valid_disabled_issue(self):
     request = construct_dummy_request()
     request.session = {'issue': self.issue_disabled.uid}
     response = discussion.valid_issue_by_id(request)
     self.assertFalse(
         response,
         'The field-experiment-issue is disabled in the development-seed and can\'t be queried'
     )
     self.assertIsInstance(response, bool)
예제 #9
0
 def test_different_position_and_reason_is_valid(self):
     request: IRequest = construct_dummy_request(
         matchdict={'slug': self.issue_cat_or_dog.slug},
         json_body={
             'position': 'some position',
             'reason': 'some valid reason for it'
         })
     self.assertTrue(
         discussion.valid_reason_and_position_not_equal(request))
예제 #10
0
 def test_has_number_keywords(self):
     request = construct_dummy_request({
         'int': 4,
         'float': 4.0
     })
     response = has_keywords(('int', int), ('float', float))(request)
     self.assertTrue(response)
     self.assertIn('int', request.validated)
     self.assertIn('float', request.validated)
예제 #11
0
 def test_wrong_slug(self):
     request = construct_dummy_request()
     request.matchdict = {
         'slug': 'kitty-or-doggy-is-a-wrong-slug',
         'statement_id': 2,
         'attitude': Attitudes.AGREE.value,
     }
     response = discussion_justify_statement(request)
     self.assertIsInstance(response, httpexceptions.HTTPError)
예제 #12
0
    def test_page_logged_in(self):
        self.config.testing_securitypolicy(userid='Tobias', permissive=True)

        request = construct_dummy_request()
        response = history(request)
        verify_dictionary_of_view(response)

        self.assertIn('history', response)
        self.assertTrue(len(response['history']) != 0)
예제 #13
0
 def test_has_multiple_keywords(self):
     request = construct_dummy_request({
         'string': 'foo',
         'bool': True
     })
     response = has_keywords(('string', str), ('bool', bool))(request)
     self.assertTrue(response)
     self.assertIn('string', request.validated)
     self.assertIn('bool', request.validated)
예제 #14
0
 def test_wrong_statement_returns_error(self):
     request = construct_dummy_request(
         match_dict={
             'slug': self.issue_cat_or_dog.slug,
             'statement_id': -1,
             'attitude': Attitudes.AGREE.value
         })
     response = apiviews.discussion_justify_statement(request)
     self.assertIsInstance(response, httpexceptions.HTTPError)
예제 #15
0
 def test_login_empty_user_is_not_allowed_to_login(self):
     request = construct_dummy_request({
         'nickname': '',
         'password': '******'
     })
     response = apiviews.user_login(request)
     self.assertIn('nickname', request.validated)
     self.assertEqual(401, response.status_code)
     self.assertIsInstance(response, httpexceptions.HTTPError)
예제 #16
0
    def test_page(self):
        request = construct_dummy_request()
        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'])
예제 #17
0
 def test_main_admin(self):
     self.config.testing_securitypolicy(userid='Tobias', permissive=True)
     self.__update_user('Tobias')
     request = construct_dummy_request()
     response = main_admin(request)
     self.assertIn('title', response)
     self.assertIn('project', response)
     self.assertIn('extras', response)
     self.assertIn('dashboard', response)
예제 #18
0
 def test_login_wrong_user(self):
     request = construct_dummy_request(json_body={
         'nickname': r'¯\_(ツ)_/¯',
         'password': '******'
     })
     response = apiviews.user_login(request)
     self.assertIn('nickname', request.validated)
     self.assertEqual(401, response.status_code)
     self.assertIsInstance(response, httpexceptions.HTTPError)
예제 #19
0
 def test_wrong_attitude(self):
     request = construct_dummy_request()
     request.matchdict = {
         'slug': 'cat-or-dog',
         'statement_id': 2,
         'attitude': 'not-a-valid-attitude',
     }
     response = discussion_justify_statement(request)
     self.assertIsInstance(response, httpexceptions.HTTPError)
예제 #20
0
 def test_wrong_attitude_returns_error(self):
     request = construct_dummy_request(
         matchdict={
             'slug': self.issue_cat_or_dog.slug,
             'statement_id': self.statement_cat_or_dog.uid,
             'attitude': 'not-an-attitude'
         })
     response = apiviews.discussion_justify_statement(request)
     self.assertIsInstance(response, httpexceptions.HTTPError)
예제 #21
0
 def test_stmt_or_arg_id_does_not_belong_to_issue(self):
     request = construct_dummy_request()
     request.matchdict = {
         'slug': 'cat-or-dog',
         'statement_id': 40,
         'attitude': Attitudes.AGREE.value,
     }
     response = discussion_justify_statement(request)
     self.assertIsInstance(response, httpexceptions.HTTPError)
예제 #22
0
 def test_valid_slug_and_issue_returns_bubbles(self):
     request = construct_dummy_request(
         matchdict={
             'slug': self.issue_cat_or_dog.slug,
             'argument_id': self.argument_cat_or_dog.uid
         })
     response = apiviews.discussion_finish(request)
     self.assertIsInstance(response, dict)
     self.assertIn('bubbles', response)
예제 #23
0
    def test_slug_must_be_valid(self):
        request = construct_dummy_request(matchdict={'slug': ''})
        response = discussion.valid_issue_by_slug(request)
        self.assertFalse(response, 'Slug is missing')
        self.assertIsInstance(response, bool)
        self.assertNotIn('issue', request.validated)

        request = construct_dummy_request(matchdict={'slug': 1})
        response = discussion.valid_issue_by_slug(request)
        self.assertFalse(response, 'Slug should be a string')
        self.assertIsInstance(response, bool)
        self.assertNotIn('issue', request.validated)

        request = construct_dummy_request(matchdict={'slug': None})
        response = discussion.valid_issue_by_slug(request)
        self.assertFalse(response, 'Slug should be a string')
        self.assertIsInstance(response, bool)
        self.assertNotIn('issue', request.validated)
예제 #24
0
 def test_invalid_credentials(self):
     request = construct_dummy_request()
     request.validated = {
         'nickname': 'Walter',
         'password': '******'
     }
     validate_credentials(request)
     self.assertNotIn('user', request.validated)
     self.assertGreater(len(request.errors), 0)
예제 #25
0
 def test_missing_issue_should_fail(self):
     request = construct_dummy_request(matchdict={
         'slug': '',
         'arg_id_user': 2,
         'arg_id_sys': 11
     })
     response = discussion.valid_support(request)
     self.assertFalse(response)
     self.assertIsInstance(response, bool)
예제 #26
0
 def test_login_twitter(self):
     try:
         redirect_uri = 'http://lvh.me:4284/discuss?service=twitter'
         request = construct_dummy_request()
         resp = twitter.start_flow(request=request,
                                   redirect_uri=redirect_uri)
         self.assertIn('authorization_url', resp)
     except ValueError:
         return True
예제 #27
0
 def test_argument_does_not_belong_to_issue(self):
     request = construct_dummy_request(
         matchdict={
             'slug': self.issue_cat_or_dog.slug,
             'argument_id': self.argument_town.uid
         })
     response = apiviews.discussion_finish(request)
     self.assertIsInstance(response, httpexceptions.HTTPError)
     self.assertEqual(response.status_code, 400)
예제 #28
0
 def test_valid_token(self):
     nickname = 'Walter'
     token = user_tokens[nickname]
     request = construct_dummy_request()
     request.headers[self.header] = json.dumps(
         {'nickname': nickname, 'token': token, 'additional key': 'will be ignored'})
     valid_token(request)
     self.assertEqual(request.errors, [])
     self.assertIn('user', request.validated)
예제 #29
0
def test_has_keywords():
    request = construct_dummy_request()
    fn = core.has_keywords(('foo', int))
    response = fn(request)
    assert type(response) == bool
    assert response is False

    request = construct_dummy_request({'foo': 'bar'})
    fn = core.has_keywords(('foo', int))
    response = fn(request)
    assert type(response) == bool
    assert response is False

    request = construct_dummy_request({'foo': 2})
    fn = core.has_keywords(('foo', int))
    response = fn(request)
    assert type(response) == bool
    assert response is True
예제 #30
0
 def test_issue_is_disabled(self):
     request = construct_dummy_request(
         matchdict={
             'slug': self.issue_disabled.slug,
             'argument_id': self.argument_town.uid
         })
     response: Response = apiviews.discussion_finish(request)
     self.assertIsInstance(response, httpexceptions.HTTPError)
     self.assertEqual(response.status_code, 410)