def test_send_build_status_with_remote_repo_gitlab(self, send_build_status): self.project.repo = 'https://gitlab.com/test/test/' self.project.save() social_account = get(SocialAccount, user=self.eric, provider='gitlab') remote_repo = get(RemoteRepository, project=self.project) get(RemoteRepositoryRelation, remote_repository=remote_repo, user=self.eric, account=social_account) external_version = get(Version, project=self.project, type=EXTERNAL) external_build = get(Build, project=self.project, version=external_version) tasks.send_build_status(external_build.id, external_build.commit, BUILD_STATUS_SUCCESS) send_build_status.assert_called_once_with( build=external_build, commit=external_build.commit, state=BUILD_STATUS_SUCCESS, link_to_build=False, ) self.assertEqual(Message.objects.filter(user=self.eric).count(), 0)
def delete_inactive_external_versions(limit=200, days=30 * 3): """ Delete external versions that have been marked as inactive after ``days``. The commit status is updated to link to the build page, as the docs are removed. """ days_ago = datetime.now() - timedelta(days=days) queryset = Version.external.filter( active=False, modified__lte=days_ago, )[:limit] for version in queryset: try: last_build = version.last_build if last_build: status = BUILD_STATUS_PENDING if last_build.finished: status = BUILD_STATUS_SUCCESS if last_build.success else BUILD_STATUS_FAILURE send_build_status( build_pk=last_build.pk, commit=last_build.commit, status=status, link_to_build=True, ) except Exception: log.exception( "Failed to send status: project=%s version=%s", version.project.slug, version.slug, ) else: log.info( "Removing external version. project=%s version=%s", version.project.slug, version.slug, ) version.delete()
def test_send_build_status_task_without_remote_repo( self, send_build_status): external_version = get(Version, project=self.project, type=EXTERNAL) external_build = get(Build, project=self.project, version=external_version) tasks.send_build_status(external_build.id, BUILD_STATUS_SUCCESS) send_build_status.assert_not_called()
def test_send_build_status_no_remote_repo_or_social_account_gitlab( self, send_build_status): self.project.repo = 'https://gitlab.com/test/test/' self.project.save() external_version = get(Version, project=self.project, type=EXTERNAL) external_build = get(Build, project=self.project, version=external_version) tasks.send_build_status(external_build.id, external_build.commit, BUILD_STATUS_SUCCESS) send_build_status.assert_not_called() self.assertEqual(Message.objects.filter(user=self.eric).count(), 1)
def test_send_build_status_task(self, send_build_status): social_account = get(SocialAccount, provider='github') remote_repo = get(RemoteRepository, account=social_account, project=self.project) remote_repo.users.add(self.eric) external_version = get(Version, project=self.project, type=EXTERNAL) external_build = get(Build, project=self.project, version=external_version) tasks.send_build_status(external_build.id, BUILD_STATUS_SUCCESS) send_build_status.assert_called_once_with(external_build, BUILD_STATUS_SUCCESS)
def test_send_build_status_task_with_social_account( self, send_build_status): social_account = get(SocialAccount, user=self.eric, provider='github') self.project.repo = 'https://github.com/test/test/' self.project.save() external_version = get(Version, project=self.project, type=EXTERNAL) external_build = get(Build, project=self.project, version=external_version) tasks.send_build_status(external_build.id, external_build.commit, BUILD_STATUS_SUCCESS) send_build_status.assert_called_once_with(external_build, external_build.commit, BUILD_STATUS_SUCCESS)
def test_send_build_status_with_remote_repo_github(self, send_build_status): self.project.repo = 'https://github.com/test/test/' self.project.save() social_account = get(SocialAccount, provider='github') remote_repo = get(RemoteRepository, account=social_account, project=self.project) remote_repo.users.add(self.eric) external_version = get(Version, project=self.project, type=EXTERNAL) external_build = get( Build, project=self.project, version=external_version ) tasks.send_build_status( external_build.id, external_build.commit, BUILD_STATUS_SUCCESS ) send_build_status.assert_called_once_with( external_build, external_build.commit, BUILD_STATUS_SUCCESS ) self.assertEqual(Message.objects.filter(user=self.eric).count(), 0)