Skip to content

Conversation

@aaronjae22
Copy link
Collaborator

@aaronjae22 aaronjae22 commented Jan 19, 2025

Testbed Test Data Seeding

Implements a Django management command to seed the database with test data, creating a network of actors, notes, activities, and outboxes with proper relationships.

Features

  • Creates test users and associated ActivityPub actors
  • Generates notes with realistic content using Faker
  • Creates activities linked to notes
  • Establishes outboxes for each actor with proper activity associations
  • Optional admin user creation for testing purposes

Implementation

  • Uses Django's BaseCommand for custom management command
  • Leverages Faker library for generating realistic test data
  • Implements proper relationship handling between models:
    • User -> Actor
    • Actor -> Notes
    • Notes -> Activities
    • Actor -> PortabilityOutbox
    • PortabilityOutbox -> Activities

Data Generation Details

  • Creates 10 test actors
  • Each actor gets 5 notes and associated activities
  • Timestamps are properly distributed across a realistic timeline
  • All relationships maintain referential integrity

Usage

Run the command using:

python manage.py seed

Testing

  • Verified proper creation of all model instances-
  • Confirmed correct relationship establishment
  • Validated JSON-LD output format for ActivityPub compatibility

Output:
image
image

Closes #22

@aaronjae22 aaronjae22 self-assigned this Jan 19, 2025
@aaronjae22 aaronjae22 requested a review from lisad January 20, 2025 00:13
@aaronjae22
Copy link
Collaborator Author

This got a bit bigger than what I was expecting. I added factories to the project that led me to modified the testing files alongside with the seeding file.

I implemented the requested changes and they added very useful features into the project.

image
image

There are a couple of features that I would like to implement into these features but I'll create new issues. I don't want to continue adding into this branch and make it bigger.

Closes #24
Closes #25

@aaronjae22 aaronjae22 requested a review from lisad January 22, 2025 17:53
model = Activity

actor = factory.SubFactory(ActorFactory)
type = factory.Iterator(['Create', 'Like', 'Update', 'Follow', 'Announce', 'Delete', 'Undo', 'Flag'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is going to create conformant ActivityPub objects. Some of these types can have a Note attached but some shouldn't. This is fine for this PR but we'll need to iterate. Possibly some of the Activity types should be subclasses of the Activity model class that enforce things like whether the type has a note or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was something I was going to deal with in the next PR.

outbox = PortabilityOutbox.objects.create(actor=self)

# Create an initial Activity for the Actor
activity = Activity.objects.create(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be the activity that announces the creation of the Actor themselves? Is it correct for an Activity of type "Create" to have no internal object?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Yes, correct. It announces the creation of the Actor itself.

  • No, it shouldn't be that way. I should've added the internal object. The internal object should be the Actor itself.

{
  "@context": "https://www.w3.org/ns/activitystreams",
  "type": "Create",
  "actor": "https://example.com/users/someuser",
  "object": {
    "type": "Person",
    "id": "https://example.com/users/someuser",
    "preferredUsername": "someuser",
    "name": "Some User",
  }
}

@aaronjae22 aaronjae22 merged commit b0b0d86 into main Jan 22, 2025
@aaronjae22 aaronjae22 deleted the seeding-database-with-testing-data branch April 2, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Seeding database for demoing testbed

2 participants