Skip to content

Commit

Permalink
Adjust IATI validation background job runner
Browse files Browse the repository at this point in the history
  • Loading branch information
zuhdil committed Dec 26, 2023
1 parent d4b97af commit 956dd20
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion akvo/rsr/tests/rest/test_project_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ def setUp(self):
self.org = self.create_organisation('Akvo')
self.make_org_admin(self.user, self.org)
self.project = self.create_project('')
self.project.iati_activity_id = 'TEST-123'
self.project.save()
self.make_partner(self.project, self.org)
self.c = Client(HTTP_HOST=settings.RSR_DOMAIN)
self.c.login(username=self.username, password=self.password)
Expand All @@ -725,7 +727,7 @@ def test_update_project_attributes_runs_iati_checks(self):
# Given
error_checks = self.project.iati_checks.filter(status=3).count()
url = '/rest/v1/project/{}/?format=json'.format(self.project.id)
data = {"title": "DEMONSTRATION!", "date_start_planned": "2009-06-10"}
data = {"title": "DEMONSTRATION!", "date_start_planned": "2009-06-10", "iati_activity_id": "ABCD-123"}

# When
response = self.c.patch(
Expand Down
2 changes: 2 additions & 0 deletions akvo/rsr/tests/usecases/test_schedule_iati_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
class ScheduleIatiActivityValidationTestCase(BaseTestCase):
def setUp(self):
self.project = self.create_project('Test project')
self.project.iati_activity_id = 'ABC-123'
self.project.save()

def test_no_job_for_unpublished_project(self):
schedule_at = now() + timedelta(minutes=1)
Expand Down
2 changes: 2 additions & 0 deletions akvo/rsr/usecases/iati_validation/run_validation_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def get_pending_activity_jobs(scheduled_at: datetime) -> QuerySet:
def process_activity_validation_results(project: Project, validator_result: IATIValidationResult, check_result: CheckResult):
if check_result.error_count == validator_result.error_count:
return
if check_result.error_count > 0:
return
email_recipients = getattr(settings, 'IATI_ACTIVITY_VALIDATION_ERROR_RECIPIENTS', [])
if not email_recipients:
message = f'Inconsistent IATI activity validation results for project: {project.title}\n'\
Expand Down
2 changes: 1 addition & 1 deletion akvo/rsr/usecases/iati_validation/schedule_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def schedule_iati_activity_validation(project: Project, schedule_at: Optional[datetime] = None):
if project.is_published():
if project.is_published() and project.iati_activity_id:
logger.info("Scheduling IATI validation for project %s", project.id)
scheduled_at = schedule_at if schedule_at else now() + DEFAULT_SCHEDULE_DELAY_TIME
pending_jobs = IatiActivityValidationJob.objects.filter(project=project, started_at=None)
Expand Down

0 comments on commit 956dd20

Please sign in to comment.