Пример #1
0
def test_scrap_details_from_amo():
    record = {"id": "123", "blockID": "foobar"}

    with open(os.path.join(os.path.dirname(__file__), "blocked_item_detail_page.html")) as html_file:
        html = html_file.read()

    with mock.patch("grequests.map") as grequests_mock:
        response = mock.MagicMock()
        response.url = BLOCKLIST_DETAIL_URL.format("foobar")
        response.text = html
        grequests_mock.return_value = [response]

        records = scrap_details_from_amo([record])

    expected_record = {
        "id": "123",
        "blockID": "foobar",
        "details": {
            "why": "This add-on is believed to be silently installed in "
            'Firefox, in violation of the <a href="https://'
            'developer.mozilla.org/en-US/Add-ons/Add-on_guidelines">'
            "Add-on Guidelines</a>.",
            "who": "All Firefox users who have this add-on installed. Users "
            "who wish\n to continue using this add-on can enable it in "
            "the Add-ons Manager.",
            "name": "webget",
            "bug": "https://bugzilla.mozilla.org/show_bug.cgi?id=1033857",
            "created": "2014-08-06T00:00:00Z",
        },
    }

    assert records == [expected_record]
    assert record != expected_record
Пример #2
0
def sync_records(fields, filename, xpath, kinto_client, bucket, collection,
                 schema=None, with_scrapping=False, force_signature=True):
    xml_records = get_xml_records(
        fields=fields,
        filename=filename,
        xpath=xpath)
    kinto_records = get_kinto_records(
        kinto_client=kinto_client,
        bucket=bucket,
        collection=collection,
        schema=schema,
        permissions=COLLECTION_PERMISSIONS)

    to_create, to_delete = get_diff(xml_records, kinto_records)

    if with_scrapping:
        to_create = scrap_details_from_amo(to_create)

    push_changes((to_create, to_delete), kinto_client,
                 bucket=bucket, collection=collection,
                 to_be_signed=force_signature)
Пример #3
0
def test_scrap_details_from_amo():
    record = {'id': '123', 'blockID': 'foobar'}

    with open(
            os.path.join(os.path.dirname(__file__),
                         'blocked_item_detail_page.html')) as html_file:
        html = html_file.read()

    with mock.patch('grequests.map') as grequests_mock:
        response = mock.MagicMock()
        response.url = BLOCKLIST_DETAIL_URL.format('foobar')
        response.text = html
        grequests_mock.return_value = [response]

        records = scrap_details_from_amo([record])

    expected_record = {
        'id': '123',
        'blockID': 'foobar',
        'details': {
            'why':
            'This add-on is believed to be silently installed in '
            'Firefox, in violation of the <a href="https://'
            'developer.mozilla.org/en-US/Add-ons/Add-on_guidelines">'
            'Add-on Guidelines</a>.',
            'who':
            'All Firefox users who have this add-on installed. Users '
            'who wish\n to continue using this add-on can enable it in '
            'the Add-ons Manager.',
            'name':
            'webget',
            'bug':
            'https://bugzilla.mozilla.org/show_bug.cgi?id=1033857',
            'created':
            '2014-08-06T00:00:00Z',
        }
    }

    assert records == [expected_record]
    assert record != expected_record
Пример #4
0
def test_scrap_detail_should_not_scrap_records_with_missing_blockID():
    with mock.patch("grequests.map") as grequests_mock:
        records = scrap_details_from_amo([{"id": "foo"}])
        assert grequests_mock.call_count == 0
        assert records == [{"id": "foo"}]
Пример #5
0
def test_scrap_detail_should_not_scrap_records_with_missing_blockID():
    with mock.patch('grequests.map') as grequests_mock:
        records = scrap_details_from_amo([{"id": "foo"}])
        assert grequests_mock.call_count == 0
        assert records == [{"id": "foo"}]