当前位置: 首页>>代码示例>>Python>>正文


Python TestApp.authorization方法代码示例

本文整理汇总了Python中webtest.TestApp.authorization方法的典型用法代码示例。如果您正苦于以下问题:Python TestApp.authorization方法的具体用法?Python TestApp.authorization怎么用?Python TestApp.authorization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webtest.TestApp的用法示例。


在下文中一共展示了TestApp.authorization方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_bad_secret

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
    def test_bad_secret(self):
        """ The DB API should return a 401 unauthorised if I submit a request
            as an agent but with a bad or empty password.
        """
        app = TestApp(get_app(test_ini))

        #With no password
        app.authorization = ('Basic', ('agent', ''))
        app.get("/users/testuser/credit", status=401)

        #And with a bad one
        app.authorization = ('Basic', ('agent', 'badpass'))
        app.get("/users/testuser/credit", status=401)
开发者ID:cedadev,项目名称:eos-db,代码行数:15,代码来源:test_agent_api.py

示例2: test_view_wabstic_proporz

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
def test_view_wabstic_proporz(election_day_app):
    id_, token = add_data_source(
        Client(election_day_app),
        upload_type='proporz',
        fill=True
    )

    client = Client(election_day_app)
    client.authorization = ('Basic', ('', token))

    params = [
        (name, Upload('{}.csv'.format(name), 'a'.encode('utf-8')))
        for name in (
            'wp_wahl',
            'wpstatic_gemeinden',
            'wp_gemeinden',
            'wp_listen',
            'wp_listengde',
            'wpstatic_kandidaten',
            'wp_kandidaten',
            'wp_kandidatengde',
        )
    ]

    with patch(
        'onegov.election_day.views.upload.wabsti_exporter'
        '.import_election_wabstic_proporz'
    ) as import_:
        result = client.post('/upload-wabsti-proporz', params=params)
        assert import_.called
        assert '1' in import_.call_args[0]
        assert '2' in import_.call_args[0]
        assert result.json['status'] == 'success'
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:35,代码来源:test_views_upload_wabstic.py

示例3: test_view_rest_parties

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
def test_view_rest_parties(election_day_app):
    token = UploadTokenCollection(election_day_app.session()).create()
    token = str(token.token)
    transaction.commit()

    client = Client(election_day_app)
    client.authorization = ('Basic', ('', token))

    create_election(election_day_app, 'proporz')

    params = (
        ('id', 'election'),
        ('type', 'parties'),
        ('results', Upload('results.csv', 'a'.encode('utf-8'))),
    )

    with patch(
        'onegov.election_day.views.upload.rest.import_party_results',
        return_value=[]
    ) as import_:
        result = client.post('/upload', params=params)
        assert result.json['status'] == 'success'

        assert import_.called
        assert isinstance(import_.call_args[0][0], Election)
        assert isinstance(import_.call_args[0][1], BytesIO)
        assert import_.call_args[0][2] == 'application/octet-stream'
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:29,代码来源:test_views_upload_rest.py

示例4: test_auth

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
def test_auth(monkeypatch):
    monkeypatch.setenv("WSGI_AUTH_CREDENTIALS", "foo:bar")
    application = wsgi_basic_auth.BasicAuth(wsgi_app)
    app = TestApp(application)
    app.get("/", status=401)

    app.authorization = ("Basic", ("foo", "bar"))
    app.get("/", status=200)
开发者ID:mvantellingen,项目名称:wsgi-basic-auth,代码行数:10,代码来源:test_wsgi_basic_auth.py

示例5: test_states_empty

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
    def test_states_empty(self):
        #Get a valid log-in
        app = TestApp(get_app(test_ini))
        settings = get_appsettings(test_ini)
        app.authorization = ('Basic', ('agent', settings['agent.secret']))

        r = app.get('/states')

        self.assertEqual(r.json, { s : 0 for s in server.get_state_list() })
开发者ID:cedadev,项目名称:eos-db,代码行数:11,代码来源:test_agent_api.py

示例6: test_view_rest_authenticate

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
def test_view_rest_authenticate(election_day_app):
    client = Client(election_day_app)

    client.post('/upload', status=401)

    client.authorization = ('Basic', ('', 'password'))
    client.post('/upload', status=401)

    collection = UploadTokenCollection(election_day_app.session())
    token = str(collection.create().token)
    transaction.commit()
    client.post('/upload', status=401)

    client.authorization = ('Basic', ('', token))
    client.post('/upload', status=400)

    for token in collection.query():
        collection.delete(token)
    transaction.commit()
    client.post('/upload', status=401)
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:22,代码来源:test_views_upload_rest.py

