|
4 | 4 | from django.contrib.auth import get_user_model |
5 | 5 | from django.conf import settings |
6 | 6 | from django.utils import timezone |
7 | | -from testbed.core.models import LikeActivity |
| 7 | +from testbed.core.models import LikeActivity, FollowActivity |
8 | 8 | from testbed.core.factories import ( |
9 | 9 | ActorFactory, |
10 | 10 | CreateActivityFactory, |
@@ -57,6 +57,39 @@ def create_remote_like(self, actor): |
57 | 57 | visibility="public", |
58 | 58 | ) |
59 | 59 |
|
| 60 | + def create_remote_follow(self, actor): |
| 61 | + server, usernames = random.choice(REMOTE_SERVERS) |
| 62 | + username = random.choice(usernames) |
| 63 | + |
| 64 | + return FollowActivity.objects.create( |
| 65 | + actor=actor, |
| 66 | + target_actor=None, |
| 67 | + target_actor_url=f"https://{server}/users/{username}", |
| 68 | + target_actor_data={ |
| 69 | + "type": "Person", |
| 70 | + "preferredUsername": username, |
| 71 | + "name": username, |
| 72 | + "url": f"https://{server}/users/{username}", |
| 73 | + }, |
| 74 | + visibility="public" |
| 75 | + ) |
| 76 | + |
| 77 | + # Create actor with previous server history |
| 78 | + def create_actor_with_history(self): |
| 79 | + actor = ActorFactory.create() |
| 80 | + |
| 81 | + # Add 1-2 previous servers |
| 82 | + num_previous = random.randint(1, 2) |
| 83 | + |
| 84 | + for _ in range(num_previous): |
| 85 | + server, usernames = random.choice(REMOTE_SERVERS) |
| 86 | + username = random.choice(usernames) |
| 87 | + move_date = timezone.now() - timedelta(days=random.randint(30, 365)) |
| 88 | + |
| 89 | + actor.record_move(server, username, move_date) |
| 90 | + |
| 91 | + return actor |
| 92 | + |
60 | 93 | def handle(self, *args, **kwargs): |
61 | 94 | try: |
62 | 95 | # Check if seeding is allowed in current environment |
@@ -104,15 +137,22 @@ def handle(self, *args, **kwargs): |
104 | 137 | self.style.WARNING("Skipping admin user creation.") |
105 | 138 | ) |
106 | 139 | else: |
107 | | - self.stdout.write(self.style.SUCCESS("Admin user already exists.")) |
108 | | - |
109 | | - # Create multiple actors (Outbox will be created automatically) |
110 | | - self.stdout.write("Creating actors...") |
111 | | - actors = ActorFactory.create_batch(10) |
112 | | - |
113 | | - # Track different types of likes |
| 140 | + self.stdout.write(self.style.SUCCESS('Admin user already exists.')) |
| 141 | + |
| 142 | + # Create multiple actors - mix of regular and those with history |
| 143 | + # (Outbox will be created automatically) |
| 144 | + self.stdout.write('Creating actors...') |
| 145 | + regular_actors = ActorFactory.create_batch(7) # 7 regular actors |
| 146 | + history_actors = [self.create_actor_with_history() for _ in range(3)] # 3 actors with history |
| 147 | + actors = regular_actors + history_actors |
| 148 | + |
| 149 | + # Track different types of activities |
114 | 150 | local_like_count = 0 |
115 | 151 | remote_like_count = 0 |
| 152 | + local_follow_count = 0 |
| 153 | + remote_follow_count = 0 |
| 154 | + moved_actors_count = len(history_actors) # Counts the number of actors with history |
| 155 | + regular_actors_count = len(regular_actors) # Counts the number of regular actors |
116 | 156 |
|
117 | 157 | # Create notes and various activities |
118 | 158 | self.stdout.write("Creating notes and activities...") |
@@ -142,30 +182,40 @@ def handle(self, *args, **kwargs): |
142 | 182 | actor.portability_outbox.first().add_activity(remote_like) |
143 | 183 | remote_like_count += 1 |
144 | 184 |
|
145 | | - # Create some follow relationships |
146 | | - for _ in range(2): # Each actor follows 2 other actors |
| 185 | + # Create local follows |
| 186 | + for _ in range(1): # Each actor follows 1 local actor |
| 187 | + |
147 | 188 | target = random.choice([a for a in actors if a != actor]) |
148 | 189 | follow_activity = FollowActivityFactory( |
149 | 190 | actor=actor, target_actor=target, visibility="public" |
150 | 191 | ) |
151 | 192 | actor.portability_outbox.first().add_activity(follow_activity) |
| 193 | + local_follow_count += 1 |
| 194 | + |
| 195 | + # Create remote follows |
| 196 | + for _ in range(1): # Each actor follows 1 remote actor |
| 197 | + remote_follow = self.create_remote_follow(actor) |
| 198 | + actor.portability_outbox.first().add_activity(remote_follow) |
| 199 | + remote_follow_count += 1 |
152 | 200 |
|
153 | 201 | # Count all activities |
154 | 202 | total_actors = len(actors) |
155 | 203 | total_notes = len(actors) * 3 |
156 | | - total_creates = total_notes + total_actors # Notes + Actor creates |
157 | | - total_follows = len(actors) * 2 |
| 204 | + total_creates = total_notes + total_actors # Notes + Actor creates |
158 | 205 |
|
159 | 206 | self.stdout.write( |
160 | 207 | self.style.SUCCESS( |
161 | | - f"Successfully created:\n" |
162 | | - f"- {total_actors} actors\n" |
163 | | - f"- {total_notes} notes\n" |
164 | | - f"- {total_creates} Create activities ({total_actors} for actors, {total_notes} for notes)\n" |
165 | | - f"- {local_like_count} Local Like activities\n" |
166 | | - f"- {remote_like_count} Remote Like activities\n" |
167 | | - f"- {total_follows} Follow activities\n\n" |
168 | | - f"Federation seeding created with servers: f{','.join(server for server, _ in REMOTE_SERVERS)}" |
| 208 | + f'Successfully created:\n' |
| 209 | + f'- {total_actors} actors\n' |
| 210 | + f'- {moved_actors_count} actors with history\n' |
| 211 | + f'- {regular_actors_count} regular actors\n' |
| 212 | + f'- {total_notes} notes\n' |
| 213 | + f'- {total_creates} Create activities ({total_actors} for actors, {total_notes} for notes)\n' |
| 214 | + f'- {local_like_count} Local Like activities\n' |
| 215 | + f'- {remote_like_count} Remote Like activities\n' |
| 216 | + f'- {local_follow_count} Local Follow activities\n' |
| 217 | + f'- {remote_follow_count} Remote Follow activities\n\n' |
| 218 | + f'Federation seeding created with servers: {", ".join(server for server, _ in REMOTE_SERVERS)}' |
169 | 219 | ) |
170 | 220 | ) |
171 | 221 |
|
|
0 commit comments