Skip to content

Commit

Permalink
LITE-30091 Invalid rql filter when fetching reports for upload creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatrios committed Apr 29, 2024
1 parent ff2c593 commit b7a876e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 22 deletions.
2 changes: 1 addition & 1 deletion connect_bi_reporter/uploads/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ def disable_feeds(db, feeds, logger):
def create_uploads(db, client, logger, feeds):
feeds_to_disable = []
uploads = []
rql = R().status.eq('succeeded')
feed_ids = [f.id for f in feeds]
existing_reports_ids = util.flatten_iterator(db.query(Upload.report_id).filter(
Upload.feed_id.in_(feed_ids),
))
for feed in feeds:
report_file = None
rql = R().status.eq('succeeded')
rql &= R().account.id.eq(feed.account_id) & R().schedule.id.eq(feed.schedule_id)
reason, mark_as_disabled = _get_report_schedule_reason(client, feed.schedule_id)
if mark_as_disabled:
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ services:
DATABASE_URL: postgresql+psycopg2://postgres:1q2w3e@db/bi_reporter
depends_on:
- db
links:
- "db_ram:db"

connect_bi_reporter_test:
container_name: connect_bi_reporter_test
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sqlalchemy = "^1.3.12"
psycopg2-binary = "^2.9.6"
pyjwt = "^2.8.0"
azure-storage-blob = "^12.19.0"
connect-extension-utils = "^1.0.0"
connect-extension-utils = "^1.2.0"

[tool.poetry.dev-dependencies]
pytest = ">=6.1.2,<8"
Expand Down
60 changes: 47 additions & 13 deletions tests/uploads/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import re
from unittest.mock import call

import pytest
from connect.client import ClientError
from connect.client.rql import R
from connect.eaas.core.inject.models import Context
from sqlalchemy.exc import DBAPIError

Expand Down Expand Up @@ -213,7 +215,10 @@ def test_create_upload_schedule_task(
'account_id': installation['owner']['id'],
},
}
report_file = {'id': 'RP-262-019-481', 'renderer': 'csv'}
report_file = [
{'id': 'RP-262-019-481', 'renderer': 'csv'},
{'id': 'RP-262-019-482', 'renderer': 'csv'},
]
ext = ConnectBiReporterEventsApplication(
connect_client,
logger,
Expand All @@ -232,37 +237,66 @@ def test_create_upload_schedule_task(
'connect_bi_reporter.uploads.services.get_report_schedule',
return_value=report_schedule,
)
mocker.patch(
p_get_reporting_report = mocker.patch(
'connect_bi_reporter.uploads.services.get_reporting_report',
return_value=report_file,
side_effect=report_file,
)
mocker.patch(
'connect_bi_reporter.scheduler.create_schedule_task',
return_value=eaas_schedule_task,
)
feed = feed_factory(
feed1 = feed_factory(
schedule_id=report_schedule['id'],
account_id=installation['owner']['id'],
status=feed_factory._meta.model.STATUSES.enabled,
)
feed2 = feed_factory(
schedule_id=report_schedule['id'],
account_id=installation['owner']['id'],
status=feed_factory._meta.model.STATUSES.enabled,
)

result = ext.create_uploads(schedule)
upload = dbsession.query(upload_factory._meta.model).first()
assert result.status == 'success'
assert upload.report_id == report_file['id']
assert upload.status == upload_factory._meta.model.STATUSES.pending
assert upload.feed_id == feed.id
uploads = dbsession.query(upload_factory._meta.model).all()
p_get_reporting_report.assert_has_calls(
[
call(
connect_client, (
R().status.eq('succeeded') & R().account.id.eq(feed1.account_id)
& R().schedule.id.eq(feed1.schedule_id)
),
),
call(
connect_client, (
R().status.eq('succeeded') & R().account.id.eq(feed2.account_id)
& R().schedule.id.eq(feed2.schedule_id)
),
),
],
)
for idx, zipped in enumerate(zip(uploads, [feed1, feed2])):
upload, feed = zipped
assert result.status == 'success'
assert upload.report_id == report_file[idx]['id']
assert upload.status == upload_factory._meta.model.STATUSES.pending
assert upload.feed_id == feed.id

assert logger.method_calls[0].args[0] == (
f'New Uploads were created: `Upload={upload.id}'
f' for Feed={feed.id}`.'
f'New Uploads were created: `Upload={uploads[0].id} for Feed={feed1.id}, '
f'Upload={uploads[1].id} for Feed={feed2.id}`.'
)
assert logger.method_calls[1].args[0] == (
f'Periodic Schedule Task created: `{eaas_schedule_task["id"]}`.'
)
assert logger.method_calls[2].args[0] == (
f'New Scheduled Task `{eaas_schedule_task["id"]}`'
f' created for Upload `{upload.id}`: '
f'Will process Report File `{report_file["id"]}`'
f' created for Upload `{uploads[0].id}`: '
f'Will process Report File `{report_file[0]["id"]}`'
)
assert logger.method_calls[4].args[0] == (
f'New Scheduled Task `{eaas_schedule_task["id"]}`'
f' created for Upload `{uploads[1].id}`: '
f'Will process Report File `{report_file[1]["id"]}`'
)


Expand Down

0 comments on commit b7a876e

Please sign in to comment.