Beispiel #1
0
def test_upload_multiple(db_session, client):
    john = users.john()
    db_session.add(john)
    db_session.commit()

    data = MultiDict()
    data.add("pilotName", "JD   ")
    data.add("files", (igcs.simple_path,))
    data.add("files", (igcs.hornet_path,))

    res = client.post("/flights/upload", headers=auth_for(john), data=data)
    assert res.status_code == 200
    assert res.json == S(
        {
            u"club_members": [],
            u"aircraft_models": [],
            u"results": ExactSequence(
                [
                    {
                        u"status": 0,
                        u"cacheKey": text_type,
                        u"flight": Partial(
                            {
                                u"club": None,
                                u"copilot": None,
                                u"copilotName": None,
                                u"distance": 7872,
                                u"igcFile": dict,
                                u"pilot": None,
                                u"pilotName": "JD",
                            }
                        ),
                        u"name": Match(r".*simple\.igc"),
                        u"trace": dict,
                        u"airspaces": [],
                    },
                    {
                        u"status": 0,
                        u"cacheKey": text_type,
                        u"flight": Partial(
                            {
                                u"club": None,
                                u"copilot": None,
                                u"copilotName": None,
                                u"distance": 171246,
                                u"igcFile": dict,
                                u"pilot": None,
                                u"pilotName": "JD",
                            }
                        ),
                        u"name": Match(r".*2018-04-14-fla-6ng-01\.igc"),
                        u"trace": dict,
                        u"airspaces": [],
                    },
                ]
            ),
        }
    )
Beispiel #2
0
def test_upload_with_weglide(db_session, client):
    john = users.john()
    db_session.add(john)
    db_session.commit()

    data = dict(
        pilotId=john.id,
        weglideUserId="123",
        weglideBirthday="2020-01-07",
        files=(igcs.simple_path,),
    )

    with patch.object(tasks.upload_to_weglide, "delay", return_value=None) as mock:
        res = client.post("/flights/upload", headers=auth_for(john), data=data)

    mock.assert_called_once()
    assert len(mock.call_args.args) == 3
    assert mock.call_args.args[1] == 123
    assert mock.call_args.args[2] == "2020-01-07"

    assert res.status_code == 200
    assert res.json == S(
        {
            u"club_members": list,
            u"aircraft_models": list,
            u"results": ExactSequence(
                [
                    {
                        u"status": 0,
                        u"cacheKey": IsTrue(),
                        u"flight": Partial(
                            {
                                u"club": None,
                                u"copilot": None,
                                u"copilotName": None,
                                u"distance": 7872,
                                u"igcFile": Partial(
                                    {
                                        u"weglideStatus": 1,
                                        u"weglideData": None,
                                    }
                                ),
                                u"pilotName": None,
                                u"pilot": {
                                    u"id": john.id,
                                    u"name": john.name,
                                },
                            }
                        ),
                        u"name": Match(r".*simple.igc"),
                        u"trace": dict,
                        u"airspaces": [],
                    }
                ]
            ),
        }
    )
def test_error_reporting():
    expected = S({
        'info': Partial({
            'package_url': 'http://pypi.python.org/pypi/pytest',
            'platform': 'INVALID VALUE',
            'description': Length(max=10),
            'downloads': list,
            'classifiers': dict,
        }),
        'urls': int
    })
    _ = expected == TEST_DATA
    msgs = pytest_assertrepr_compare('==', expected, TEST_DATA)
    assert S(Unordered([
        "failed due to validation error(s):",
        "- info.platform: not a valid value (actual: 'unix')",
        "- info.description: length of value must be at most 10 (actual: 'lorem ipsum lorem ipsum')",
        "- info.downloads: expected list (actual: {'last_month': 0})",
        "- info.classifiers: expected dict (actual: ['Development Status :: 6 - Mature', 'Intended Audience :: Developers'])",
        "- urls: expected int (actual: [{}, {}])",
        Any(
            "- releases: extra keys not allowed (actual: {'3.0.7': [], '3.1.3': []})",
            "- releases: extra keys not allowed (actual: {'3.1.3': [], '3.0.7': []})",
        ),
    ])) == msgs
Beispiel #4
0
def test_error_reporting():
    expected = S({
        'info':
        Partial({
            'package_url': 'http://pypi.python.org/pypi/pytest',
            'platform': 'INVALID VALUE',
            'description': Length(max=10),
            'downloads': list,
            'classifiers': dict,
        }),
        'urls':
        int
    })
    _ = expected == TEST_DATA
    msgs = pytest_assertrepr_compare('==', expected, TEST_DATA)
    assert S(
        Unordered([
            "failed to validation error(s):",
            "- info.platform: not a valid value for dictionary value @ data['info']['platform']",
            "- info.description: length of value must be at most 10 for dictionary value @ data['info']['description']",
            "- info.downloads: expected list for dictionary value @ data['info']['downloads']",
            "- info.classifiers: expected dict for dictionary value @ data['info']['classifiers']",
            "- urls: expected int for dictionary value @ data['urls']",
            "- releases: extra keys not allowed @ data['releases']"
        ])) == msgs