示例7: test_view_rest_validation

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
def test_view_rest_validation(election_day_app):
    token = UploadTokenCollection(election_day_app.session()).create()
    token = str(token.token)
    transaction.commit()

    client = Client(election_day_app)
    client.authorization = ('Basic', ('', token))

    # No parameters
    result = client.post('/upload', status=400).json
    assert result['status'] == 'error'
    assert result['errors'] == {
        'id': [{'message': 'This field is required.'}],
        'results': [{'message': 'This field is required.'}],
        'type': [{'message': 'This field is required.'}],
    }

    # Invalid type
    result = client.post('/upload', status=400, params=(('type', 'xyz'),)).json
    assert result['errors']['type'] == [{'message': 'Not a valid choice'}]

    # No vote
    params = (
        ('id', 'vote-id'),
        ('type', 'vote'),
        ('results', Upload('results.csv', 'a'.encode('utf-8'))),
    )
    result = client.post('/upload', status=400, params=params).json
    assert result['errors']['id'] == [{'message': 'Invalid id'}]

    # No election
    params = (
        ('id', 'election-id'),
        ('type', 'election'),
        ('results', Upload('results.csv', 'a'.encode('utf-8'))),
    )
    result = client.post('/upload', status=400, params=params).json
    assert result['errors']['id'] == [{'message': 'Invalid id'}]

    # Wrong election type
    create_election(election_day_app, 'majorz')
    params = (
        ('id', 'election'),
        ('type', 'parties'),
        ('results', Upload('results.csv', 'a'.encode('utf-8'))),
    )
    result = client.post('/upload', status=400, params=params).json
    assert result['errors']['id'] == [{
        'message': 'Use an election based on proportional representation'
    }]
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:52,代码来源:test_views_upload_rest.py

示例8: test_env_secretfile

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
    def test_env_secretfile(self):
        """ I should be able to supply the secret in the environment and it should
            override the config file.
        """
        #Don't do this, it stays set and breaks other tests
        #os.environ['agent_secretfile'] = secret_file
        #Do this...
        with patch.dict('os.environ', {'agent_secretfile': secret_file}):
           app = TestApp(get_app(test_ini))

        # We know what's in the secret_file; see the first test above
        app.authorization = ('Basic', ('agent', 'testsharedsecret'))

        r = app.get("/users/testuser/credit")
        self.assertEqual(r.json['credit_balance'], 200)
开发者ID:cedadev,项目名称:eos-db,代码行数:17,代码来源:test_agent_api.py

示例9: test_view_wabstic_authenticate

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
def test_view_wabstic_authenticate(election_day_app):
    client = Client(election_day_app)
    urls = ('vote', 'majorz', 'proporz')

    def post(url):
        return client.post('/upload-wabsti-{}'.format(url), expect_errors=True)

    assert all((post(url).status_code == 403 for url in urls))

    client.authorization = ('Basic', ('', 'password'))

    assert all((post(url).status_code == 403 for url in urls))

    id_, token = add_data_source(Client(election_day_app))

    assert all((post(url).status_code == 403 for url in urls))

    client.authorization = ('Basic', ('', token))

    assert all((post(url).status_code == 200 for url in urls))

    regenerate_token(Client(election_day_app), id_)

    assert all((post(url).status_code == 403 for url in urls))
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:26,代码来源:test_views_upload_wabstic.py

示例10: test_secret_in_file

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
    def test_secret_in_file(self):
        """ Likewise I should be able to set a secretfile in the config file
            and the secret should be read from there.
        """
        #self test 2 above confirms that this sets the agent.secretfile correctly
        with patch('builtins.open',
                   filter_open(TestAgentAPI._ini_filter, pattern=r'test\.ini$', verbose=False)):
            appconf = get_app(test_ini)

        app = TestApp(appconf)

        # We know what's in the secret_file; see the first test above
        app.authorization = ('Basic', ('agent', 'testsharedsecret'))

        r = app.get("/users/testuser/credit")
        self.assertEqual(r.json['credit_balance'], 200)
开发者ID:cedadev,项目名称:eos-db,代码行数:18,代码来源:test_agent_api.py

示例11: _get_test_app

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
    def _get_test_app(self):
        # This is tested in the test below, and also convenient for other tests where
        # we just want a working agent log-in.

        app = TestApp(get_app(test_ini))
        #Re-read the .ini to find out the secret.
        settings = get_appsettings(test_ini)

        #This should not be the same as what's in secret-file.txt.
        #Actually, I already tested this above, no matter.
        # self.assertNotEqual(settings['agent.secret'], 'testsharedsecret')
        app.authorization = ('Basic', ('agent', settings['agent.secret']))

        #And we need this, or else the second call will fail with
        # KeyError: 'No such user'.  Really we should either suppress HAP returning
        # a login token to agents or else allow it to validate the token successfully.
        app.cookiejar.set_policy(DefaultCookiePolicy(allowed_domains=[]))

        return app
开发者ID:cedadev,项目名称:eos-db,代码行数:21,代码来源:test_agent_api.py

