def test_download_document(workfile_tempdir, mock_req):
    url = "https://api.data.gov/regulations/v3/download?documentId=FDA-2015-N-0540-0004&attachmentNumber=1&contentType=msw12"
    mock_req.get(add_api_key(url), status_code=200, reason="")
    result = api_call_manager(add_api_key(url))
    type = "msw12"
    download_document(workfile_tempdir, "FDA-2015-N-0540-0004", result, type)
    assert os.path.exists(workfile_tempdir + "/doc.FDA-2015-N-0540-0004.doc")
def test_collect_attachments(mock_req, workfile_tempdir):
    mock_req.get(
        add_api_key(make_doc_url("DOCUMENT")),
        status_code=200,
        text='{ "attachments": [ '
        '{ "fileFormats": [ '
        '"https://api.data.gov/regulations/v3/download?documentId=FDA-2015-N-0540-0004&attachmentNumber=1&contentType=msw12", '
        '"https://api.data.gov/regulations/v3/download?documentId=FDA-2015-N-0540-0004&attachmentNumber=1&contentType=pdf" '
        '] } ] }')
    mock_req.get(add_api_key(
        "https://api.data.gov/regulations/v3/download?documentId=FDA-2015-N-0540-0004&attachmentNumber=1&contentType=msw12"
    ),
                 status_code=200,
                 text='Document!')
    mock_req.get(add_api_key(
        "https://api.data.gov/regulations/v3/download?documentId=FDA-2015-N-0540-0004&attachmentNumber=1&contentType=pdf"
    ),
                 status_code=200,
                 text='Document!')

    result = get_extra_documents(
        api_call_manager(add_api_key(make_doc_url("DOCUMENT"))),
        workfile_tempdir, "FDA-2015-N-0540-0004")

    assert result == 1
def test_collect_extra_documents(mock_req, workfile_tempdir):
    mock_req.get(add_api_key(make_doc_url("DOCUMENT")), status_code=200, text='{ "fileFormats": '
                                                                              '["https://api.data.gov/regulations/v3/download?'
                                                                              'documentId=OSHA-H117-2006-0947-0647&'
                                                                              'attachmentNumber=1&contentType=pdf"] }')
    mock_req.get(add_api_key("https://api.data.gov/regulations/v3/download?documentId=OSHA-H117-2006-0947-0647&attachmentNumber=1&contentType=pdf"),
                 status_code=200, text='Document!')
    result = get_extra_documents(api_call_manager(add_api_key(make_doc_url("DOCUMENT"))), workfile_tempdir, "OSHA-H117-2006-0947-0647")

    assert result == 1
示例#4
0
def test_return_docs(mock_req):
    mock_req.post(serverurl + "/return_docs", status_code=200)
    mock_req.get(add_api_key('http://website.com/random'),
                 status_code=200,
                 text='{"documents": \
                                                                                  [{"documentId": "CMS-2005-0001-0001", "attachmentCount": 4},\
                                                                                  {"documentId": "CMS-2005-0001-0002", "attachmentCount": 999}]}'
                 )
    r = return_docs({
        'job_id': 'qwerty',
        'data': ['http://website.com/random']
    }, str(client_id))
    assert r.status_code == 200
示例#5
0
def ignore_test_return_docs_error(mock_req):

    mock_req.get(add_api_key('http://website.com/random'),
                 status_code=400,
                 text='{"documents": \
                                                                                  [{"documentId": "CMS-2005-0001-0001", "attachmentCount": 4},\
                                                                                  {"documentId": "CMS-2005-0001-0002", "attachmentCount": 999}]}'
                 )
    with pytest.raises(CallFailException):
        r = return_docs(
            {
                'job_id': 'qwerty',
                'data': ['http://website.com/random']
            }, str(client_id))
示例#6
0
def test_return_doc(mock_req):
    mock_req.post(serverurl + "/return_doc", status_code=200)
    mock_req.get(add_api_key(
        'https://api.data.gov/regulations/v3/document?documentId=website-com'),
                 status_code=200,
                 text='{ "something": '
                 '["https://api.data.gov/regulations/v3/download?'
                 'documentId=OSHA-H117-2006-0947-0647&'
                 'attachmentNumber=1&contentType=pdf"] }')
    r = return_doc(
        {
            'job_id': 'qwerty',
            'data': [{
                'id': 'website-com',
                'count': 4
            }]
        }, str(client_id))
    assert r.status_code == 200