# Path: collectors/pubmed/spider.py
# def _make_start_urls(prefix, template, date_from=None, date_to=None, session=None):
#     """ Return start_urls.
#     """
# 
#     # Init urls and session
#     urls = set()
#     if not session:
#         session = requests.Session()
#     adapter_opts = {'max_retries': requests.packages.urllib3.util.Retry(total=5, status_forcelist=[503])}
#     session.mount('https://', requests.adapters.HTTPAdapter(**adapter_opts))
# 
#     # Prepare dates
#     if date_from is None:
#         date_from = str(date.today() - timedelta(days=1))
#     if date_to is None:
#         date_to = str(date.today())
#     date_from = datetime.strptime(date_from, '%Y-%m-%d').strftime('%Y/%m/%d')
#     date_to = datetime.strptime(date_to, '%Y-%m-%d').strftime('%Y/%m/%d')
# 
#     # Prepare query
#     query = OrderedDict()
#     query['db'] = 'pubmed'
#     query['retmode'] = 'json'
#     query['mindate'] = date_from
#     query['maxdate'] = date_to
# 
#     # Terms to search
#     query['term'] = """(randomized controlled trial[Publication Type] OR
#                         (randomized[Title/Abstract]
#                          AND controlled[Title/Abstract]
#                          AND trial[Title/Abstract]
#                         ))
#                     """
# 
#     # For both publication/modifiction
#     for date_type in ['pdat', 'mdat']:
#         retstart = 0
#         retmax = 50000
#         while True:
#             query['datetype'] = date_type
#             query['retstart'] = retstart
#             query['retmax'] = retmax
#             url = '%s?%s' % (prefix, urlencode(query))
#             response = session.get(url)
#             pmids = response.json()['esearchresult']['idlist']
#             if not pmids:
#                 break
#             for pmid in pmids:
#                 urls.add(template.format(pmid=pmid))
#             retstart += retmax
# 
#     # Log urls count
#     logger.info('Populated Pubmed start urls: %s', len(urls))
# 
#     return list(urls)


from collectors.pubmed.spider import _make_start_urls
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals



class TestPubmedSpider(object):
    def test_make_start_urls(self, betamax_session):

# Path: collectors/pubmed/spider.py
# def _make_start_urls(prefix, template, date_from=None, date_to=None, session=None):
#     """ Return start_urls.
#     """
# 
#     # Init urls and session
#     urls = set()
#     if not session:
#         session = requests.Session()
#     adapter_opts = {'max_retries': requests.packages.urllib3.util.Retry(total=5, status_forcelist=[503])}
#     session.mount('https://', requests.adapters.HTTPAdapter(**adapter_opts))
# 
#     # Prepare dates
#     if date_from is None:
#         date_from = str(date.today() - timedelta(days=1))
#     if date_to is None:
#         date_to = str(date.today())
#     date_from = datetime.strptime(date_from, '%Y-%m-%d').strftime('%Y/%m/%d')
#     date_to = datetime.strptime(date_to, '%Y-%m-%d').strftime('%Y/%m/%d')
# 
#     # Prepare query
#     query = OrderedDict()
#     query['db'] = 'pubmed'
#     query['retmode'] = 'json'
#     query['mindate'] = date_from
#     query['maxdate'] = date_to
# 
#     # Terms to search
#     query['term'] = """(randomized controlled trial[Publication Type] OR
#                         (randomized[Title/Abstract]
#                          AND controlled[Title/Abstract]
#                          AND trial[Title/Abstract]
#                         ))
#                     """
# 
#     # For both publication/modifiction
#     for date_type in ['pdat', 'mdat']:
#         retstart = 0
#         retmax = 50000
#         while True:
#             query['datetype'] = date_type
#             query['retstart'] = retstart
#             query['retmax'] = retmax
#             url = '%s?%s' % (prefix, urlencode(query))
#             response = session.get(url)
#             pmids = response.json()['esearchresult']['idlist']
#             if not pmids:
#                 break
#             for pmid in pmids:
#                 urls.add(template.format(pmid=pmid))
#             retstart += retmax
# 
#     # Log urls count
#     logger.info('Populated Pubmed start urls: %s', len(urls))
# 
#     return list(urls)


# Path: tests/collectors/pubmed/test_spider.py
from collectors.pubmed.spider import _make_start_urls

# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals



class TestPubmedSpider(object):
    def test_make_start_urls(self, betamax_session):

        result = _make_start_urls(