def get_releases(self, filter_options): """Gets all releases fitting filter_options. Args: filter_options: object containing all filter parameters Returns: releases_data: a filtered, sorted list of release objects """ # build the SQL query release_query = to_sql_releases(filter_options) # get the data from SQL releases_data = {} for config in self._configs: raw_release_data = config.db.query(release_query) # it's a tuple, so no .append() # package the data into release objects with all neccessary info releases_data.update(read_releases(raw_release_data, config.db)) # filter for the stuff that SQL can't natively filter for, # due to some data being based on a tasks releases_data = filter_releases(releases_data, filter_options) # sort with the stuff that SQL can't natively sort according to, # due to some data being based on tasks releases_data = sort(releases_data, filter_options) return releases_data
def test_sort_method_modified_ascending(self): sorted_releases = sort(self.unsorted, 3, 0) previous = datetime.datetime.fromtimestamp(0) for item in sorted_releases: time = item.last_modified self.assertGreaterEqual(time, previous) previous = time
def test_sort_method_modified_descending(self): sorted_releases = sort(self.unsorted, 3, 1) previous = datetime.datetime.now()-datetime.datetime(1970, 1, 1) previous = previous.total_seconds() for item in sorted_releases: time = item.last_modified-datetime.datetime(1970, 1, 1) time = time.total_seconds() self.assertLessEqual(time, previous) previous = time
def test_sort_method_active_ascending(self): sorted_releases = sort(self.unsorted, 4, 0) previous_name = None for item in sorted_releases: if previous_name is None: previous_name = item.last_active_task for i, char in enumerate(item.last_active_task): if char.isalpha(): if previous_name: if len(previous_name) > i: self.assertLessEqual(char, previous_name[i]) else: break if char < previous_name[i]: break if char.isdigit(): if len(previous_name) > i: self.assertGreaterEqual(char, previous_name[i]) else: break if char > previous_name[i]: break previous_name = item.last_active_task