Exemple #1
0
def test_download_wgs_parts_wgs_scafld(req):
    cfg = Config(format="genbank")
    wgs_contig = open(full_path('wgs_scafld.gbk'), 'rt')
    with open(full_path('wgs_full.gbk'), 'rt') as handle:
        full_file = handle.read()
    req.get(ENTREZ_URL, text=full_file)

    outhandle = wgs.download_wgs_parts(wgs_contig, cfg)
    assert outhandle.getvalue() == full_file
    wgs_contig.close()
Exemple #2
0
def test_download_wgs_parts_wgs(req):
    cfg = Config(format="genbank")
    wgs_contig = open(full_path('wgs.gbk'), 'rt')
    req.get(ENTREZ_URL, body=open(full_path('wgs_full.gbk'), 'rt'))

    outhandle = wgs.download_wgs_parts(wgs_contig, cfg)
    wgs_full = open(full_path('wgs_full.gbk'), 'rt')
    assert outhandle.getvalue() == wgs_full.read()
    wgs_full.close()
    wgs_contig.close()
Exemple #3
0
def test_download_wgs_no_parts(req):
    cfg = Config(format="genbank")
    supercontig = open(full_path('supercontig_full.gbk'), 'rt')
    req.get(ENTREZ_URL, status_code=404)

    outhandle = wgs.download_wgs_parts(supercontig, cfg)
    supercontig_full = open(full_path('supercontig_full.gbk'), 'rt')
    assert outhandle.getvalue() == supercontig_full.read()
    supercontig_full.close()
    supercontig.close()
Exemple #4
0
def test_download_wgs_parts_no_biopython():
    old_have_biopython = wgs.HAVE_BIOPYTHON
    wgs.HAVE_BIOPYTHON = False

    cfg = Config(format="genbank")

    handle = StringIO()

    new_handle = wgs.download_wgs_parts(handle, cfg)
    wgs.HAVE_BIOPYTHON = old_have_biopython
    assert handle == new_handle
Exemple #5
0
def test_download_wgs_parts_wgs_retry(req):
    cfg = Config(format="genbank")
    wgs_contig = open(full_path('wgs.gbk'), 'rt')
    req.get(ENTREZ_URL, response_list=[
        {"text": u'Whoa, slow down', "status_code": 429, "headers": {"Retry-After": "0"}},
        {"body": open(full_path('wgs_full.gbk'), 'rt')},
    ])

    outhandle = wgs.download_wgs_parts(wgs_contig, cfg)
    wgs_full = open(full_path('wgs_full.gbk'), 'rt')
    assert outhandle.getvalue() == wgs_full.read()
    wgs_full.close()
    wgs_contig.close()
Exemple #6
0
def _validate_and_write(request, orig_handle, dl_id, config):
    if config.extended_validation != 'none' or config.recursive:
        handle = StringIO()
    else:
        handle = orig_handle

    write_stream(request, handle, dl_id, config)

    if config.recursive:
        downloaded = download_wgs_parts(handle, config)
        handle = downloaded

    if config.extended_validation != 'none':
        if not run_extended_validation(handle, config.format, config.extended_validation):
            raise ValidationError("Sequence(s) downloaded for {} failed to load.".format(dl_id))

    if config.extended_validation != 'none' or config.recursive:
        orig_handle.write(handle.getvalue())