# Path: urbanaccess/gtfsfeeds.py
# class urbanaccess_gtfsfeeds(object):
#     def __init__(self,
#                  gtfs_feeds={}):
#     def from_yaml(cls, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                 'gtfsfeeds'),
#                   yamlname='gtfsfeeds.yaml'):
#     def to_dict(self):
#     def add_feed(self, add_dict, replace=False):
#     def remove_feed(self, del_key=None, remove_all=False):
#     def to_yaml(self, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                'gtfsfeeds'),
#                 yamlname='gtfsfeeds.yaml',
#                 overwrite=False):
# def search(api='gtfsdataexch', search_text=None, search_field=None,
#            match='contains', add_feed=False, overwrite_feed=False):
# def download(data_folder=os.path.join(config.settings.data_folder),
#              feed_name=None, feed_url=None, feed_dict=None,
#              error_pause_duration=5, delete_zips=False):
# def _unzip(zip_rootpath, delete_zips=True):
# def _zipfile_type_check(file, feed_url_value):
# 
# Path: urbanaccess/gtfsfeeds.py
# class urbanaccess_gtfsfeeds(object):
#     def __init__(self,
#                  gtfs_feeds={}):
#     def from_yaml(cls, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                 'gtfsfeeds'),
#                   yamlname='gtfsfeeds.yaml'):
#     def to_dict(self):
#     def add_feed(self, add_dict, replace=False):
#     def remove_feed(self, del_key=None, remove_all=False):
#     def to_yaml(self, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                'gtfsfeeds'),
#                 yamlname='gtfsfeeds.yaml',
#                 overwrite=False):
# def search(api='gtfsdataexch', search_text=None, search_field=None,
#            match='contains', add_feed=False, overwrite_feed=False):
# def download(data_folder=os.path.join(config.settings.data_folder),
#              feed_name=None, feed_url=None, feed_dict=None,
#              error_pause_duration=5, delete_zips=False):
# def _unzip(zip_rootpath, delete_zips=True):
# def _zipfile_type_check(file, feed_url_value):


import pytest
import os
import pandas as pd
import yaml
from urbanaccess import gtfsfeeds
from urbanaccess.gtfsfeeds import feeds
def test_search_contains_gtfs_data_exchange():
    search_result = gtfsfeeds.search(api='gtfsdataexch',
                                     search_text=['ac transit', 'santa rosa'],
                                     search_field=None, match='contains',
                                     add_feed=False, overwrite_feed=False)

    assert isinstance(search_result, pd.DataFrame)
    assert search_result.empty is False
    assert len(search_result) == 2

    col_list = ['dataexchange_url', 'dataexchange_id', 'name']
    for col in col_list:
        assert col in search_result.columns
        assert search_result[col].isnull().all() == False  # noqa

    value_list = ['ac-transit', 'santa-rosa-citybus']
    for value in value_list:
        assert value in list(search_result['dataexchange_id'])


def test_search_contains_add_feed_gtfs_data_exchange():
    gtfsfeeds.search(api='gtfsdataexch',
                     search_text='ac transit',
                     search_field=None, match='contains',
                     add_feed=True, overwrite_feed=False)

    assert len(feeds.gtfs_feeds.keys()) == 1
    assert 'AC Transit' in feeds.gtfs_feeds.keys()

    # test overwrite feed

# Path: urbanaccess/gtfsfeeds.py
# class urbanaccess_gtfsfeeds(object):
#     def __init__(self,
#                  gtfs_feeds={}):
#     def from_yaml(cls, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                 'gtfsfeeds'),
#                   yamlname='gtfsfeeds.yaml'):
#     def to_dict(self):
#     def add_feed(self, add_dict, replace=False):
#     def remove_feed(self, del_key=None, remove_all=False):
#     def to_yaml(self, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                'gtfsfeeds'),
#                 yamlname='gtfsfeeds.yaml',
#                 overwrite=False):
# def search(api='gtfsdataexch', search_text=None, search_field=None,
#            match='contains', add_feed=False, overwrite_feed=False):
# def download(data_folder=os.path.join(config.settings.data_folder),
#              feed_name=None, feed_url=None, feed_dict=None,
#              error_pause_duration=5, delete_zips=False):
# def _unzip(zip_rootpath, delete_zips=True):
# def _zipfile_type_check(file, feed_url_value):
# 
# Path: urbanaccess/gtfsfeeds.py
# class urbanaccess_gtfsfeeds(object):
#     def __init__(self,
#                  gtfs_feeds={}):
#     def from_yaml(cls, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                 'gtfsfeeds'),
#                   yamlname='gtfsfeeds.yaml'):
#     def to_dict(self):
#     def add_feed(self, add_dict, replace=False):
#     def remove_feed(self, del_key=None, remove_all=False):
#     def to_yaml(self, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                'gtfsfeeds'),
#                 yamlname='gtfsfeeds.yaml',
#                 overwrite=False):
# def search(api='gtfsdataexch', search_text=None, search_field=None,
#            match='contains', add_feed=False, overwrite_feed=False):
# def download(data_folder=os.path.join(config.settings.data_folder),
#              feed_name=None, feed_url=None, feed_dict=None,
#              error_pause_duration=5, delete_zips=False):
# def _unzip(zip_rootpath, delete_zips=True):
# def _zipfile_type_check(file, feed_url_value):


# Path: urbanaccess/tests/test_gtfsfeeds.py
import pytest
import os
import pandas as pd
import yaml
from urbanaccess import gtfsfeeds
from urbanaccess.gtfsfeeds import feeds

def test_search_contains_gtfs_data_exchange():
    search_result = gtfsfeeds.search(api='gtfsdataexch',
                                     search_text=['ac transit', 'santa rosa'],
                                     search_field=None, match='contains',
                                     add_feed=False, overwrite_feed=False)

    assert isinstance(search_result, pd.DataFrame)
    assert search_result.empty is False
    assert len(search_result) == 2

    col_list = ['dataexchange_url', 'dataexchange_id', 'name']
    for col in col_list:
        assert col in search_result.columns
        assert search_result[col].isnull().all() == False  # noqa

    value_list = ['ac-transit', 'santa-rosa-citybus']
    for value in value_list:
        assert value in list(search_result['dataexchange_id'])


def test_search_contains_add_feed_gtfs_data_exchange():
    gtfsfeeds.search(api='gtfsdataexch',
                     search_text='ac transit',
                     search_field=None, match='contains',
                     add_feed=True, overwrite_feed=False)

    assert len(feeds.gtfs_feeds.keys()) == 1
    assert 'AC Transit' in feeds.gtfs_feeds.keys()

    # test overwrite feed

    gtfsfeeds.search(api='gtfsdataexch',