def test_part_one(self): "Test part one example of Passwords object" # 1. Create Passwords object from text myobj = passwords.Passwords(text=aoc_02.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
def test_part_two(self): "Test part two example of Passwords object" # 1. Create Passwords object from text myobj = passwords.Passwords(part2=True, text=aoc_02.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_text_init(self): "Test the Passwords object creation from text" # 1. Create Passwords object from text myobj = passwords.Passwords(text=aoc_02.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 3)
def test_empty_init(self): "Test the default Passwords creation" # 1. Create default Passwords object myobj = passwords.Passwords() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = passwords.Passwords(part2=True, text=input_lines) # 2. Determine the solution for part two solution = solver.part_two(verbose=args.verbose, limit=args.limit) if solution is None: print("There is no solution") else: print("The solution for part two is %s" % (solution)) # 3. Return result return solution is not None
#! /usr/bin/python3 import os import sys import MySQLdb import passwords import json import cgi import cgitb cgitb.enable() credentials = passwords.Passwords() host = credentials.getHost() user = credentials.getUser() passwrd = credentials.getPass() db = credentials.getDB() link = 'http://54.164.47.138/cgi-bin/webhooks/webhooks.py' conn = MySQLdb.connect(host=host, user=user, passwd=passwrd, db=db) def respond_404(): print("Status: 404 Not Found") print() def respond_405(): print("Status: 405 Method Not Allowed") print() def postHandler(inputData):