File: test_expand_testing_fixture.py

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (59 lines) | stat: -rw-r--r-- 1,764 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json

import pytest


def test_expand_testing_fixture_fails_on_bad_reference(sphinx_runner, capsys):
    sphinx_runner.ensure_failure(
        ".. expandtestfixture:: NO_SUCH_FIXTURE",
    )

    captured = capsys.readouterr()
    err_lines = captured.err.splitlines()

    test_line = None
    for line in err_lines:
        if "ValueError: no fixtures defined" in line:
            test_line = line
            break
    else:
        pytest.fail("Didn't find 'ValueError: no fixtures defined' in stderr")

    assert (
        "no fixtures defined for globus_sdk.testing.data.NO_SUCH_FIXTURE" in test_line
    )


# choose an arbitrary example fixture to test
def test_expand_testing_fixture_on_valid_fixture(sphinx_runner):
    etree = sphinx_runner.to_etree(
        ".. expandtestfixture:: groups.set_group_policies",
    )

    code_block = etree.find("./literal_block")
    assert code_block is not None
    assert code_block.get("language") == "json"

    # check against the known values for this fixture
    data = json.loads(code_block.text)
    assert data["is_high_assurance"] is False
    assert data["group_visibility"] == "private"


# choose an arbitrary example fixture to test with multiple cases
def test_expand_testing_fixture_on_non_default_case(sphinx_runner):
    etree = sphinx_runner.to_etree(
        """\
        .. expandtestfixture:: auth.userinfo
            :case: unauthorized
        """,
    )

    code_block = etree.find("./literal_block")
    assert code_block is not None
    assert code_block.get("language") == "json"

    # check against the known values for this fixture
    data = json.loads(code_block.text)
    assert data["error_description"] == "Unauthorized"
    assert data["errors"][0]["status"] == "401"