def test_main(caplog): """Test main function """ caplog.set_level(logging.INFO) cdb.main(["-i", "./data/head-cust.csv"]) output = [record for record in caplog.records] assert "Parsing command line arguments..." in str(output) assert "Initializes the HP Norton database from csv" in str(output) assert "Adding tables..." in str(output) for record in range(9): assert f"Adding record for C00000{record}" in str(output) assert "End of file" in str(output) assert "Closing database" in str(output) with open("./data/head-cust.csv", "rb") as content: next(content) lines = content.read().decode("utf-8", errors="ignore").split("\n") for line in lines[:-1]: customer = line.split(",") item = cdb.db.Customer.get( cdb.db.Customer.customer_id == customer[0]) assert item.customer_id == customer[0] assert item.name == customer[1] assert item.last_name == customer[2] assert item.home_address == customer[3] assert item.phone_number == customer[4] assert item.email_address == customer[5] assert item.status.lower() == customer[6].lower() assert int(item.credit_limit) == int(customer[7]) cleanup_database()
def main(): query, sql_password, user, password, selected_browser = get_args() os.environ['sql_password'] = sql_password # drop_database() log = logger.create_log() log.info('Starting to collect data') print('Starting to collect data') create_db.main() soup_tweets = get_tweets(log=log, query=query, user=user, password=password, user_browser=selected_browser) tweets_dict = create_tweets_obj(tweets=soup_tweets, log=log) store_tweets_dict(tweets_dict, query, user, log) log.info('Finished running') print('Finished running')
def test_main(caplog): """Test main function """ engine = create_engine("sqlite:///HPNorton.db") db_session = sessionmaker(bind=engine) session = db_session() metadata = MetaData(bind=engine) customers = Table("Customer", metadata, autoload=True) caplog.set_level(logging.INFO) cdb.main(["-i", "./data/head-cust.csv"]) output = [record for record in caplog.records] assert "Parsing command line arguments..." in str(output) assert "Initializes the HP Norton database from csv" in str(output) assert "Adding tables..." in str(output) for record in range(9): assert f"Adding record for C00000{record}" in str(output) assert "End of file" in str(output) assert "Closing database" in str(output) with open("./data/head-cust.csv", "rb") as content: next(content) lines = content.read().decode("utf-8", errors="ignore").split("\n") for line in lines[:-1]: customer = line.split(",") select_st = customers.select().where( customers.c.customer_id == customer[0]) query = session.execute(select_st) for item in query: assert item.customer_id == customer[0] assert item.name == customer[1] assert item.last_name == customer[2] assert item.home_address == customer[3] assert item.phone_number == customer[4] assert item.email_address == customer[5] assert item.status.lower() == customer[6].lower() assert int(item.credit_limit) == int(customer[7]) cleanup_database(customers)
""" Functions to modify customer information in the customers.db table. """ import logging from peewee import JOIN, DoesNotExist import create_db import customer_model as cm logging.basicConfig(level=logging.DEBUG) LOGGER = logging.getLogger(__name__) create_db.main() # create file handler which logs even debug messages log_file = logging.FileHandler('db.log') # create formatter and add it to the handlers formatter = logging.Formatter('%(asctime)s %(filename)s:%(lineno)-3d \ %(levelname)s %(message)s') log_file.setFormatter(formatter) LOGGER.addHandler(log_file) def add_customer(customer_id, name, lastname, home_address, phone_number, email_address, active, credit_limit): """ Adds a customer to the database. Must have all parameters set for full customer record. :param customer_id: Customer identification number :param name: First name :param lastname: Last name :param home_address: Home address of customer
import cherryproxy import sys import os import create_db import urlparse, urllib2, httplib, sys, threading, logging from cherryproxy import wsgiserver import sqlite3 create_db.main("capture2.pcap") #__version__ = '0.13' #SERVER_NAME = 'CherryProxy/%s' % __version__ request_uri = "" req_method = "" req_uri = "" count_index = 0 class CherryProxy_tcpreplay(cherryproxy.CherryProxy): global request_uri global req_method global req_uri global conunt_index global req_path global req_host def filter_request(self): pass def filter_request_headers(self): global request_uri global req_method global req_uri global conunt_index global req_path
def wacot_create(args): create_db.main()
import cherryproxy import sys import os import create_db import urlparse, urllib2, httplib, sys, threading, logging from cherryproxy import wsgiserver import sqlite3 create_db.main("capture2.pcap") #__version__ = '0.13' #SERVER_NAME = 'CherryProxy/%s' % __version__ request_uri = "" req_method = "" req_uri = "" count_index = 0 class CherryProxy_tcpreplay(cherryproxy.CherryProxy): global request_uri global req_method global req_uri global conunt_index global req_path global req_host def filter_request(self): pass def filter_request_headers(self): global request_uri