跳转到主要内容

Firefox Accounts的pytest插件

项目描述

pytest-fxa 是一个pytest插件,它为Firefox Accounts提供测试账户。

License PyPI Travis Issues Updates Python 3

要求

使用pytest-fxa,您需要以下先决条件:

  • Python 2.7, 3.6, PyPy或PyPy3

安装

要安装pytest-fxa:

$ pip install pytest-fxa

创建一个测试Firefox账户

为了创建一个用于测试的Firefox账户,在测试方法签名中包含fxa_account fixture名称。这是一个具有命名属性的元组,用于测试账户的emailpassword。以下示例显示了如何使用Selenium与使用Firefox Accounts进行身份验证的网站进行登录

def test_my_fxa_site(fxa_account, selenium):
    selenium.get('https://example.com/')
    selenium.find_element(By.ID, 'email').send_keys(fxa_account.email)
    selenium.find_element(By.ID, 'password').send_keys(fxa_account.password)
    selenium.find_element(By.ID, 'login').click()

当不再需要时,测试账户将被自动销毁。

指定环境

默认情况下,所有账户都将创建在“测试”环境中。您可以将FXA_ENV环境变量设置为“生产”或“稳定”。

如果您需要为测试子集覆盖环境,或针对多个环境运行测试,您可以使用fxa_env标记

@pytest.mark.fxa_env('production')
def test_production(fxa_account):
    selenium.get('https://example.com/')
    selenium.find_element(By.ID, 'email').send_keys(fxa_account.email)
    selenium.find_element(By.ID, 'password').send_keys(fxa_account.password)
    selenium.find_element(By.ID, 'login').click()


@pytest.mark.fxa_env('stage', 'stable')
def test_stage(fxa_account):
    selenium.get('https://elpmaxe.com/')
    selenium.find_element(By.ID, 'email').send_keys(fxa_account.email)
    selenium.find_element(By.ID, 'password').send_keys(fxa_account.password)
    selenium.find_element(By.ID, 'login').click()

或者,您可以使用fxa_urls固定装置来完全控制您环境的URL

@pytest.fixture
def fxa_urls():
    return {
        'authentication': 'https://api-accounts.stage.mozaws.net/v1',
        'oauth': 'https://oauth.stage.mozaws.net/v1',
        'content': 'https://accounts.stage.mozaws.net/',
        'profile': 'https://profile.stage.mozaws.net/v1',
        'token': 'https://token.stage.mozaws.net/'}

资源

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪一个,请了解有关安装包的更多信息。

源分发

pytest-fxa-1.4.0.tar.gz (7.1 kB 查看散列值)

上传时间

构建分发

pytest_fxa-1.4.0-py2.py3-none-any.whl (4.6 kB 查看散列值)

上传时间 Python 2 Python 3

由以下支持