# Path: publisher.py
# class Publisher:
# 
#     @staticmethod
#     def __fetchgithubips():
#         jsonResponse = requests.get("https://api.github.com/meta", auth=("KentonCountyLibrary-Cincypy", "CincyPyCoders2000"))
#         ipranges = jsonResponse.json()["hooks"]
# 
#         ipranges = [list(ip_network(ip).hosts()) for ip in ipranges]
# 
#         # Flatten the matrix to an array
#         flat_range = list(chain.from_iterable(ipranges))
#         return flat_range
# 
#     def in_ip_address_range(self):
#         return self.ip in Publisher.__fetchgithubips()
# 
#     def __init__(self, ip, sourcebranch, payload):
#         # use https://api.github.com/meta to get github ipaddresses
#         self.sourcebranch = sourcebranch
#         self.payload = payload
#         self.ip = ip_address(ip)
# 
# Path: config.py
# def sitename_from_readme():
# def splitcamel(s):
#     def __init__(self):
# class Config(object):
# class TestConfig(Config):
#     NAME = "DEBUG"
#     SECRET_KEY = os.environ.get("SECRET_KEY")
#     DEBUG = True
#     MAIL_SERVER = "smtp.gmail.com"
#     MAIL_USERNAME = "KentonCountyLibrary@gmail.com"
#     MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD",None)
#     MAIL_PORT = 587
#     MAIL_USE_TLS = True
#     MAIL_DEFAULT_SENDER = "KentonCountyLibrary@gmail.com"
#     SQLALCHEMY_DATABASE_URI = "sqlite:///library.db"
#     SITENAME = sitename_from_readme()
#     SITENAMEPARTS = splitcamel(SITENAME)
#     NAME = "TEST"
#     SQLALCHEMY_DATABASE_URI = "sqlite://"


import unittest
import flask
import requests
import library
import models
import flask
import os
import sys
import datetime
from itertools import chain
from ipaddress import ip_network
from publisher import Publisher
from sqlalchemy import or_, and_
from config import config
                _csrf_token = flask.session['_csrf_token'],
            ), follow_redirects=True)
            self.assertIn("contact request was received",response.data)
            patroncontact=models.PatronContact.query.filter(and_(
                models.PatronContact.username=='fred',
                models.PatronContact.name=='Jeff Johnson',
                models.PatronContact.email=='test@test.net',
                models.PatronContact.contact=='irl',
                models.PatronContact.times=='Anytime')).first()
            self.assertIsNotNone(patroncontact)

            #test contact page exists
            response = self.app.get("/contact/fred")
            self.assertIn("Contact Fred",response.data)
            #confirm that default contact preference is/not present
            self.assertIn("In Person",response.data)
            self.assertNotIn("Online Chat",response.data)

            #add In Person contact request
            response = c.post("/contact/fred",data=dict(
                test = True,
                name = 'Jeff Johnson',
                email = 'test@test.net',
                contact = 'irl',
                times = 'Anytime',
                _csrf_token = flask.session['_csrf_token'],
            ), follow_redirects=True)
            self.assertIn("contact request was received",response.data)
            patroncontact=models.PatronContact.query.filter(and_(
                models.PatronContact.username=='fred',

# Path: publisher.py
# class Publisher:
# 
#     @staticmethod
#     def __fetchgithubips():
#         jsonResponse = requests.get("https://api.github.com/meta", auth=("KentonCountyLibrary-Cincypy", "CincyPyCoders2000"))
#         ipranges = jsonResponse.json()["hooks"]
# 
#         ipranges = [list(ip_network(ip).hosts()) for ip in ipranges]
# 
#         # Flatten the matrix to an array
#         flat_range = list(chain.from_iterable(ipranges))
#         return flat_range
# 
#     def in_ip_address_range(self):
#         return self.ip in Publisher.__fetchgithubips()
# 
#     def __init__(self, ip, sourcebranch, payload):
#         # use https://api.github.com/meta to get github ipaddresses
#         self.sourcebranch = sourcebranch
#         self.payload = payload
#         self.ip = ip_address(ip)
# 
# Path: config.py
# def sitename_from_readme():
# def splitcamel(s):
#     def __init__(self):
# class Config(object):
# class TestConfig(Config):
#     NAME = "DEBUG"
#     SECRET_KEY = os.environ.get("SECRET_KEY")
#     DEBUG = True
#     MAIL_SERVER = "smtp.gmail.com"
#     MAIL_USERNAME = "KentonCountyLibrary@gmail.com"
#     MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD",None)
#     MAIL_PORT = 587
#     MAIL_USE_TLS = True
#     MAIL_DEFAULT_SENDER = "KentonCountyLibrary@gmail.com"
#     SQLALCHEMY_DATABASE_URI = "sqlite:///library.db"
#     SITENAME = sitename_from_readme()
#     SITENAMEPARTS = splitcamel(SITENAME)
#     NAME = "TEST"
#     SQLALCHEMY_DATABASE_URI = "sqlite://"


# Path: tests.py
import unittest
import flask
import requests
import library
import models
import flask
import os
import sys
import datetime
from itertools import chain
from ipaddress import ip_network
from publisher import Publisher
from sqlalchemy import or_, and_
from config import config

                _csrf_token = flask.session['_csrf_token'],
            ), follow_redirects=True)
            self.assertIn("contact request was received",response.data)
            patroncontact=models.PatronContact.query.filter(and_(
                models.PatronContact.username=='fred',
                models.PatronContact.name=='Jeff Johnson',
                models.PatronContact.email=='test@test.net',
                models.PatronContact.contact=='irl',
                models.PatronContact.times=='Anytime')).first()
            self.assertIsNotNone(patroncontact)

            #test contact page exists
            response = self.app.get("/contact/fred")
            self.assertIn("Contact Fred",response.data)
            #confirm that default contact preference is/not present
            self.assertIn("In Person",response.data)
            self.assertNotIn("Online Chat",response.data)

            #add In Person contact request
            response = c.post("/contact/fred",data=dict(
                test = True,
                name = 'Jeff Johnson',
                email = 'test@test.net',
                contact = 'irl',
                times = 'Anytime',
                _csrf_token = flask.session['_csrf_token'],
            ), follow_redirects=True)
            self.assertIn("contact request was received",response.data)
            patroncontact=models.PatronContact.query.filter(and_(
                models.PatronContact.username=='fred',

                models.PatronContact.name=='Jeff Johnson',