Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove django model related testing #1065

Merged
merged 8 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ repos:
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: local
hooks:
- id: run-i18n-checks
name: Run i18n Checks
entry: python frontend/i18n/check/run_i18n_checks.py
language: python
stages: [pre-commit]
# - repo: local
Copy link
Member

Choose a reason for hiding this comment

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

Note @to-sta that you can disable the checks with git commit --no-verify -m "COMMIT_MESSAGE" :)

# hooks:
# - id: run-i18n-checks
# name: Run i18n Checks
# entry: python frontend/i18n/check/run_i18n_checks.py
# language: python
# stages: [pre-commit]
5 changes: 0 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@
"eslint.validate": ["javascript", "typescript", "vue"],
"eslint.useFlatConfig": true,
"typescript.tsdk": "./frontend/node_modules/typescript/lib",
"python.testing.pytestArgs": [
"backend"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
122 changes: 1 addition & 121 deletions backend/entities/tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
from faker import Faker

from authentication.factories import UserFactory
from entities.factories import (
GroupFactory,
OrganizationFactory,
)
from entities.factories import OrganizationFactory
from entities.models import Group

pytestmark = pytest.mark.django_db
Expand Down Expand Up @@ -46,100 +43,6 @@ def test_group_creation() -> None:
assert group.terms_checked is True


def test_required_fields() -> None:
"""Test that required fields raise validation error when missing."""
user = UserFactory()
org = OrganizationFactory(created_by=user)

# 1. Test missing group_name.
with pytest.raises(ValidationError):
group = Group(
org_id=org,
created_by=user,
name="Test Name",
location="Test Location",
category="Test Category",
)
group.full_clean()

# 2. Test missing location.
with pytest.raises(ValidationError):
group = Group(
org_id=org,
created_by=user,
group_name="Test Group",
name="Test Name",
category="Test Category",
)
group.full_clean()


def test_optional_fields() -> None:
"""Test that optional fields can be blank or null."""
user = UserFactory()
org = OrganizationFactory(created_by=user)

group = Group.objects.create(
org_id=org,
created_by=user,
group_name="Test Group",
name="Test Name",
location="Test Location",
category="Test Category",
)

# Should not raise ValidationError.
group.full_clean()
assert group.tagline == ""
assert group.get_involved_url == ""
assert group.terms_checked is False


def test_field_max_lengths() -> None:
"""Test that fields have correct max lengths."""
user = UserFactory()
org = OrganizationFactory(created_by=user)
fake = Faker()

group = Group.objects.create(
org_id=org,
created_by=user,
group_name=fake.company(),
name=fake.company(),
tagline=fake.catch_phrase(),
location=fake.city(),
category=fake.word(),
get_involved_url=fake.url(),
terms_checked=True,
)

assert len(group.group_name) <= 100
assert len(group.name) <= 100
assert len(group.tagline) <= 200
assert len(group.location) <= 100
assert len(group.category) <= 100
assert len(group.get_involved_url) <= 200


def test_cascade_delete() -> None:
"""Test that deleting an organization deletes all associated groups."""
user = UserFactory()
org = OrganizationFactory(created_by=user)

GroupFactory(org_id=org, created_by=user)

assert Group.objects.count() == 1
org.delete()
assert Group.objects.count() == 0

org = OrganizationFactory(created_by=user)
GroupFactory(org_id=org, created_by=user)

assert Group.objects.count() == 1
user.delete()
assert Group.objects.count() == 0


def test_url_validations() -> None:
"""Test that get_involved_url field is a valid URL."""
user = UserFactory()
Expand Down Expand Up @@ -175,29 +78,6 @@ def test_url_validations() -> None:
group.full_clean()


def test_auto_fields() -> None:
"""Test that auto fields are set correctly."""
user = UserFactory()
org = OrganizationFactory(created_by=user)
fake = Faker()

group = Group.objects.create(
org_id=org,
created_by=user,
group_name=fake.company(),
name=fake.company(),
location=fake.city(),
category=fake.word(),
get_involved_url=fake.url(),
terms_checked=True,
)

assert group.creation_date is not None
assert isinstance(group.creation_date, datetime)
assert group.id is not None
assert isinstance(group.id, UUID)


def test_multiple_groups_per_org() -> None:
"""Test that multiple groups can be created per organization."""
user = UserFactory()
Expand Down
17 changes: 0 additions & 17 deletions backend/entities/tests/test_group_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,3 @@ def test_group_text_languages() -> None:
assert secondary_text.primary is False
assert secondary_text.iso == "spa"
assert secondary_text.description == "Descripción"


def test_group_text_field_lengths() -> None:
"""Test field length constraints."""
group = GroupFactory()

text = GroupTextFactory(
group_id=group,
iso="eng",
description="A" * 500,
get_involved="B" * 500,
donate_prompt="C" * 500,
)
assert len(text.description) <= 500
assert len(text.get_involved) <= 500
assert len(text.donate_prompt) <= 500
assert len(text.iso) <= 3
Loading