def test_view(self): view = MVC.View() controller = ControllerMock(view) view.register(controller) self.assertIs(view.answer_button, None, "The answer button should not be set.") self.assertIs(view.continue_button, None, "The continue button should not be set.") view.new_question("Test", ["correct", "incorrect"]) self.assertIsNot(view.answer_button, None, "The answer button should be set.") self.assertIs(view.continue_button, None, "The continue button should not be set.") # simulate a button press view.answer_button.invoke() self.assertIs(view.answer_button, None, "The answer button should not be set.") self.assertIsNot(view.continue_button, None, "The continue button should be set.") self.assertEqual(controller.question, "Test", "The question asked should be \"Test\".") self.assertEqual(controller.answer, "correct", "The answer given should be \"correct\".") # continue view.continue_button.invoke() self.assertIsNot(view.answer_button, None, "The answer button should be set.") self.assertIs(view.continue_button, None, "The continue button should not be set.")
def test_controller(self): model = ModelMock() view = ViewMock() controller = MVC.Controller(model, view) controller.new_question() self.assertEqual(view.question, "Question", "Controller should pass the question to the view.") controller.answer("Question", "correct") self.assertEqual(controller.view.mock_feedback, "That is correct.", "The feedback for a correct answer is wrong.") controller.answer("Question", "incorrect") self.assertEqual(controller.view.mock_feedback, "Sorry that's wrong.", "The feedback for an incorrect answer is wrong.")
def test_model(self): model = MVC.Model() question, possible_answers = model.question_and_answers() # can't test what they are because they're random self.assertTrue(isinstance(question, str), "Question should be a string") self.assertTrue(isinstance(possible_answers, list), "Answers should be a list") for item in possible_answers: self.assertTrue( isinstance(item[0], str), "Elements of possible answer list should be strings")
def find_company( company_name, wiki_url ): company = { 'name' : company_name, 'wikipedia' : 'http://en.wikipedia.org' + wiki_url } info = find_company_info( wiki_url ) if info: for key,value in info.iteritems(): if 'headquarters' in key.lower(): company['headquarters'] = value elif 'founded' in key.lower(): company['founded'] = value elif 'industry' in key.lower(): company['industry'] = value CompanyModel = MVC.loadModel( 'Company' ) try: CompanyModel.create( company ) except UnicodeEncodeError: print 'UnicodeEncodeError, cannot create company'
# End file header # Install our primary dependancies subprocess.call( "apt-get install python-mysqldb", shell=True ) subprocess.call( "apt-get install python-bs4", shell=True ) # Install web dependancies subprocess.call( "apt-get install python-cherrypy3", shell=True ) subprocess.call( "apt-get install python-jinja2", shell=True ) # Install our data download # Install our data manipulation dependancies subprocess.call( "apt-get install python-numpy", shell=True ) Mysql = MVC.loadDriver('Mysql' ) Mysql.ex( 'CREATE DATABASE IF NOT EXISTS `%s`;' % MVC.db['name'] ) if( len( sys.argv ) > 1 and sys.argv[1] == 'cleanup' ): dropTable_options = "DROP TABLE IF EXISTS `%s`.`options`; " % MVC.db['name'] dropTable_users = "DROP TABLE IF EXISTS `%s`.`users`; " % MVC.db['name'] dropTable_usermeta = "DROP TABLE IF EXISTS `%s`.`usermeta`; " % MVC.db['name'] dropTable_acl_roles = "DROP TABLE IF EXISTS `%s`.`acl_roles`; " % MVC.db['name'] dropTable_acl_permissions = "DROP TABLE IF EXISTS `%s`.`acl_permissions`; " % MVC.db['name'] dropTable_acl_role_perms = "DROP TABLE IF EXISTS `%s`.`acl_role_perms`; " % MVC.db['name'] dropTable_acl_user_perms = "DROP TABLE IF EXISTS `%s`.`acl_user_perms`; " % MVC.db['name'] dropTable_acl_user_roles = "DROP TABLE IF EXISTS `%s`.`acl_user_roles`; " % MVC.db['name'] dropTable_companies = "DROP TABLE IF EXISTS `%s`.`companies`; " % MVC.db['name'] dropTable_companies_meta = "DROP TABLE IF EXISTS `%s`.`companies_meta`; " % MVC.db['name'] dropTable_companies_types = "DROP TABLE IF EXISTS `%s`.`companies_types`; " % MVC.db['name'] dropTable_companies_industry = "DROP TABLE IF EXISTS `%s`.`companies_industry`;" % MVC.db['name']
index = open(rp + '/.mvc/index.json', 'r+') newIndexData = json.load(index) newIndexData['repoPath'] = rp index.seek(0) index.truncate() json.dump(newIndexData,index) index.close() timeout = False socketIO.disconnect() if __name__=='__main__': domainIP = '172.17.0.8' domainPort = 80 rp = init.mvcInit() m = MVC.MVC(repoPath=rp) dbName = m.getDbName() flag = 1 timeout = True print("Connecting to Server", sys.stdout) sys.stdout.flush() while flag < 6 : try: with SocketIO(domainIP, domainPort,wait_for_connection=False) as socketIO: socketIO.emit("pullDB", {"dbName": dbName}) socketIO.on("pullSignal", pullSignal) socketIO.wait() if not timeout : m.mergeWithLatestVersion() os.remove(os.path.join(rp, '.mvc/old_index.json')) flag = 6
#!/usr/bin/python """ Update Companies """ import sys import urllib2 from bs4 import BeautifulSoup import re sys.path.append( '../web/' ) import MVC as MVC MVC = MVC.MVC() CompaniesModel = MVC.loadModel( 'Companies' ) def start(): companies = CompaniesModel.getUpdateSet() for company in companies: print company['wikipedia'] soup = get_soup( company['wikipedia'] ) description = get_description( soup ) sys.exit() def get_description( soup ): p_tags = soup.find('div', { 'id' : 'mw-content-text' } ).findAll('p') for tag in p_tags: print clean_wiki_text( tag ) sys.exit()
#!/usr/bin/python """ UNIT TESTER """ import sys sys.path.append( '../web/' ) import MVC as MVC MVC = MVC.MVC() JobLog = MVC.loadModel('JobLog') ModelCompany = MVC.loadModel('Company') ModelCompanies = MVC.loadModel('Companies') ModelCompanyTypes = MVC.loadModel('CompanyTypes') ModelNews = MVC.loadModel('News') ModelNewsSources = MVC.loadModel('NewsSources') ModelPerson = MVC.loadModel('Person') Wikipedia = MVC.loadDriver('Wikipedia') GoogleNews = MVC.loadDriver('GoogleNews') Debugger = MVC.loadHelper('Debug') if __name__ == "__main__": ModelNewsSources.updateCounts()
from PIL import ImageTk, Image from tkinter import Tk, filedialog, simpledialog, Frame, LabelFrame, Label, Button, Menu import platform import csv import MVC import threading # Root window created, can add more later # windows within windows. root = Tk() c = MVC.Controller(MVC.Model(), MVC.View()) class Window(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.master = master self.init_window() # Creation of init_window def init_window(self): # changing the title of our master widget self.master.title("GUI") def popup(): S1 = simpledialog.askstring('Input file name', 'file name') # prints the string typed in by the user, make a funtion to save the file by that name. print(S1) if platform.system() == 'Windows': newline = ''
#!/usr/bin/python """ Data Exporter Creates two exports, one for site backup, one for public sharing """ import os import sys import urllib2 from bs4 import BeautifulSoup sys.path.append( '../web/' ) import MVC as MVC MVC = MVC.MVC() Backup = MVC.loadHelper( 'Backup' ) print MVC.app_dir print 'Backing Up Database' # Backup.database( phile='public', tables=['companies', 'company_meta', 'people', 'people_meta'] ) # Backup.database( phile='backup')