diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b34e854c0..7c977ce57 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -310,10 +310,20 @@ Please see the [activist style guide](https://github.com/activist-org/activist/b ### Backend -Please run the following from the project root to test the backend: +Please run the following commands from the project root to test the backend: ```bash -pytest ./backend -vv +# Start the Docker container: +docker compose --env-file .env.dev up backend --build -d # -d to hide logs + +# Enter the backend container: +docker exec -it django_backend sh + +# Run backend tests: +pytest + +# Once tests are finished: +exit ``` ### Frontend diff --git a/README.md b/README.md index 60c948dfa..db66a4ce4 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ git remote add upstream https://github.com/activist-org/activist.git ```bash docker compose --env-file .env.dev up - # Or with new dependencies: + # Or with new dependencies or backend model changes: # docker compose --env-file .env.dev up --build # And to stop the containers when you're done working: diff --git a/backend/authentication/models.py b/backend/authentication/models.py index fec4f9e72..5f1f3d18b 100644 --- a/backend/authentication/models.py +++ b/backend/authentication/models.py @@ -56,7 +56,7 @@ def create_user( class SupportEntityType(models.Model): - id = models.IntegerField(primary_key=True) + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) name = models.CharField(max_length=255) def __str__(self) -> str: diff --git a/backend/content/models.py b/backend/content/models.py index dd9452701..a3ae69940 100644 --- a/backend/content/models.py +++ b/backend/content/models.py @@ -70,7 +70,7 @@ def __str__(self) -> str: class Tag(models.Model): - id = models.IntegerField(primary_key=True) + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) text = models.CharField(max_length=255) creation_date = models.DateTimeField(auto_now_add=True) diff --git a/backend/entities/factories.py b/backend/entities/factories.py index 13f8628fd..2bcf69b1b 100644 --- a/backend/entities/factories.py +++ b/backend/entities/factories.py @@ -2,8 +2,6 @@ import factory -from authentication.models import UserModel - from .models import ( Group, GroupEvent, @@ -35,14 +33,15 @@ class Meta: name = factory.Faker("word") tagline = factory.Faker("word") social_links = ["https://www.instagram.com/activist_org/"] - - @factory.lazy_attribute - def created_by(self): - if UserModel.objects.exclude(username="admin").exists(): - return UserModel.objects.exclude(username="admin").first() - else: - return factory.SubFactory("authentication.factories.UserFactory") - + # Note: Version that accesses the database so we don't create new each time. + # created_by = factory.LazyAttribute( + # lambda x: ( + # UserModel.objects.exclude(username="admin").first() + # if UserModel.objects.exclude(username="admin").exists() + # else factory.SubFactory("authentication.factories.UserFactory") + # ) + # ) + created_by = factory.SubFactory("authentication.factories.UserFactory") status = factory.SubFactory("entities.factories.StatusTypeFactory", name="Active") is_high_risk = factory.Faker("boolean") location = factory.Faker("city") @@ -59,14 +58,7 @@ class Meta: name = factory.Faker("word") tagline = factory.Faker("word") social_links = ["https://www.instagram.com/activist_org/"] - - @factory.lazy_attribute - def created_by(self): - if UserModel.objects.exclude(username="admin").exists(): - return UserModel.objects.exclude(username="admin").first() - else: - return factory.SubFactory("authentication.factories.UserFactory") - + created_by = factory.SubFactory("authentication.factories.UserFactory") creation_date = factory.LazyFunction( lambda: datetime.datetime.now(tz=datetime.timezone.utc) ) diff --git a/backend/entities/models.py b/backend/entities/models.py index d366d3d29..56bbd64b5 100644 --- a/backend/entities/models.py +++ b/backend/entities/models.py @@ -158,7 +158,7 @@ def __str__(self) -> str: class OrganizationApplicationStatus(models.Model): - id = models.IntegerField(primary_key=True) + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) status_name = models.CharField(max_length=255) def __str__(self) -> str: diff --git a/backend/events/factories.py b/backend/events/factories.py index 49e3b34ac..d23368c9f 100644 --- a/backend/events/factories.py +++ b/backend/events/factories.py @@ -3,8 +3,6 @@ import factory -from authentication.models import UserModel - from .models import ( Event, EventAttendee, @@ -39,14 +37,7 @@ class Meta: datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(days=1) ) ) - - @factory.lazy_attribute - def created_by(self): - if UserModel.objects.exclude(username="admin").exists(): - return UserModel.objects.exclude(username="admin").first() - else: - return factory.SubFactory("authentication.factories.UserFactory") - + created_by = factory.SubFactory("authentication.factories.UserFactory") creation_date = factory.LazyFunction( lambda: datetime.datetime.now(tz=datetime.timezone.utc) ) diff --git a/backend/events/models.py b/backend/events/models.py index 8317857a3..7814b0a98 100644 --- a/backend/events/models.py +++ b/backend/events/models.py @@ -41,7 +41,7 @@ def __str__(self) -> str: class Format(models.Model): - id = models.IntegerField(primary_key=True) + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) name = models.CharField(max_length=255) description = models.TextField(max_length=500) creation_date = models.DateTimeField(auto_now_add=True) @@ -53,7 +53,7 @@ def __str__(self) -> str: class Role(models.Model): - id = models.IntegerField(primary_key=True) + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) name = models.CharField(max_length=255) is_custom = models.BooleanField(default=False) description = models.TextField(max_length=500) @@ -81,7 +81,7 @@ def __str__(self) -> str: class EventAttendeeStatus(models.Model): - id = models.IntegerField(primary_key=True) + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) status_name = models.CharField(max_length=255) def __str__(self) -> str: