Skip to content

test: created first test case for get_or_create method for UsersResource#384

Open
edward-yee-ny wants to merge 6 commits intoweeklyfrom
379-feat-auto-provision-users-during-oauth-login
Open

test: created first test case for get_or_create method for UsersResource#384
edward-yee-ny wants to merge 6 commits intoweeklyfrom
379-feat-auto-provision-users-during-oauth-login

Conversation

@edward-yee-ny
Copy link

No description provided.

@edward-yee-ny edward-yee-ny changed the title created first test case for get_or_create method for UsersResource test: created first test case for get_or_create method for UsersResource Mar 17, 2026
@edward-yee-ny edward-yee-ny reopened this Mar 17, 2026
Copy link
Contributor

@ngjunsiang ngjunsiang left a comment

Choose a reason for hiding this comment

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

Nice work 👍

@LohithNYJC LohithNYJC requested a review from ngjunsiang March 19, 2026 07:50
@LohithNYJC
Copy link

Hi Mr Ng, I added a new test function, test_get_or_create_returns_existing_user_when_exists(). Could you help me check this function? Thank you.

@ngjunsiang
Copy link
Contributor

ngjunsiang commented Mar 19, 2026

Hi Mr Ng, I added a new test function, test_get_or_create_returns_existing_user_when_exists(). Could you help me check this function? Thank you.

Hi @lohith, I just realized the comment is inaccurate. Please see https://github.com/nyjc-computing/campus/blob/weekly/campus%2Fauth%2Fresources%2Fuser.py for the interface of UsersResource class. Note that there is no user_storage attribute.

In general, use the methods available on the resource object, without touching the storage layer. Mediating any changes in data schema is the resource class's responsibility, and the test should not take on that responsibility unless there is good reason.

@edward-yee-ny edward-yee-ny requested a review from SavioNYJC March 19, 2026 09:13
SavioNYJC

This comment was marked as outdated.

Copy link

@SavioNYJC SavioNYJC left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@saltensity saltensity left a comment

Choose a reason for hiding this comment

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

Resubmit changes for proper usage of the resource

email = "new_user@gmail.com"
name = "New_User"
self.resource.user_storage.insert_one(user_id, email, name)
timestamp = self.resource.user_storage.get(user_id).created_at

Choose a reason for hiding this comment

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

Following the previous comment, this line would not be needed

user_id = schema.UserID("New_User")
email = "new_user@gmail.com"
name = "New_User"
self.resource.user_storage.insert_one(user_id, email, name)
Copy link

@saltensity saltensity Mar 19, 2026

Choose a reason for hiding this comment

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

You can use the self.resource.new() method to add a new user directly to the resource

(The .new() method also returns the User object for the newly created user, maybe you can store it in a variable and use its created_at?)

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.

5 participants