Beispiel #5
0
def test_list_vims(
    adaptor: VimAdaptor,
    connection: Connection,
    example_vim: AwsVim,
    mocked_aws_resource_utilization,
):
    BaseVim.objects.delete()

    def list_vims():
        response = connection.call_sync(
            "infrastructure.management.compute.list")
        assert response is not None
        return response.payload

    assert [] == list_vims()

    example_vim.save()

    assert (S([
        Partial({
            "id": str(example_vim.id),
            "name": example_vim.name,
            "country": example_vim.country,
            "city": example_vim.city,
            "type": example_vim.type,
        })
    ]) == list_vims())
def test_retrieve_supported_tags_response_structure_is_as_expected(client):
    """
    GIVEN a client
    WHEN retrieving the list of supported tags
    THEN the structure of the response is as expected
    """
    response = client.retrieve_supported_tags().json()
    schema = S({"data": Partial([S({"tag": str, "description": str})])})
    assert response == schema
def test_validation_ok():
    assert S({
        'info': Partial({
            'package_url': 'http://pypi.python.org/pypi/pytest',
            'platform': 'unix',
            'description': Length(min=10),
            'downloads': dict,
            'classifiers': list,
        }),
        'releases': {
            any: list
        },
        'urls': list
    }) == TEST_DATA
Beispiel #8
0
    def on_vim_adaptor_deploy(message: Message):
        with reraise(catch=True):
            assert (S({
                "function_instance_id": str,
                "service_instance_id": str,
                "vim_id": str,
                "vnfd": Partial({"id": str}),
            }) == message.payload)

        return ({
            "request_status": "ERROR",
            "message": "error-message"
        } if is_vim_adaptor_response_error else {
            "request_status": "COMPLETED",
            "vnfr": {
                "id": "my-vnfr"
            }
        })
def test_scraper_output_format_is_valid(county: str) -> None:
    if county not in scrapers:
        pytest.fail(f'Unknown county: "{county}"')
    try:
        result = scrapers[county].get_county()
    except Exception as error:
        message = (f'Cannot validate "{county}" format because it failed to '
                   f'scrape: {error}')
        warnings.warn(message)
        pytest.skip(message)
        return

    # All the totals sections have basically the same schema.
    totals_section = Partial({
        Optional('gender'):
        Exact({
            # Gender must always at least have male and female.
            'male': int,
            'female': int,
            # Any remaining values should be integers.
            Optional(str): int
        }),
        Optional('age_group'): [Exact({
            'group': str,
            'raw_count': int
        })],
        Optional('race_eth'):
        Exact({
            # We have some mostly-standard keys, but not all scrapers/data
            # sources conform to them. Just validate that values are integers.
            str: int
        }),
        Optional('transmission_cat'):
        Exact({
            # The keys here are not standardized.
            str: int
        })
    })

    assert S({
        'name':
        str,
        'update_time':
        DatetimeIso,
        'source_url':
        Url,
        'meta_from_source':
        str,
        'meta_from_baypd':
        str,
        'series':
        Exact({
            'cases': [
                Exact({
                    'date': Date(),
                    Optional('cases'): int,
                    Optional('cumul_cases'): int
                })
            ],
            'deaths': [
                Exact({
                    'date': Date(),
                    Optional('deaths'): int,
                    Optional('cumul_deaths'): int
                })
            ],
            Optional('tests'): [Partial({
                'date': Date(),
                str: Number
            })]
        }),
        'case_totals':
        totals_section,
        Optional('death_totals'):
        totals_section,
        Optional('population_totals'):
        totals_section
    }) <= result
Beispiel #10
0
def test_upload_zips(db_session, client):
    john = users.john()
    db_session.add(john)
    db_session.commit()

    data = dict(
        pilotId="",
        pilotName="Johnny Dee",
        files=(igcs.zip_path,),
    )

    res = client.post("/flights/upload", headers=auth_for(john), data=data)
    assert res.status_code == 200
    assert res.json == S(
        {
            u"club_members": list,
            u"aircraft_models": list,
            u"results": ExactSequence(
                [
                    {
                        u"status": 0,
                        u"cacheKey": text_type,
                        u"flight": Partial(
                            {
                                u"club": None,
                                u"copilot": None,
                                u"copilotName": None,
                                u"distance": 171246,
                                u"igcFile": dict,
                                u"pilot": None,
                                u"pilotName": "Johnny Dee",
                            }
                        ),
                        u"name": u"foo/2018-04-14-fla-6ng-01.igc",
                        u"trace": dict,
                        u"airspaces": [],
                    },
                    {
                        u"status": 2,
                        u"cacheKey": None,
                        u"flight": None,
                        u"name": u"__MACOSX/foo/._2018-04-14-fla-6ng-01.igc",
                        u"trace": None,
                        u"airspaces": None,
                    },
                    {
                        u"status": 0,
                        u"cacheKey": text_type,
                        u"flight": Partial(
                            {
                                u"club": None,
                                u"copilot": None,
                                u"copilotName": None,
                                u"distance": 195040,
                                u"igcFile": dict,
                                u"pilot": None,
                                u"pilotName": "Johnny Dee",
                            }
                        ),
                        u"name": u"792xaaa1.igc",
                        u"trace": dict,
                        u"airspaces": [],
                    },
                    {
                        u"status": 2,
                        u"cacheKey": None,
                        u"flight": None,
                        u"name": u"__MACOSX/._792xaaa1.igc",
                        u"trace": None,
                        u"airspaces": None,
                    },
                ]
            ),
        }
    )