Skip to content

Commit

Permalink
Backend testing directions + no more integer ids in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Sep 7, 2024
1 parent 9ced66f commit bfe6414
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 37 deletions.
14 changes: 12 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion backend/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion backend/content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 10 additions & 18 deletions backend/entities/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import factory

from authentication.models import UserModel

from .models import (
Group,
GroupEvent,
Expand Down Expand Up @@ -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")
Expand All @@ -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)
)
Expand Down
2 changes: 1 addition & 1 deletion backend/entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 1 addition & 10 deletions backend/events/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import factory

from authentication.models import UserModel

from .models import (
Event,
EventAttendee,
Expand Down Expand Up @@ -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)
)
Expand Down
6 changes: 3 additions & 3 deletions backend/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bfe6414

Please sign in to comment.