pytest plugin for Firefox Accounts
Перейти к файлу
dependabot-preview[bot] 79c0143854 Bump flake8 from 3.7.7 to 3.7.8 (#64)
Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.7.7 to 3.7.8.
- [Release notes](https://gitlab.com/pycqa/flake8/tags)
- [Commits](https://gitlab.com/pycqa/flake8/compare/3.7.7...3.7.8)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-22 13:08:08 -07:00
pytest_fxa Use a similar method to generating random emails for command line and environment variable tests 2018-10-04 16:04:25 +01:00
tests Fix flake8 issue with invalid escape sequence 2018-11-02 16:06:42 +00:00
.gitignore Add __pycache__ to .gitignore 2018-06-26 07:47:59 -07:00
.pre-commit-config.yaml Reformat code using black, configure pre-commit, and add contributing guidelines 2018-08-29 16:18:58 +01:00
.travis.yml Add support for Python 3.7 and update all dependencies 2018-08-29 16:10:17 +01:00
CHANGES.rst Update release notes for 1.4.0 2018-08-28 18:09:33 +01:00
CODE_OF_CONDUCT.md Add Mozilla Code of Conduct file (#53) 2019-04-06 00:38:59 -07:00
CONTRIBUTING.md Reformat code using black, configure pre-commit, and add contributing guidelines 2018-08-29 16:18:58 +01:00
LICENSE Initial commit 2018-04-12 17:49:29 +01:00
Pipfile Bump flake8 from 3.7.7 to 3.7.8 (#64) 2019-08-22 13:08:08 -07:00
README.rst Add Dependabot badge to README 2018-09-03 20:13:34 +01:00
pipenv.txt Update pipenv 2018-11-02 16:06:42 +00:00
setup.cfg Reformat code using black, configure pre-commit, and add contributing guidelines 2018-08-29 16:18:58 +01:00
setup.py Reformat code using black, configure pre-commit, and add contributing guidelines 2018-08-29 16:18:58 +01:00
tox.ini Add support for Python 3.7 and update all dependencies 2018-08-29 16:10:17 +01:00

README.rst

pytest-fxa
==========

pytest-fxa is a plugin for pytest_ that provides test accounts for
`Firefox Accounts`_.

.. image:: https://img.shields.io/badge/license-MPL%202.0-blue.svg
   :target: https://github.com/mozilla/pytest-fxa/blob/master/LICENSE
   :alt: License
.. image:: https://img.shields.io/pypi/v/pytest-fxa.svg
   :target: https://pypi.python.org/pypi/pytest-fxa/
   :alt: PyPI
.. image:: https://img.shields.io/travis/mozilla/pytest-fxa.svg
   :target: https://travis-ci.org/mozilla/pytest-fxa/
   :alt: Travis
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
   :target: https://github.com/ambv/black
.. image:: https://img.shields.io/github/issues-raw/mozilla/pytest-fxa.svg
   :target: https://github.com/mozilla/pytest-fxa/issues
   :alt: Issues
.. image:: https://api.dependabot.com/badges/status?host=github&repo=mozilla/pytest-fxa
   :target: https://dependabot.com
   :alt: Dependabot

Requirements
------------

You will need the following prerequisites in order to use pytest-fxa:

- Python 2.7, 3.6, 3.7, PyPy, or PyPy3

Installation
------------

To install pytest-fxa:

.. code-block:: bash

  $ pip install pytest-fxa

Creating a test Firefox Account
-------------------------------

To create a Firefox Account for testing, include the ``fxa_account`` fixture
name in your test method signature. This is a tuple with named properties for
the test account's ``email`` and ``password``. The following example shows how
this could be used with `Selenium`_ to sign into a website that uses Firefox
Accounts for authentication:

.. code-block:: python

  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()

The test account will be automatically destroyed when it's no longer needed.

Specifying an environment
-------------------------

By default all accounts will be created on the 'stage' environment. You can set
the ``FXA_ENV`` environment variable to target 'production' or 'stable'.

If you need to override the environment for a subset of tests, or run tests against multiple environments, you can use the ``fxa_env`` marker:

.. code-block:: python

  @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()

Alternatively, you can override the ``fxa_urls`` fixture for full control of
the URLs for your environment:

.. code-block:: python

  @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/'}

Resources
---------

- `Release Notes`_
- `Issue Tracker`_
- Code_

.. _pytest: http://www.python.org/
.. _Firefox Accounts: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Firefox_Accounts
.. _Selenium: https://www.seleniumhq.org/
.. _Release Notes:  http://github.com/mozilla/pytest-fxa/blob/master/CHANGES.rst
.. _Issue Tracker: http://github.com/mozilla/pytest-fxa/issues
.. _Code: http://github.com/mozilla/pytest-fxa