# 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/scraper.py
# HEADERS = {
#     "User-Agent": "ParkAPI v%s - Info: %s" %
#     (env.SERVER_VERSION, env.SOURCE_REPOSITORY),
# }
# def get_html(city):
# def parse_html(city, html):
# def add_metadata(data):
# def save_data_to_db(cursor, parking_data, city):
# def _live(module):
# def scrape_city(module):
# def main():
# 
# 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):


import os
import unittest
import helpers
import requests
import requests_mock
from park_api import env, scraper, db

class ScraperTestCase(unittest.TestCase):
    def setUp(self):
        db.setup()
    @requests_mock.Mocker()
    def test_insert(self, mock):
        path = os.path.join(helpers.TEST_ROOT, "fixtures", "dresden.html")
        cities = env.supported_cities()
        module = cities["Dresden"]
        with open(path) as f:
            src = module.geodata.city.source
            mock.get(src, text=f.read())

# 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/scraper.py
# HEADERS = {
#     "User-Agent": "ParkAPI v%s - Info: %s" %
#     (env.SERVER_VERSION, env.SOURCE_REPOSITORY),
# }
# def get_html(city):
# def parse_html(city, html):
# def add_metadata(data):
# def save_data_to_db(cursor, parking_data, city):
# def _live(module):
# def scrape_city(module):
# def main():
# 
# 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: tests/test_scraper.py
import os
import unittest
import helpers
import requests
import requests_mock
from park_api import env, scraper, db


class ScraperTestCase(unittest.TestCase):
    def setUp(self):
        db.setup()
    @requests_mock.Mocker()
    def test_insert(self, mock):
        path = os.path.join(helpers.TEST_ROOT, "fixtures", "dresden.html")
        cities = env.supported_cities()
        module = cities["Dresden"]
        with open(path) as f:
            src = module.geodata.city.source
            mock.get(src, text=f.read())

        scraper.scrape_city(module)