-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue 3266] mod factories opp attach staging (#3370)
## Summary Fixes #{[3266](#3266)} ### Time to review: __10 mins__ ## Changes proposed > Added class method to staging and foreign Opportunity Factory > Added test --------- Co-authored-by: nava-platform-bot <[email protected]>
- Loading branch information
1 parent
263f8b3
commit 89581c1
Showing
5 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
from sqlalchemy.orm import Mapped, foreign, relationship | ||
|
||
from src.db.models.legacy_mixin import synopsis_mixin | ||
from src.db.models.staging.staging_base import StagingBase, StagingParamMixin | ||
|
||
from .opportunity import Topportunity | ||
|
||
|
||
class TsynopsisAttachment(StagingBase, synopsis_mixin.TsynopsisAttachmentMixin, StagingParamMixin): | ||
__tablename__ = "tsynopsisattachment" | ||
|
||
opportunity: Mapped[Topportunity | None] = relationship( | ||
Topportunity, | ||
primaryjoin=lambda: TsynopsisAttachment.opportunity_id | ||
== foreign(Topportunity.opportunity_id), | ||
uselist=False, | ||
overlaps="opportunity", | ||
) |
41 changes: 41 additions & 0 deletions
41
api/tests/src/data_migration/transformation/subtask/test_transform_opportunity_attachment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from src.db.models.foreign.attachment import TsynopsisAttachment as TsynopsisAttachmentF | ||
from src.db.models.staging.attachment import TsynopsisAttachment as TsynopsisAttachmentS | ||
from tests.src.db.models.factories import ( | ||
ForeignTsynopsisAttachmentFactory, | ||
StagingTsynopsisAttachmentFactory, | ||
) | ||
|
||
|
||
def test_uploading_attachment_staging(db_session, enable_factory_create, tmp_path): | ||
att = StagingTsynopsisAttachmentFactory.create(file_lob=b"Testing attachment") | ||
db_session.commit() | ||
db_session.expire_all() | ||
|
||
db_att = ( | ||
db_session.query(TsynopsisAttachmentS) | ||
.filter(TsynopsisAttachmentS.opportunity_id == att.opportunity_id) | ||
.one_or_none() | ||
) | ||
temp_file = tmp_path / "out_file.txt" | ||
temp_file.write_bytes(db_att.file_lob) | ||
file_content = temp_file.read_bytes() | ||
|
||
assert file_content == db_att.file_lob | ||
|
||
|
||
def test_uploading_attachment_foreign(db_session, enable_factory_create, tmp_path): | ||
att = ForeignTsynopsisAttachmentFactory.create(file_lob=b"Testing attachment") | ||
db_session.commit() | ||
db_session.expire_all() | ||
|
||
db_att = ( | ||
db_session.query(TsynopsisAttachmentF) | ||
.filter(TsynopsisAttachmentF.opportunity_id == att.opportunity_id) | ||
.one_or_none() | ||
) | ||
|
||
temp_file = tmp_path / "out_file.txt" | ||
temp_file.write_bytes(db_att.file_lob) | ||
file_content = temp_file.read_bytes() | ||
|
||
assert file_content == db_att.file_lob |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.