from twilio.twiml.messaging_response import MessagingResponse from flask import Flask, request, render_template from hue_controller import HueController from name_converter import clean_name from data_writer import writeFile,colorPercent,mostRecentColors,numOfEachColor,invalidColors,firstEntryDate from previousRedisColor import PreviousColorsRedis from html_colors_generator import generate_colors_from_redis from colors_redis import colorsRedis import logging logging.basicConfig(level=logging.INFO,filename="hue_log.log", format="%(asctime)s:%(levelname)s:%(message)s" ) app = Flask(__name__) controller = HueController() file = "data.csv" @app.route('/', methods=['POST']) def set_color(): phone_number = request.values.get('From', None) color_name = request.values.get('Body', None) color_name = clean_name(color_name) if color_name == "black": response = MessagingResponse() response.message("Haha... please use a color that contains light.") return str(response) if color_name == "previous": prev_color = PreviousColorsRedis().getPreviousColor() response = MessagingResponse()
import csv, unittest, os from data_writer import writeFile, mostRecentColors, numOfEachColor, invalidColors from hue_controller import HueController controller = HueController() filename = "testdata.csv" red_message = controller.set_color("red") blue_message = controller.set_color("blue") green_message = controller.set_color("green") white_message = controller.set_color("white") yellow_message = controller.set_color("yellow") foo_message = controller.set_color("foo") filePath = os.path.abspath("testdata.csv") class csvTest(unittest.TestCase): def testWriteFile(self): fileCreator.createTestFile(self) with open(filename) as data: data_reader = csv.reader(data) num = [] for row in data_reader: num.append(row) self.assertEqual(len(num), 16) os.remove(filePath) def testListMostRecent(self): fileCreator.createTestFile(self) expectedColors = ['yellow', 'blue', 'red', 'white', 'blue'] self.assertListEqual(expectedColors, mostRecentColors(filename))