def test_delete(self): ''' Test run deletion ''' # Delete the run inserted by this test runs = DBSession.query(Run).filter(Run.user_name==self._insert_name) assert runs.all() for run in runs: DBSession.delete(run) DBSession.commit() # Ensure deletion runs = DBSession.query(Run).filter(Run.user_name==self._insert_name) assert not runs.all()
def test_delete(self): """ This method tests the ability of the runs table to delete data from it. The expected result of this is for the data to be correctly deleted from the table. """ # Delete the run inserted by this test runs = DBSession.query(Run).filter(Run.user_name==self._insert_name) # Assert that the runs have been retrieved assert runs.all() for run in runs: DBSession.delete(run) DBSession.commit() runs = DBSession.query(Run).filter(Run.user_name==self._insert_name) # Assert that the selected runs have been deleted. assert not runs.all()
def get_run_for_time_slot(cls, time_slot): """ @param time_slot The time slot the database should query for a run. @return The run that occupies the specified time slot if one exists, otherwise None. Returns a run if it exists for the given time slot otherwise return None """ return DBSession.query(Run).filter(Run.time_slot == time_slot).all()
def test_query(self): """ This method tests the ability of the runs table to retrieve data from the runs table. The expected result of this is for a row to be retrieved from the table correctly. """ # Test logic works assert DBSession.query(Run).filter(Run.user_name==self._insert_name).all() # Test logic works as expected (Grid object is not altered in any way) for row in DBSession.query(Run).filter(Run.user_name==self._insert_name).all(): returned_pattern = row.input_pattern.split('\n') test_pattern = create_input_pattern().split('\n') for x, row in enumerate(test_pattern): # For each row of the pattern for y, col in enumerate(row): if test_pattern[x][y] == '*': # Assert that the retrieved pattern and the test pattern match at these 'coordinates'. assert returned_pattern[x][y] == '*' else: # Assert that the retrieved pattern and the test pattern match at these 'coordinates'. assert returned_pattern[x][y] == '-'
def teardown_class(self): """ This method tears down the class after testing has been completed, in order to ensure no data exists after testing that shouldn't. In this case, closes down the database session. """ with transaction.manager: for run in DBSession.query(Run).all(): # Delete all runs in the database. DBSession.delete(run) DBSession.commit() # Close the database session. DBSession.remove() testing.tearDown()
def teardown_class(self): """ This method tears down the testing logic to ensure that no data remains after testing that shouldn't. In this case, it closes the database session. """ with transaction.manager: for run in DBSession.query(Run).all(): # Delete every run in the session. DBSession.delete(run) DBSession.commit() # Close the session. DBSession.remove() testing.tearDown()
def get_runs_for_day(cls, date): """ This method retrieves every run set to take place on the given data. @param date The date for which the runs to take place should be retrieved. @return The runs set to take place for the day. """ now = datetime.datetime.now() start = date end = date + datetime.timedelta(days=1) # Query the runs that are happening at this hour run_times = ( DBSession.query(Run).filter(and_(Run.time_slot < end, Run.time_slot >= start, Run.time_slot > now)).all() ) return run_times
def get_unsent_runs(cls, min_time): """ This method retrieves all of the currently unsent patterns in the database that are set to occur after the given minimum time. @param min_time The time after which the database should be query. @return unsent_runs The runs that have not yet been sent to the Raspberry Pi. """ with transaction.manager: unsent_runs = DBSession.query(Run).filter(and_(Run.time_slot > min_time, Run.sent == False)).all() for run in unsent_runs: run.sent = True DBSession.commit() return unsent_runs
def test_query(self): ''' Test querying of data from the runs table ''' assert DBSession.query(Run).filter(Run.user_name==self._insert_name).all()