Пример #1
0
def test_stream_read(requests_mock, auth, stream, endpoint):
    args = {"authenticator": auth}
    stream = stream(**args)
    stream_responses = [{
        "json": {
            stream.data_field: [{
                "id": "test_id"
            }],
        }
    }]
    stream_url = stream.url_base + endpoint
    requests_mock.register_uri("GET", stream_url, stream_responses)
    records = read_full_refresh(stream)

    assert records
Пример #2
0
def test_media_read(api, user_stories_data, requests_mock):
    test_id = "test_id"
    stream = Media(api=api)

    requests_mock.register_uri(
        "GET", FacebookSession.GRAPH + f"/{FB_API_VERSION}/{test_id}/media",
        [{
            "json": user_stories_data
        }])

    records = read_full_refresh(stream)
    assert records == [{
        "business_account_id": "test_id",
        "id": "test_id",
        "page_id": "act_unknown_account"
    }]
Пример #3
0
def test_user_read(api, user_data, requests_mock):
    test_id = "test_id"
    stream = Users(api=api)

    requests_mock.register_uri(
        "GET", FacebookSession.GRAPH + f"/{FB_API_VERSION}/{test_id}/",
        [{
            "json": user_data
        }])

    records = read_full_refresh(stream)
    assert records == [{
        "biography": "Dino data crunching app",
        "id": "17841405822304914",
        "page_id": "act_unknown_account",
        "username": "******",
        "website": "http://www.metricsaurus.com/",
    }]
Пример #4
0
def test_user_lifetime_insights_read(api, config, user_insight_data,
                                     requests_mock):
    test_id = "test_id"

    stream = UserLifetimeInsights(api=api)

    requests_mock.register_uri(
        "GET", FacebookSession.GRAPH + f"/{FB_API_VERSION}/{test_id}/insights",
        [{
            "json": user_insight_data
        }])

    records = read_full_refresh(stream)
    assert records == [{
        "page_id": "act_unknown_account",
        "business_account_id": "test_id",
        "metric": "impressions",
        "date": "2020-05-04T07:00:00+0000",
        "value": 4,
    }]
Пример #5
0
def test_common_error_retry(error_response, requests_mock, api, account_id):
    """Error once, check that we retry and not fail"""
    response = {
        "business_account_id": "test_id",
        "page_id": "act_unknown_account"
    }
    responses = [
        error_response,
        {
            "json": response,
            "status_code": 200,
        },
    ]
    test_id = "test_id"
    requests_mock.register_uri(
        "GET", FacebookSession.GRAPH + f"/{FB_API_VERSION}/{test_id}/media",
        responses)

    stream = Media(api=api)
    records = read_full_refresh(stream)

    assert [response] == records
Пример #6
0
def test_stories_insights_read(api, requests_mock, user_stories_data,
                               user_media_insights_data):
    test_id = "test_id"
    stream = StoryInsights(api=api)

    requests_mock.register_uri(
        "GET", FacebookSession.GRAPH + f"/{FB_API_VERSION}/{test_id}/stories",
        [{
            "json": user_stories_data
        }])
    requests_mock.register_uri(
        "GET", FacebookSession.GRAPH + f"/{FB_API_VERSION}/{test_id}/insights",
        [{
            "json": user_media_insights_data
        }])

    records = read_full_refresh(stream)
    assert records == [{
        "business_account_id": "test_id",
        "id": "test_id",
        "impressions": 264,
        "page_id": "act_unknown_account"
    }]