# Path: park_api/db.py
# POOL = None
#     POOL = ThreadedConnectionPool(1, 20,
#             database=u.path[1:],
#             user=u.username,
#             password=u.password,
#             host=u.hostname,
#             port=u.port)
# def setup(url=env.DATABASE_URI):
# def cursor(commit=False):
# 
# Path: park_api/env.py
# API_VERSION = '1.0'
# SERVER_VERSION = '0.3.0'
# SOURCE_REPOSITORY = 'https://github.com/offenesdresden/ParkAPI'
# APP_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
# SERVER_CONF = None
# ENV = None
# SUPPORTED_CITIES = None
# DATABASE = {}
# DEFAULT_CONFIGURATION = {
#     "port": 5000,
#     "host": "::1",
#     "debug": False,
#     "live_scrape": True,
#     "database_uri": "postgres:///park_api",
# }
#         SUPPORTED_CITIES = load_cities()
#     ENV = os.getenv("env", "development")
#     SERVER_CONF = structs.ServerConf(host=raw_config.get('host'),
#                                      port=raw_config.getint("port"),
#                                      debug=raw_config.getboolean("debug"))
#     LIVE_SCRAPE = raw_config.getboolean("live_scrape")
#     DATABASE_URI = raw_config.get("database_uri")
#         SERVER_VERSION = '0.3.{0}'.format(rev)
# def is_production():
# def is_development():
# def is_testing():
# def is_staging():
# def load_cities():
# def supported_cities():
# def load_config():
# def determine_server_version():
# 
# Path: park_api/security.py
# def file_is_allowed(file):


import os
import unittest
import ddt
import helpers
import importlib
from datetime import datetime
from park_api import db, env, security


def scrape_city(city):
    allowed_extensions = [".html", ".json", ".xml"]
    for extension in allowed_extensions:
        path = os.path.join(helpers.TEST_ROOT,
                            "fixtures",
                            city.lower() + extension)
        if os.path.isfile(path):
            break
    with open(path, 'rb') as f:
        city = importlib.import_module("park_api.cities." + city)
        return city.parse_html(f.read().decode('utf-8', 'replace'))

def get_tests():
    modpath = os.path.join(env.APP_ROOT, "park_api", "cities")
    strip_py = lambda name: ".".join(name.split(".")[:-1])
    for (dirpath, dirnames, filenames) in os.walk(modpath):
        return tuple(map(strip_py, filter(security.file_is_allowed, filenames)))

@ddt.ddt
class CityTestCase(unittest.TestCase):
    def setUp(self):

# Path: park_api/db.py
# POOL = None
#     POOL = ThreadedConnectionPool(1, 20,
#             database=u.path[1:],
#             user=u.username,
#             password=u.password,
#             host=u.hostname,
#             port=u.port)
# def setup(url=env.DATABASE_URI):
# def cursor(commit=False):
# 
# Path: park_api/env.py
# API_VERSION = '1.0'
# SERVER_VERSION = '0.3.0'
# SOURCE_REPOSITORY = 'https://github.com/offenesdresden/ParkAPI'
# APP_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
# SERVER_CONF = None
# ENV = None
# SUPPORTED_CITIES = None
# DATABASE = {}
# DEFAULT_CONFIGURATION = {
#     "port": 5000,
#     "host": "::1",
#     "debug": False,
#     "live_scrape": True,
#     "database_uri": "postgres:///park_api",
# }
#         SUPPORTED_CITIES = load_cities()
#     ENV = os.getenv("env", "development")
#     SERVER_CONF = structs.ServerConf(host=raw_config.get('host'),
#                                      port=raw_config.getint("port"),
#                                      debug=raw_config.getboolean("debug"))
#     LIVE_SCRAPE = raw_config.getboolean("live_scrape")
#     DATABASE_URI = raw_config.get("database_uri")
#         SERVER_VERSION = '0.3.{0}'.format(rev)
# def is_production():
# def is_development():
# def is_testing():
# def is_staging():
# def load_cities():
# def supported_cities():
# def load_config():
# def determine_server_version():
# 
# Path: park_api/security.py
# def file_is_allowed(file):


# Path: tests/test_cities.py
import os
import unittest
import ddt
import helpers
import importlib
from datetime import datetime
from park_api import db, env, security



def scrape_city(city):
    allowed_extensions = [".html", ".json", ".xml"]
    for extension in allowed_extensions:
        path = os.path.join(helpers.TEST_ROOT,
                            "fixtures",
                            city.lower() + extension)
        if os.path.isfile(path):
            break
    with open(path, 'rb') as f:
        city = importlib.import_module("park_api.cities." + city)
        return city.parse_html(f.read().decode('utf-8', 'replace'))

def get_tests():
    modpath = os.path.join(env.APP_ROOT, "park_api", "cities")
    strip_py = lambda name: ".".join(name.split(".")[:-1])
    for (dirpath, dirnames, filenames) in os.walk(modpath):
        return tuple(map(strip_py, filter(security.file_is_allowed, filenames)))

@ddt.ddt
class CityTestCase(unittest.TestCase):
    def setUp(self):

        db.setup()