@@ -1575,6 +1575,8 @@ def init_syn(self, syn: Synapse) -> None:
15751575 async def test_no_provenance_no_activity (self ) -> None :
15761576 """When used and executed are empty, no Activity is set on the file."""
15771577 mock_file = _make_file_mock ("/a.txt" , "syn1" )
1578+ # Remove the auto-created attribute so we can detect if it gets set
1579+ del mock_file .activity
15781580
15791581 result = await _upload_item_async (
15801582 item = mock_file ,
@@ -1588,17 +1590,59 @@ async def test_no_provenance_no_activity(self) -> None:
15881590
15891591 assert result is mock_file
15901592 mock_file .store_async .assert_awaited_once_with (synapse_client = self .syn )
1591- assert (
1592- not hasattr (mock_file , "activity" )
1593- or mock_file .activity == mock_file .activity
1593+ assert not hasattr (mock_file , "activity" )
1594+
1595+ async def test_with_used_only_sets_activity (self ) -> None :
1596+ """When only used is provided, an Activity is attached before store."""
1597+ from synapseclient .models import Activity
1598+
1599+ mock_file = _make_file_mock ("/a.txt" , "syn1" )
1600+ del mock_file .activity
1601+
1602+ await _upload_item_async (
1603+ item = mock_file ,
1604+ used = ["syn999" ],
1605+ executed = [],
1606+ activity_name = "my activity" ,
1607+ activity_description = "my description" ,
1608+ prerequisite_tasks = [],
1609+ syn = self .syn ,
1610+ )
1611+
1612+ assert isinstance (mock_file .activity , Activity )
1613+ assert mock_file .activity .name == "my activity"
1614+ assert mock_file .activity .description == "my description"
1615+ assert len (mock_file .activity .used ) == 1
1616+ assert len (mock_file .activity .executed ) == 0
1617+
1618+ async def test_with_executed_only_sets_activity (self ) -> None :
1619+ """When only executed is provided, an Activity is attached before store."""
1620+ from synapseclient .models import Activity
1621+
1622+ mock_file = _make_file_mock ("/a.txt" , "syn1" )
1623+ del mock_file .activity
1624+
1625+ await _upload_item_async (
1626+ item = mock_file ,
1627+ used = [],
1628+ executed = ["https://github.com/code.py" ],
1629+ activity_name = "my activity" ,
1630+ activity_description = "my description" ,
1631+ prerequisite_tasks = [],
1632+ syn = self .syn ,
15941633 )
15951634
1596- async def test_with_provenance_sets_activity (self ) -> None :
1597- """When used/executed are provided, an Activity is attached before store."""
1635+ assert isinstance (mock_file .activity , Activity )
1636+ assert mock_file .activity .name == "my activity"
1637+ assert mock_file .activity .description == "my description"
1638+ assert len (mock_file .activity .used ) == 0
1639+ assert len (mock_file .activity .executed ) == 1
1640+
1641+ async def test_with_used_and_executed_sets_activity (self ) -> None :
1642+ """When both used and executed are provided, an Activity is attached before store."""
15981643 from synapseclient .models import Activity
15991644
16001645 mock_file = _make_file_mock ("/a.txt" , "syn1" )
1601- # Remove any default activity attribute so we can check it gets set
16021646 del mock_file .activity
16031647
16041648 await _upload_item_async (
0 commit comments