class TestDatabase(unittest.TestCase): def setUp(self): ''' Stardard init method: runs before each test_* method Initializes a PluginManager ''' self.configdir = tempfile.mkdtemp() self.db = QtDBConnector(self.configdir) def tearDown(self): ''' Generic unittest.TestCase.tearDown() ''' shutil.rmtree(self.configdir) del self.db def test_get_talks(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_talks(), QtSql.QSqlQuery) def test_get_events(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_events(), QtSql.QSqlQuery) def test_get_talk_ids(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_talk_ids(), QtSql.QSqlQuery) def test_get_talks_by_event(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_talks_by_event("SC2011"), QtSql.QSqlQuery) def test_get_talks_by_room(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_talks_by_room("T105"), QtSql.QSqlQuery) def test_get_presentation(self): """Simply test that a presentation is returned""" self.assertIsInstance(self.db.get_presentation(1), Presentation) def test_get_presentations_model(self): """Simply test that a model is returned""" self.assertIsInstance(self.db.get_presentations_model(), QtSql.QSqlTableModel) def test_get_events_model(self): """Simply test that a model is returned""" self.assertIsInstance(self.db.get_events_model(), QtSql.QSqlQueryModel) def test_get_rooms_model(self): """Simply test that a model is returned""" self.assertIsInstance(self.db.get_rooms_model("SC2011"), QtSql.QSqlQueryModel) def test_get_talks_model(self): """Simply test that a model is returned""" self.assertIsInstance(self.db.get_talks_model("SC2011", "T105"), QtSql.QSqlQueryModel)
class TestDatabase(unittest.TestCase): def setUp(self): ''' Stardard init method: runs before each test_* method Initializes a PluginManager ''' self.profile_path = tempfile.mkdtemp() profile = Profile(self.profile_path, 'testing') dirname = os.path.dirname(__file__) self._csvfile = os.path.join(dirname, 'sample_talks.csv') db_file = os.path.join(self.profile_path, 'presentations.db') self.db = QtDBConnector(db_file, PluginManager(profile)) def tearDown(self): ''' Generic unittest.TestCase.tearDown() ''' shutil.rmtree(self.profile_path) def test_get_talks(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_talks(), QtSql.QSqlQuery) def test_get_events(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_events(), QtSql.QSqlQuery) def test_get_talk_ids(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_talk_ids(), QtSql.QSqlQuery) def test_get_talks_by_event(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_talks_by_event("SC2011"), QtSql.QSqlQuery) def test_get_talks_by_room(self): """Simply test that a query is returned""" self.assertIsInstance(self.db.get_talks_by_room("T105"), QtSql.QSqlQuery) def test_get_presentation(self): """Simply test that a presentation is returned""" self.assertIsInstance(self.db.get_presentation(1), Presentation) def test_get_presentations_model(self): """Simply test that a model is returned""" self.assertIsInstance(self.db.get_presentations_model(), QtSql.QSqlTableModel) def test_get_events_model(self): """Simply test that a model is returned""" self.assertIsInstance(self.db.get_events_model(), QtSql.QSqlQueryModel) def test_get_rooms_model(self): """Simply test that a model is returned""" self.assertIsInstance(self.db.get_rooms_model("SC2011"), QtSql.QSqlQueryModel) def test_get_talks_model(self): """Simply test that a model is returned""" self.assertIsInstance(self.db.get_talks_model("SC2011", "T105"), QtSql.QSqlQueryModel) def test_add_talks_from_rss(self): """Test that talks are retrieved from the RSS feed""" feed1 = "http://fosslc.org/drupal/presentations_rss/summercamp2010" feed2 = "http://fosslc.org/drupal/presentations_rss/sc2011" presentation1 = Presentation("Managing map data in a database", "Andrew Ross") presentation2 = Presentation("Building NetBSD", "David Maxwell") self.db.add_talks_from_rss(feed1) self.assertTrue(self.db.presentation_exists(presentation1)) self.db.add_talks_from_rss(feed2) self.assertTrue(self.db.presentation_exists(presentation2)) def test_add_talks_from_csv(self): """Test that talks are retrieved from the CSV file""" fname = self._csvfile presentation = Presentation("Building NetBSD", "David Maxwell") self.db.add_talks_from_csv(fname) self.assertTrue(self.db.presentation_exists(presentation))
class RecordingController: def __init__(self, cli=False, profile=None): self.config = Config(settings.configdir, profile=profile) self.db = QtDBConnector(settings.configdir) self.plugman = PluginManager(settings.configdir, profile=profile) self.media = Multimedia(self.config, self.plugman, cli=cli) def set_window_id(self, window_id): """Sets the Window ID which GStreamer should paint on""" self.media.set_window_id(window_id) def set_audio_feedback_handler(self, audio_feedback_handler): """Sets the handler for Audio Feedback levels""" self.media.set_audio_feedback_handler(audio_feedback_handler) def record(self): """Start Recording""" self.media.record() def stop(self): """Stop Recording""" self.media.stop() def pause(self): """Pause Recording""" self.media.pause() def load_backend(self, presentation=None): """Prepares the backend for recording""" initialized, filename_for_frontend = self.media.load_backend( presentation) if initialized: return True, filename_for_frontend else: return False # Error something failed while loading the backend def print_talks(self): query = self.db.get_talks() # Print the header print("\n") print("ID: Speaker - Title") print("-------------------") while (query.next()): talkid = unicode(query.value(0).toString()) title = unicode(query.value(1).toString()) speaker = unicode(query.value(2).toString()) print("{talkid}: {speaker} - {title}".format(talkid=talkid, speaker=speaker, title=title)) ### ### Convenience commands ### def record_talk_id(self, talk_id): """Records using a known Talk ID Returns True if recording is successfully started Returns False if any issues arise """ presentation = self.db.get_presentation(talk_id) if self.media.load_backend(presentation): # Only record if the backend successfully loaded # No need to print error on failure since load_backend already # prints an error message self.record() return True else: return False def record_filename(self, filename): """Records to a specific filename Returns True if recording is successfully started Returns False if any issues arise """ if self.media.load_backend(filename=filename): self.record() return True else: return False
class RecordingController: def __init__(self, cli=False, profile=None): self.config = Config(settings.configdir, profile=profile) self.db = QtDBConnector(settings.configdir) self.plugman = PluginManager(settings.configdir, profile=profile) self.media = Multimedia(self.config, self.plugman, cli=cli) def set_window_id(self, window_id): """Sets the Window ID which GStreamer should paint on""" self.media.set_window_id(window_id) def set_audio_feedback_handler(self, audio_feedback_handler): """Sets the handler for Audio Feedback levels""" self.media.set_audio_feedback_handler(audio_feedback_handler) def record(self): """Start Recording""" self.media.record() def stop(self): """Stop Recording""" self.media.stop() def pause(self): """Pause Recording""" self.media.pause() def load_backend(self, presentation=None): """Prepares the backend for recording""" initialized, filename_for_frontend = self.media.load_backend(presentation) if initialized: return True, filename_for_frontend else: return False # Error something failed while loading the backend def print_talks(self): query = self.db.get_talks() # Print the header print("\n") print("ID: Speaker - Title") print("-------------------") while(query.next()): talkid = unicode(query.value(0).toString()) title = unicode(query.value(1).toString()) speaker = unicode(query.value(2).toString()) print("{talkid}: {speaker} - {title}".format(talkid=talkid, speaker=speaker, title=title)) ### ### Convenience commands ### def record_talk_id(self, talk_id): """Records using a known Talk ID Returns True if recording is successfully started Returns False if any issues arise """ presentation = self.db.get_presentation(talk_id) if self.media.load_backend(presentation): # Only record if the backend successfully loaded # No need to print error on failure since load_backend already # prints an error message self.record() return True else: return False def record_filename(self, filename): """Records to a specific filename Returns True if recording is successfully started Returns False if any issues arise """ if self.media.load_backend(filename=filename): self.record() return True else: return False