Skip to content

🧪 Add tests for user registration error paths#66

Open
DivyanshuChipa wants to merge 1 commit intomasterfrom
testing-improvement-users-register-14722163909695510411
Open

🧪 Add tests for user registration error paths#66
DivyanshuChipa wants to merge 1 commit intomasterfrom
testing-improvement-users-register-14722163909695510411

Conversation

@DivyanshuChipa
Copy link
Copy Markdown
Owner

Added a comprehensive test suite for user registration in backend/users.py. The tests cover the happy path (successful registration), the edge case where admin approval is required, and the error path where a duplicate username triggers an sqlite3.IntegrityError. Since the passlib library is not available in the environment, a mocking strategy was implemented in conftest.py to allow the tests to run successfully. Each test runs against an isolated, temporary SQLite database to ensure no side effects.


PR created automatically by Jules for task 14722163909695510411 started by @DivyanshuChipa

This change introduces unit tests for the `register_user` function in `backend/users.py`, specifically covering:
- Successful user registration.
- Duplicate username registration (triggers `sqlite3.IntegrityError`).
- Registration requiring admin approval.

A `backend/tests/conftest.py` was added to:
- Mock the `passlib` dependency which is missing in the environment.
- Provide a `setup_test_db` fixture that creates an isolated temporary SQLite database for each test.

Verified by running `pytest backend/tests/test_users.py`.

Co-authored-by: DivyanshuChipa <211708943+DivyanshuChipa@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f4e33763a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -0,0 +1,42 @@
import pytest
from backend.users import register_user
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove hard dependency on PYTHONPATH in test import

Using from backend.users import register_user makes test collection fail under a standard pytest run when PYTHONPATH is not explicitly set (it raises ModuleNotFoundError: No module named 'backend'), so the new suite is not runnable out of the box. This blocks the registration tests in default local/CI environments unless extra path configuration is added; switch to an import path that works with the repo layout (or add explicit pytest path config) so tests collect reliably.

Useful? React with 👍 / 👎.

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.

1 participant