9
9
10
10
import stream
11
11
from stream .exceptions import ApiKeyException , InputException
12
- from stream .tests .test_client import get_unique_postfix
13
12
14
13
15
14
def assert_first_activity_id_equal (activities , correct_activity_id ):
@@ -82,7 +81,7 @@ async def test_update_activities_create(async_client):
82
81
83
82
@pytest .mark .asyncio
84
83
async def test_add_activity (async_client ):
85
- feed = async_client .feed ("user" , "py1" )
84
+ feed = async_client .feed ("user" , f "py1- { uuid4 () } " )
86
85
activity_data = {"actor" : 1 , "verb" : "tweet" , "object" : 1 }
87
86
response = await feed .add_activity (activity_data )
88
87
activity_id = response ["id" ]
@@ -93,7 +92,7 @@ async def test_add_activity(async_client):
93
92
94
93
@pytest .mark .asyncio
95
94
async def test_add_activity_to_inplace_change (async_client ):
96
- feed = async_client .feed ("user" , "py1" )
95
+ feed = async_client .feed ("user" , f "py1- { uuid4 () } " )
97
96
team_feed = async_client .feed ("user" , "teamy" )
98
97
activity_data = {"actor" : 1 , "verb" : "tweet" , "object" : 1 }
99
98
activity_data ["to" ] = [team_feed .id ]
@@ -103,8 +102,8 @@ async def test_add_activity_to_inplace_change(async_client):
103
102
104
103
@pytest .mark .asyncio
105
104
async def test_add_activities_to_inplace_change (async_client ):
106
- feed = async_client .feed ("user" , "py1" )
107
- team_feed = async_client .feed ("user" , "teamy" )
105
+ feed = async_client .feed ("user" , f "py1- { uuid4 () } " )
106
+ team_feed = async_client .feed ("user" , f "teamy- { uuid4 () } " )
108
107
activity_data = {"actor" : 1 , "verb" : "tweet" , "object" : 1 }
109
108
activity_data ["to" ] = [team_feed .id ]
110
109
await feed .add_activities ([activity_data ])
@@ -116,7 +115,7 @@ async def test_add_activity_to(async_client):
116
115
# test for sending an activities to the team feed using to
117
116
feeds = ["user" , "teamy" , "team_follower" ]
118
117
user_feed , team_feed , team_follower_feed = map (
119
- lambda x : async_client .feed ("user" , x ), feeds
118
+ lambda x : async_client .feed ("user" , f" { x } - { uuid4 () } " ), feeds
120
119
)
121
120
await team_follower_feed .follow (team_feed .slug , team_feed .user_id )
122
121
activity_data = {"actor" : 1 , "verb" : "tweet" , "object" : 1 , "to" : [team_feed .id ]}
@@ -202,8 +201,8 @@ async def test_add_activities(user1):
202
201
203
202
@pytest .mark .asyncio
204
203
async def test_add_activities_to (async_client , user1 ):
205
- pyto2 = async_client .feed ("user" , "pyto2" )
206
- pyto3 = async_client .feed ("user" , "pyto3" )
204
+ pyto2 = async_client .feed ("user" , f "pyto2- { uuid4 () } " )
205
+ pyto3 = async_client .feed ("user" , f "pyto3- { uuid4 () } " )
207
206
208
207
to = [pyto2 .id , pyto3 .id ]
209
208
activity_data = [
@@ -230,7 +229,7 @@ async def test_add_activities_to(async_client, user1):
230
229
231
230
@pytest .mark .asyncio
232
231
async def test_follow_and_source (async_client ):
233
- feed = async_client .feed ("user" , "test_follow" )
232
+ feed = async_client .feed ("user" , f "test_follow- { uuid4 () } " )
234
233
agg_feed = async_client .feed ("aggregated" , "test_follow" )
235
234
actor_id = random .randint (10 , 100000 )
236
235
activity_data = {"actor" : actor_id , "verb" : "tweet" , "object" : 1 }
@@ -248,14 +247,14 @@ async def test_follow_and_source(async_client):
248
247
249
248
@pytest .mark .asyncio
250
249
async def test_empty_followings (async_client ):
251
- asocial = async_client .feed ("user" , "asocialpython" )
250
+ asocial = async_client .feed ("user" , f "asocialpython- { uuid4 () } " )
252
251
followings = await asocial .following ()
253
252
assert followings ["results" ] == []
254
253
255
254
256
255
@pytest .mark .asyncio
257
256
async def test_get_followings (async_client ):
258
- social = async_client .feed ("user" , "psocial" )
257
+ social = async_client .feed ("user" , f "psocial- { uuid4 () } " )
259
258
await social .follow ("user" , "apy" )
260
259
await social .follow ("user" , "bpy" )
261
260
await social .follow ("user" , "cpy" )
@@ -271,17 +270,17 @@ async def test_get_followings(async_client):
271
270
272
271
@pytest .mark .asyncio
273
272
async def test_empty_followers (async_client ):
274
- asocial = async_client .feed ("user" , "asocialpython" )
273
+ asocial = async_client .feed ("user" , f "asocialpython- { uuid4 () } " )
275
274
followers = await asocial .followers ()
276
275
assert followers ["results" ] == []
277
276
278
277
279
278
@pytest .mark .asyncio
280
279
async def test_get_followers (async_client ):
281
- social = async_client .feed ("user" , "psocial" )
282
- spammy1 = async_client .feed ("user" , "spammy1" )
283
- spammy2 = async_client .feed ("user" , "spammy2" )
284
- spammy3 = async_client .feed ("user" , "spammy3" )
280
+ social = async_client .feed ("user" , f "psocial- { uuid4 () } " )
281
+ spammy1 = async_client .feed ("user" , f "spammy1- { uuid4 () } " )
282
+ spammy2 = async_client .feed ("user" , f "spammy2- { uuid4 () } " )
283
+ spammy3 = async_client .feed ("user" , f "spammy3- { uuid4 () } " )
285
284
for feed in [spammy1 , spammy2 , spammy3 ]:
286
285
await feed .follow ("user" , social .user_id )
287
286
followers = await social .followers (offset = 0 , limit = 2 )
@@ -296,7 +295,7 @@ async def test_get_followers(async_client):
296
295
297
296
@pytest .mark .asyncio
298
297
async def test_empty_do_i_follow (async_client ):
299
- social = async_client .feed ("user" , "psocial" )
298
+ social = async_client .feed ("user" , f "psocial- { uuid4 () } " )
300
299
await social .follow ("user" , "apy" )
301
300
await social .follow ("user" , "bpy" )
302
301
followings = await social .following (feeds = ["user:missingpy" ])
@@ -305,7 +304,7 @@ async def test_empty_do_i_follow(async_client):
305
304
306
305
@pytest .mark .asyncio
307
306
async def test_do_i_follow (async_client ):
308
- social = async_client .feed ("user" , "psocial" )
307
+ social = async_client .feed ("user" , f "psocial- { uuid4 () } " )
309
308
await social .follow ("user" , "apy" )
310
309
await social .follow ("user" , "bpy" )
311
310
followings = await social .following (feeds = ["user:apy" ])
@@ -376,7 +375,7 @@ async def test_get(user1):
376
375
377
376
@pytest .mark .asyncio
378
377
async def test_get_not_marked_seen (async_client ):
379
- notification_feed = async_client .feed ("notification" , "test_mark_seen" )
378
+ notification_feed = async_client .feed ("notification" , f "test_mark_seen- { uuid4 () } " )
380
379
response = await notification_feed .get (limit = 3 )
381
380
activities = response ["results" ]
382
381
for activity in activities :
@@ -385,7 +384,7 @@ async def test_get_not_marked_seen(async_client):
385
384
386
385
@pytest .mark .asyncio
387
386
async def test_mark_seen_on_get (async_client ):
388
- notification_feed = async_client .feed ("notification" , "test_mark_seen" )
387
+ notification_feed = async_client .feed ("notification" , f "test_mark_seen- { uuid4 () } " )
389
388
response = await notification_feed .get (limit = 100 )
390
389
activities = response ["results" ]
391
390
for activity in activities :
@@ -433,7 +432,7 @@ async def test_mark_seen_on_get(async_client):
433
432
434
433
@pytest .mark .asyncio
435
434
async def test_mark_read_by_id (async_client ):
436
- notification_feed = async_client .feed ("notification" , "py2" )
435
+ notification_feed = async_client .feed ("notification" , f "py2- { uuid4 () } " )
437
436
response = await notification_feed .get (limit = 3 )
438
437
activities = response ["results" ]
439
438
ids = []
@@ -515,7 +514,7 @@ async def test_uniqueness_topic(flat3, topic, user1):
515
514
await flat3 .follow ("user" , user1 .user_id )
516
515
# add the same activity twice
517
516
now = datetime .now (tzlocal ())
518
- tweet = f"My Way { get_unique_postfix ()} "
517
+ tweet = f"My Way { uuid4 ()} "
519
518
activity_data = {
520
519
"actor" : 1 ,
521
520
"verb" : "tweet" ,
@@ -615,8 +614,8 @@ async def test_missing_actor(user1):
615
614
616
615
@pytest .mark .asyncio
617
616
async def test_follow_many (async_client ):
618
- sources = [async_client .feed ("user" , str ( i ) ).id for i in range (10 )]
619
- targets = [async_client .feed ("flat" , str ( i ) ).id for i in range (10 )]
617
+ sources = [async_client .feed ("user" , f" { i } - { uuid4 () } " ).id for i in range (10 )]
618
+ targets = [async_client .feed ("flat" , f" { i } - { uuid4 () } " ).id for i in range (10 )]
620
619
feeds = [{"source" : s , "target" : t } for s , t in zip (sources , targets )]
621
620
await async_client .follow_many (feeds )
622
621
@@ -631,21 +630,21 @@ async def test_follow_many(async_client):
631
630
response = await async_client .feed (* source .split (":" )).following ()
632
631
follows = response ["results" ]
633
632
assert len (follows ) == 1
634
- assert follows [0 ]["feed_id" ] in sources
635
- assert follows [0 ]["target_id" ] == source
633
+ assert follows [0 ]["feed_id" ] == source
634
+ assert follows [0 ]["target_id" ] in targets
636
635
637
636
638
637
@pytest .mark .asyncio
639
638
async def test_follow_many_acl (async_client ):
640
- sources = [async_client .feed ("user" , str ( i ) ) for i in range (10 )]
639
+ sources = [async_client .feed ("user" , f" { i } - { uuid4 () } " ) for i in range (10 )]
641
640
# ensure every source is empty first
642
641
for feed in sources :
643
642
response = await feed .get (limit = 100 )
644
643
activities = response ["results" ]
645
644
for activity in activities :
646
645
await feed .remove_activity (activity ["id" ])
647
646
648
- targets = [async_client .feed ("flat" , str ( i ) ) for i in range (10 )]
647
+ targets = [async_client .feed ("flat" , f" { i } - { uuid4 () } " ) for i in range (10 )]
649
648
# ensure every source is empty first
650
649
for feed in targets :
651
650
response = await feed .get (limit = 100 )
@@ -696,7 +695,7 @@ async def failing_unfollow():
696
695
@pytest .mark .asyncio
697
696
async def test_add_to_many (async_client ):
698
697
activity = {"actor" : 1 , "verb" : "tweet" , "object" : 1 , "custom" : "data" }
699
- feeds = [async_client .feed ("flat" , str ( i ) ).id for i in range (10 , 20 )]
698
+ feeds = [async_client .feed ("flat" , f" { i } - { uuid4 () } " ).id for i in range (10 , 20 )]
700
699
await async_client .add_to_many (activity , feeds )
701
700
702
701
for feed in feeds :
@@ -732,7 +731,7 @@ async def test_get_activities_full(async_client):
732
731
"foreign_id" : fid ,
733
732
}
734
733
735
- feed = async_client .feed ("user" , "test_get_activity" )
734
+ feed = async_client .feed ("user" , f "test_get_activity- { uuid4 () } " )
736
735
response = await feed .add_activity (activity )
737
736
738
737
response = await async_client .get_activities (ids = [response ["id" ]])
@@ -760,7 +759,7 @@ async def test_get_activities_full_with_enrichment(async_client):
760
759
"foreign_id" : fid ,
761
760
}
762
761
763
- feed = async_client .feed ("user" , "test_get_activity" )
762
+ feed = async_client .feed ("user" , f "test_get_activity- { uuid4 () } " )
764
763
activity = await feed .add_activity (activity )
765
764
766
765
reaction1 = await async_client .reactions .add ("like" , activity ["id" ], "liker" )
@@ -802,7 +801,7 @@ async def test_get_activities_full_with_enrichment_and_reaction_kinds(async_clie
802
801
"foreign_id" : fid ,
803
802
}
804
803
805
- feed = async_client .feed ("user" , "test_get_activity" )
804
+ feed = async_client .feed ("user" , f "test_get_activity- { uuid4 () } " )
806
805
activity = await feed .add_activity (activity )
807
806
808
807
await async_client .reactions .add ("like" , activity ["id" ], "liker" )
@@ -983,16 +982,18 @@ async def test_reaction_add(async_client):
983
982
984
983
@pytest .mark .asyncio
985
984
async def test_reaction_add_to_target_feeds (async_client ):
985
+ feed_id = f"user:michelle-{ uuid4 ()} "
986
986
r = await async_client .reactions .add (
987
987
"superlike" ,
988
988
"54a60c1e-4ee3-494b-a1e3-50c06acb5ed4" ,
989
989
"mike" ,
990
990
data = {"popularity" : 50 },
991
- target_feeds = ["user:michelle" ],
991
+ target_feeds = [feed_id ],
992
992
target_feeds_extra_data = {"popularity" : 100 },
993
993
)
994
994
assert r ["data" ]["popularity" ] == 50
995
- response = await async_client .feed ("user" , "michelle" ).get (limit = 1 )
995
+ feed = async_client .feed (* feed_id .split (":" ))
996
+ response = await feed .get (limit = 1 )
996
997
a = response ["results" ][0 ]
997
998
assert r ["id" ] in a ["reaction" ]
998
999
assert a ["verb" ] == "superlike"
@@ -1003,12 +1004,12 @@ async def test_reaction_add_to_target_feeds(async_client):
1003
1004
r ["id" ],
1004
1005
"rob" ,
1005
1006
data = {"popularity" : 60 },
1006
- target_feeds = ["user:michelle" ],
1007
+ target_feeds = [feed_id ],
1007
1008
target_feeds_extra_data = {"popularity" : 200 },
1008
1009
)
1009
1010
1010
1011
assert child ["data" ]["popularity" ] == 60
1011
- response = await async_client . feed ( "user" , "michelle" ) .get (limit = 1 )
1012
+ response = await feed .get (limit = 1 )
1012
1013
a = response ["results" ][0 ]
1013
1014
assert child ["id" ] in a ["reaction" ]
1014
1015
assert a ["verb" ] == "superlike"
@@ -1196,7 +1197,7 @@ async def test_collections_delete(async_client):
1196
1197
async def test_feed_enrichment_collection (async_client ):
1197
1198
entry = await async_client .collections .add ("items" , {"name" : "time machine" })
1198
1199
entry .pop ("duration" )
1199
- f = async_client .feed ("user" , "mike" )
1200
+ f = async_client .feed ("user" , f "mike- { uuid4 () } " )
1200
1201
activity_data = {
1201
1202
"actor" : "mike" ,
1202
1203
"verb" : "buy" ,
@@ -1213,7 +1214,7 @@ async def test_feed_enrichment_collection(async_client):
1213
1214
async def test_feed_enrichment_user (async_client ):
1214
1215
user = await async_client .users .add (str (uuid1 ()), {"name" : "Mike" })
1215
1216
user .pop ("duration" )
1216
- f = async_client .feed ("user" , "mike" )
1217
+ f = async_client .feed ("user" , f "mike- { uuid4 () } " )
1217
1218
activity_data = {
1218
1219
"actor" : async_client .users .create_reference (user ),
1219
1220
"verb" : "buy" ,
@@ -1228,7 +1229,7 @@ async def test_feed_enrichment_user(async_client):
1228
1229
1229
1230
@pytest .mark .asyncio
1230
1231
async def test_feed_enrichment_own_reaction (async_client ):
1231
- f = async_client .feed ("user" , "mike" )
1232
+ f = async_client .feed ("user" , f "mike- { uuid4 () } " )
1232
1233
activity_data = {"actor" : "mike" , "verb" : "buy" , "object" : "object" }
1233
1234
response = await f .add_activity (activity_data )
1234
1235
reaction = await async_client .reactions .add ("like" , response ["id" ], "mike" )
@@ -1239,7 +1240,7 @@ async def test_feed_enrichment_own_reaction(async_client):
1239
1240
1240
1241
@pytest .mark .asyncio
1241
1242
async def test_feed_enrichment_recent_reaction (async_client ):
1242
- f = async_client .feed ("user" , "mike" )
1243
+ f = async_client .feed ("user" , f "mike- { uuid4 () } " )
1243
1244
activity_data = {"actor" : "mike" , "verb" : "buy" , "object" : "object" }
1244
1245
response = await f .add_activity (activity_data )
1245
1246
reaction = await async_client .reactions .add ("like" , response ["id" ], "mike" )
@@ -1250,7 +1251,7 @@ async def test_feed_enrichment_recent_reaction(async_client):
1250
1251
1251
1252
@pytest .mark .asyncio
1252
1253
async def test_feed_enrichment_reaction_counts (async_client ):
1253
- f = async_client .feed ("user" , "mike" )
1254
+ f = async_client .feed ("user" , f "mike- { uuid4 () } " )
1254
1255
activity_data = {"actor" : "mike" , "verb" : "buy" , "object" : "object" }
1255
1256
response = await f .add_activity (activity_data )
1256
1257
reaction = await async_client .reactions .add ("like" , response ["id" ], "mike" )
0 commit comments