Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.

Migrate off topic channel name endpoint from the site API #26

Closed
wants to merge 5 commits into from
Closed

Migrate off topic channel name endpoint from the site API #26

wants to merge 5 commits into from

Conversation

Shivansh-007
Copy link

@Shivansh-007 Shivansh-007 commented Nov 2, 2021

Blocked by #25
Closes #11

I have based my branch on Dorsan's to get the test patches and routers set up. You can review this by going through the commit cfb6e87.

My commit currently has a bug in the tests where it doesn't patch session.query.all properly and order_by fails to get the correct mocked object.

D0rs4n and others added 4 commits November 1, 2021 15:19
- Add reminder endpoint package to the project:
 - Add reminder dependencies
 - Add reminder schemas
 - Add reminder endpoints
- Add reminder tests to the project.
 - The tests use mocked DB session calls, to avoid using a test DB.
- Introduce changes in the flake8 config, and main to be comaptible with the test suites.
Make the test workflow compatible with the test suite using mocked DB calls
@Akarys42 Akarys42 added review: do not merge type: feature A request for or implementation of a new feature labels Nov 2, 2021
Copy link
Member

@D0rs4n D0rs4n left a comment

Choose a reason for hiding this comment

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

The first batch of review, just to get everything sorted. Good work, overall.

api/main.py Outdated
Comment on lines 49 to 54
@app.exception_handler(ValueError)
async def handle_validation_value_error(req: Request, exc: ValueError) -> JSONResponse:
"""A default handler to handle value errors raised by pydantic model field validators."""
return JSONResponse(status_code=400, content={"error": f"{exc}"})


Copy link
Member

Choose a reason for hiding this comment

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

I don't think that's necessary, the handler above handles every exception regarding malformed request bodies (That comes from pydantic), and returns the errors, except with the error code of 400.

Copy link
Author

Choose a reason for hiding this comment

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

That didn't work for me 🤷🏻 though according to me it should have.

Copy link
Member

Choose a reason for hiding this comment

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

It worked for me, and according to the documentation that is the preferred way.
(I believe the problem might have been with the 404 instead of 400.
If not, what was the test payload that failed to error out?

pyproject.toml Show resolved Hide resolved
def test_returns_single_item_with_random_items_param_set_to_1(self):
"""Return not-used name instead used."""
url = app.url_path_for("get_off_topic_channel_names")
response = client.get(f"{url}?random_items=1", headers=AUTH_HEADER)
Copy link
Member

Choose a reason for hiding this comment

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

I think you should , pass random_items using params

Copy link
Author

Choose a reason for hiding this comment

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

It only takes URL path parameters, we are using query parameters here.

Copy link
Member

Choose a reason for hiding this comment

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

No, the params meant to accept a dictionary of query parameters.
See, the documentation

Comment on lines +14 to +16
def get_all_otn(db_session: Session) -> Query:
"""Get a partial query object with .all()."""
return db_session.query(OffTopicChannelName).all()
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 move this to a separate file, into something likeotn_dependency?

Copy link
Author

Choose a reason for hiding this comment

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

It isn't really a dependency and is only used in the current file, I don't think it deserves to go in a separate dependency file.

Copy link
Member

Choose a reason for hiding this comment

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

If your code depends on this function, then it is a dependency, the reason I ask is because in the future new dependencies could be added, and I believe it would make the project structure more friendly.

tests/endpoints/test_off_topic_channel_names.py Outdated Show resolved Hide resolved
Copy link
Member

@D0rs4n D0rs4n left a comment

Choose a reason for hiding this comment

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

The second batch of review. :)
(I'll look into the problem with tests later on today, or tomorrow)


if random_items <= 0:
return JSONResponse(
status_code=404,
Copy link
Member

@D0rs4n D0rs4n Nov 3, 2021

Choose a reason for hiding this comment

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

According to the API "docs":
- 400: returned when `random_items` is not a positive integer
So, this has to be 400.

@jchristgit
Copy link
Member

Closing this per us sunsetting this project.

@jchristgit jchristgit closed this Dec 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
review: do not merge type: feature A request for or implementation of a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate off-topic names endpoint to FastAPI
4 participants