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

feat: Added comprehensive test coverage for Group-related models #1020

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

zeus2611
Copy link
Contributor

@zeus2611 zeus2611 commented Nov 27, 2024

Contributor checklist


Description

This PR adds extensive test coverage for all Group-related models in the entities module. The new tests ensure proper validation, relationship handling, and data integrity across the Group model ecosystem.

Key additions:

  • GroupMember tests validating different role combinations (owner/admin/comms)
  • GroupEvent tests that multiple events can be associated with a single group
  • GroupResource tests covering creation and cascade deletion
  • GroupText tests for multi-language support and field constraints
  • GroupTopic tests ensuring proper group relationships
  • Group model tests for field validation and relationships

Test Coverage

New test files:

  • test_group_event.py
  • test_group_member.py
  • test_group_resource.py
  • test_group_text.py
  • test_group_topic.py
  • test_group.py

All tests use pytest and the Django test database marker.

Testing Notes

  • All tests can be run with standard pytest commands
  • Factory Boy factories are used for consistent test data
  • Database operations are properly marked with pytest.mark.django_db

Related issue

Added following tests for Group model:
- Group Creation: Tests successful creation, missing required fields, and invalid data.
- Group Update: Tests successful update and handling of invalid input.
- Group Deletion: Tests successful deletion and an attempt to delete a non-existent group.
- Add test_group_creation to validate complete Group object creation
- Add test_required_fields to ensure validation for mandatory fields
- Add test_optional_fields to verify handling of optional fields

This commit introduces three unit tests for the Group model:
1. Validates full object creation with all fields
2. Checks validation errors for missing required fields
3. Confirms optional fields can be blank/null
Add tests to verify:
- Maximum length constraints for Group model fields
- Cascade deletion behavior when parent Organization or User is deleted
- Add test cases for GroupMember model covering roles and membership
- Add test cases for GroupResource model with creation and deletion flows
- Add test cases for GroupText model including language handling
- Add test cases for GroupTopic model with relationship validations
- Add test cases for GroupEvent model with multiple event relation
- Expand Group model tests with field validations and cascade deletions

The test suite now validates:
- Model relationships and constraints
- Field validations and max lengths
- Multi-language support for text content
- Cascade deletion behavior
- Required vs optional field handling
Copy link
Contributor

github-actions bot commented Nov 27, 2024

Thank you for the pull request!

The activist team will do our best to address your contribution as soon as we can. The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the General and Development rooms once you're in. Also consider joining our bi-weekly Saturday dev syncs. It'd be great to have you!

Maintainer checklist

  • The TypeScript and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The Playwright end to end and Zap penetration tests have been ran and are passing (if necessary)

  • The changelog has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

Copy link

netlify bot commented Nov 27, 2024

Deploy Preview for activist-org canceled.

Name Link
🔨 Latest commit d960f41
🔍 Latest deploy log https://app.netlify.com/sites/activist-org/deploys/6747f8be49a48400087c1c48

@andrewtavis
Copy link
Member

Thanks so much for this, @zeus2611! We'll take a look before the weekend :)

Would you have interest in looking into testing for other parts of the backend? If so, would be great if you'd make a suggestion, or @to-sta and I can also look into things. We'd make another issue regardless 😊

@zeus2611
Copy link
Contributor Author

Sure, @andrewtavis, I’d be happy to! During testing, I noticed the current coverage is around 80-83%. I can explore areas with lower coverage and work on improving them. I’m also open to any suggestions you or @to-sta might have—just let me know!

.gitignore Outdated
@@ -41,3 +41,5 @@ dist

# Node dependencies
node_modules
/.vscode
Copy link
Member

Choose a reason for hiding this comment

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

Checking in on these being added in @zeus2611 :) We do have settings.json and extensions.json version controlled, so should we maybe take these lines out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially thought this folder was automatically modified and added to version control. However, since these files are already version-controlled, I’ll update the .gitignore file to exclude them. Thanks for pointing that out!

@@ -1,5 +1,10 @@
{
"eslint.validate": ["javascript", "typescript", "vue"],
"eslint.useFlatConfig": true,
"typescript.tsdk": "./frontend/node_modules/typescript/lib"
"typescript.tsdk": "./frontend/node_modules/typescript/lib",
"python.testing.pytestArgs": [
Copy link
Member

Choose a reason for hiding this comment

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

Could you give me a quick explanation of why these lines are needed, @zeus2611? Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VS Code automatically added these lines while I was working on the tests. It seems they were included as part of the editor's configuration updates. Let me know if you’d like me to investigate further!

Copy link
Member

Choose a reason for hiding this comment

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

Let's remove these then :) Can you do another commit to do this?

Copy link
Member

Choose a reason for hiding this comment

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

Ah you already did :)

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

org = OrganizationFactory(created_by=user)
fake = Faker()

# Test invalid URL
Copy link
Member

Choose a reason for hiding this comment

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

Minor thing that we do for comments is that if they're their own line as is the case here, then it'd be best if they were fully punctuated as this is Python standard :) If it's an inline comment, then no need for capitalization or a period at the end, but if it's on its own line then including both would be best :) I can also do this if you'd like me to!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @andrewtavis! That makes sense. I'll update the comments to follow the Python standard, ensuring punctuation and capitalization where needed for standalone comments. Appreciate the heads-up! 😊

@andrewtavis
Copy link
Member

Let me know on the above points and then I'll get to the full review, @zeus2611!

assert group.terms_checked is False


def test_field_max_lengths() -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @zeus2611,

I reviewed your changes, and they generally look great! 😃 One suggestion before we merge: please remove the tests related to Django, such as those for max_length or auto_fields.

We don't need these tests because Django’s ORM and model field types are already well-tested by the framework itself. We rely on Django's built-in tests to ensure that things like max_length and auto_fields are functioning correctly. Additionally, during the code review process, we check for the correct usage of these features. If there were any issues, we would catch them at that stage.

By removing these tests, we keep the test suite focused on more application-specific logic, avoiding redundancy.

Thanks!

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.

3 participants