def test_import_file_updates_db_with_players(): """ End to end test asserting that a HTML file is parsed and imported into an in-memory SQLite database. """ model = Model(echo=False) # open the HTML file file = open( path.join(PROJECT_SOURCE_PATH, 'test', 'resources', 'squad.html'), 'r' ) html = file.read() file.close() # parse the players players = parse_players(html) with model.session_scope() as session: # open a session and import our HTML file html_file = HTMLFile.from_file( path.join(PROJECT_SOURCE_PATH, 'test', 'resources', 'squad.html')) model.import_file(html_file) # retrieve the team from the database # and check that it has imported correctly new_team = session.query(Team).first() assert_equal(len(new_team.players), len(players))
def test_HTMLFile_is_squad_page_when_parsing_squad_HTML(self): """ Tests that a squad.html page is correctly recognised as a squad file""" # return a fake HTML Squad file self.mock_open.return_value.read.return_value = '<html><title>Battrick - Squad</title></html>' htmlFile = HTMLFile.from_file('a_file') assert_is(htmlFile.type, PageTypes.Squad.value)
def test_readfile_adds_imported_time(self): """ Tests that the 'current' time is added to the object """ test_date = datetime(2010, 10, 8, 12, 50, 33) with patch('core.PyBatBase.datetime') as mock_date: # fake today's date mock_date.today.return_value = test_date htmlFile = HTMLFile.from_file('a_file') assert_equal(htmlFile.date_imported, test_date)
def importfiles(self): """ Imports the files provided as a list of local filenames in the request. """ files = (cherrypy.request.json['files']) for filename in files: # generate HTMLFile objects from the filenames self.model.import_file(HTMLFile.from_file(filename)) # TODO: add response with import success/failure return "true"
def test_HTMLfile_from_file_adds_modified_time(self): """ Tests that the file modified time is added to the object """ htmlFile = HTMLFile.from_file('a_file') assert_equal(htmlFile.date_modified, self.test_date)
def test_HTMLFile_throws_PageParseException_if_wrong_title(self): """ Tests that a PageParseException is raised if the title is wrong """ self.mock_open.return_value.read.return_value = '<html><head><title>WrongTitle</title></head></html>' HTMLFile.from_file('a_file')
def test_HTMLFile_throws_PageParseException_if_empty_title(self): """ Tests that a PageParseException is raised if no <title> exists """ self.mock_open.return_value.read.return_value = '<html></html>' HTMLFile.from_file('a_file')
def test_HTMLFile_inits_throws_PageParseException_if_page_not_recognised(self): """ Tests that a PageParseException is raised if an incorrect page is parsed """ self.mock_open.return_value.read.return_value = '<html><title>Battrick - WrongPage</title></html>' HTMLFile.from_file('a_file')