-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/shareable event #44
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
Feature/shareable event #44
Conversation
IdanPelled
commented
Jan 13, 2021
- Expand the user model and the event model
- Add invitation model
- Create in app shareable events
- Create foundations for sending email invitations (export to .ics file)
…nto feature/shareable-event
Codecov Report
@@ Coverage Diff @@
## develop #44 +/- ##
============================================
+ Coverage 98.76% 100.00% +1.23%
============================================
Files 11 16 +5
Lines 243 424 +181
============================================
+ Hits 240 424 +184
+ Misses 3 0 -3
Continue to review full report at Codecov.
|
app/main.py
Outdated
|
|
||
|
|
||
| @app.get("/invitations") | ||
| def view_invitations(request: Request, db: Session = Depends(get_db)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to create a specific route for invitations?
| @@ -0,0 +1,103 @@ | |||
| from datetime import datetime | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between files under internal/ and utils/ folders?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Maybe should be under app/routers/export.py?
tests/conftest.py
Outdated
| from sqlalchemy.orm import Session, sessionmaker | ||
|
|
||
| from app.database.models import Event, Invitation, User, Base | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider: create a separate db_entities conftest file.
As far as I know, this is how you reference the other files:
pytest_plugins = ['module1', 'module2']
(stackoverflow answer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice ;)
app/internal/share_event.py
Outdated
| @@ -0,0 +1,85 @@ | |||
| from typing import List, Dict, Union | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this file should be in app/routers/share.py?
app/main.py
Outdated
| "request": request, | ||
| "username": current_username, | ||
| "events": upcouming_events | ||
| "events": upcoming_events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add trailing ,
| @@ -0,0 +1,103 @@ | |||
| from datetime import datetime | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Maybe should be under app/routers/export.py?
|
Please change the PR to merge into PythonFreeCourse:develop |
tests/conftest.py
Outdated
| email='test.email@gmail.com', | ||
| ) | ||
| yield test_user | ||
| delete_instance(session, test_user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you thought of the concept of DRY :)
Personally, I prefer to read tests with their logic as clear as possible - it's easier to understand what is going on in the test, and when.
So, I'm not sure if delete_instance function is more useful or more helps tests to be ambiguous :)
What do you think?
app/internal/agenda_events.py
Outdated
| end: Optional[date]) -> List[Event]: | ||
| """filter events by a time frame.""" | ||
|
|
||
| return [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match the behavior of the original filter, I might use yield from (event for ...)
app/internal/utils.py
Outdated
| return False | ||
|
|
||
|
|
||
| def get_all_user_events(session: Session, user_id: int) -> List[Event]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should prolly be in the routers/user.py file
tests/conftest.py
Outdated
|
|
||
|
|
||
| @pytest.fixture | ||
| @pytest.fixture(scope="session") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done
app/routers/export.py
Outdated
| """Adds an optional field if it exists.""" | ||
|
|
||
| if user_event.location: | ||
| data += [('location', user_event.location)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer .append to use the current list and not create a new one :)
app/routers/user.py
Outdated
|
|
||
| def does_user_exist( | ||
| session: Session, | ||
| *_, user_id=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use just plain * (without giving it a name)
app/database/models.py
Outdated
| description = Column(String, default="Happy new user!") | ||
| avatar = Column(String, default="profile.png") | ||
|
|
||
| is_active = Column(Boolean, default=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be wiser to set it as False if its about being connected to the calendar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
app/internal/events.py
Outdated
| from app.database.models import Event | ||
|
|
||
|
|
||
| def sort_by_date(events: List[Event]) -> List[Event]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add /sort to event.py in routers
| def sort_by_date(events: List[Event]) -> List[Event]: | ||
| """Sorts the events by the start of the event.""" | ||
|
|
||
| temp = events.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to, sorted already makes a copy of it
| for participant in participants: | ||
|
|
||
| if does_user_exist(email=participant, session=session): | ||
| temp: list = emails['registered'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List[] (of what?)
| """Sends invitations to all event participants.""" | ||
|
|
||
| registered, unregistered = ( | ||
| sort_emails(participants, session=session).values() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer explicitly asking the dictionary, in case the sort_emails will change and the order will be tempered:
emails = sort_email(...)
registered, unregistered = emails['registered'], emails['unregistered']
|
|
||
| def test_get_page(self, client): | ||
| resp = client.get(self.URL) | ||
| assert resp.status_code == 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.ok