示例12: test_view_wabstic_vote

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
def test_view_wabstic_vote(election_day_app):
    id_, token = add_data_source(Client(election_day_app), fill=True)

    client = Client(election_day_app)
    client.authorization = ('Basic', ('', token))

    params = [
        (name, Upload('{}.csv'.format(name), 'a'.encode('utf-8')))
        for name in ('sg_geschaefte', 'sg_gemeinden')
    ]

    with patch(
        'onegov.election_day.views.upload.wabsti_exporter.import_vote_wabstic'
    ) as import_:
        result = client.post('/upload-wabsti-vote', params=params)
        assert import_.called
        assert '1' in import_.call_args[0]
        assert '2' in import_.call_args[0]
        assert result.json['status'] == 'success'
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:21,代码来源:test_views_upload_wabstic.py

示例13: test_view_rest_translations

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
def test_view_rest_translations(election_day_app):
    token = UploadTokenCollection(election_day_app.session()).create()
    token = str(token.token)
    transaction.commit()

    client = Client(election_day_app)
    client.authorization = ('Basic', ('', token))

    params = (
        ('id', 'vote-id'),
        ('type', 'vote'),
        ('results', Upload('results.csv', 'a'.encode('utf-8'))),
    )

    # Default
    result = client.post('/upload', status=400).json
    assert result['errors']['id'][0]['message'] == 'This field is required.'

    result = client.post('/upload', status=400, params=params).json
    assert result['errors']['id'][0]['message'] == 'Invalid id'

    # Invalid header
    headers = [('Accept-Language', 'xxx')]
    result = client.post('/upload', status=400, headers=headers).json
    assert result['errors']['id'][0]['message'] == 'This field is required.'

    result = client.post('/upload', status=400, headers=headers, params=params)
    result = result.json
    assert result['errors']['id'][0]['message'] == 'Invalid id'

    # German
    headers = [('Accept-Language', 'de_CH')]
    result = client.post('/upload', status=400, headers=headers).json
    assert result['errors']['id'][0]['message'] == 'Dieses Feld wird benötigt.'

    result = client.post('/upload', status=400, headers=headers, params=params)
    result = result.json
    assert result['errors']['id'][0]['message'] == 'Ungültige ID'
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:40,代码来源:test_views_upload_rest.py

示例14: test_view_wabstic_translations

# 需要导入模块: from webtest import TestApp [as 别名]
# 或者: from webtest.TestApp import authorization [as 别名]
def test_view_wabstic_translations(election_day_app):
    id_, token = add_data_source(Client(election_day_app), fill=True)

    client = Client(election_day_app)
    client.authorization = ('Basic', ('', token))

    params = (
        ('sg_geschaefte', Upload('sg_geschaefte.txt', 'a'.encode('utf-8'))),
        ('sg_gemeinden', Upload('sg_gemeinden.txt', 'a'.encode('utf-8'))),
    )

    # Default
    result = client.post('/upload-wabsti-vote')
    assert result.json['errors']['sg_gemeinden'] == ['This field is required.']

    result = client.post('/upload-wabsti-majorz')
    assert result.json['errors']['data_source'] == [
        'The data source is not configured properly'
    ]

    result = client.post('/upload-wabsti-vote', params=params)
    assert result.json['errors']['item'][0]['message'] == (
        'Not a valid xls/xlsx file.'
    )

    # Invalid header
    headers = [('Accept-Language', 'xxx')]
    result = client.post('/upload-wabsti-vote', headers=headers)
    assert result.json['errors']['sg_gemeinden'] == ['This field is required.']

    result = client.post('/upload-wabsti-majorz', headers=headers)
    assert result.json['errors']['data_source'] == [
        'The data source is not configured properly'
    ]

    result = client.post('/upload-wabsti-vote', headers=headers, params=params)
    assert result.json['errors']['item'][0]['message'] == (
        'Not a valid xls/xlsx file.'
    )

    # German
    headers = [('Accept-Language', 'de_CH')]
    result = client.post('/upload-wabsti-vote', headers=headers)
    assert result.json['errors']['sg_gemeinden'] == [
        'Dieses Feld wird benötigt.'
    ]

    result = client.post('/upload-wabsti-majorz', headers=headers)
    assert result.json['errors']['data_source'] == [
        'Die Datenquellekonfiguration ist ungültig'
    ]

    result = client.post('/upload-wabsti-vote', headers=headers, params=params)
    assert result.json['errors']['item'][0]['message'] == (
        'Keine gültige XLS/XLSX Datei.'
    )

    # Italian
    headers = [('Accept-Language', 'it_CH')]
    result = client.post('/upload-wabsti-vote', headers=headers)
    assert result.json['errors']['sg_gemeinden'] == [
        'Questo campo è obbligatorio.'
    ]

    result = client.post('/upload-wabsti-majorz', headers=headers)
    assert result.json['errors']['data_source'] == [
        'L\'origine dati non è configurata correttamente'
    ]

    result = client.post('/upload-wabsti-vote', headers=headers, params=params)
    assert result.json['errors']['item'][0]['message'] == (
        'Nessun file XLS/XLSX valido.'
    )
开发者ID:OneGov,项目名称:onegov.election_day,代码行数:75,代码来源:test_views_upload_wabstic.py


注:本文中的webtest.TestApp.authorization方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。