def handle(self, *args, **options): available_projects = list(AVAILABLE_CHECKERS.values()) sorted_projects = sorted(available_projects, key=get_checker_group) grouped_projects = OrderedDict() for key, group in groupby(sorted_projects, key=get_checker_group): grouped_projects[key] = sorted( list(group), key=lambda p: p.name, ) projects_markdown = '' for group, projects in grouped_projects.items(): group_markdown = '\n### {group_name}\n\n'.format(group_name=group) projects_markdown += group_markdown for project in projects: project_markdown = ( '#### {0.name} \n' '**Name:** {0.name} \n' '**Slug:** {0.slug} \n' '**Homepage:** {0.homepage} \n').format(project) if project.repository: project_markdown += ( '**Repository:** {0.repository} \n'.format(project)) projects_markdown += project_markdown self.stdout.write(projects_markdown)
def cache_all_projects_latest_minor_versions(): """ Celery task responsible for getting and caching latest minor versions for all projects """ for project in AVAILABLE_CHECKERS.values(): cache_latest_minor_versions.delay(project.slug)
def test_checkers_slug_uniqueness(): """Test checkers slug uniqueness""" used_slugs = set() for project in AVAILABLE_CHECKERS.values(): slug = project.slug assert slug not in used_slugs used_slugs.add(project.slug)
def test_checkers_integration(): """ Runs integration tests on all available checkers and makes sure that all of `get_latest_version()`, `get_latest_major_versions()` and `get_latest_minor_versions()` don't raise an exception. This is run only when '--integration-tests' argument is passed to pytest """ for project in AVAILABLE_CHECKERS.values(): assert project.get_latest_version() assert project.get_latest_major_versions() assert project.get_latest_minor_versions()
def get_context_data(self, **kwargs): """ Extends Django's default `get_context_data()` behaviour and adds available projects to view context """ available_projects = list() for project in AVAILABLE_CHECKERS.values(): url = reverse( 'projects:latest', args=[project.slug], request=self.request, ) project = { 'name': project.name, 'url': url, } available_projects.append(project) random.shuffle(available_projects) kwargs['available_projects'] = available_projects[:50] return super().get_context_data(**kwargs)