-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/public event #287
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
base: develop
Are you sure you want to change the base?
Feature/public event #287
Changes from 31 commits
5ef6469
885a843
1f4b084
8e0d1ee
5a8adeb
59532d6
235c4b2
d32ca25
ef0f679
c6477a5
b7cc686
540f1bf
49ac8e7
e111110
573cd2b
847eb09
b9d6016
e715f4c
14fc7e2
f515361
e4f2ee0
9ffa3ea
e8571f1
05c90a1
71ee772
9cf15b1
70be019
1bc712c
f371ce1
05310b7
c02ffd0
8a58f78
b6ff758
093881b
7b4ee13
986b43b
cf5b771
76db81a
9bbed18
94c4a32
b08636e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,15 @@ | |
|
||
from app.config import (CALENDAR_HOME_PAGE, CALENDAR_REGISTRATION_PAGE, | ||
CALENDAR_SITE_NAME, email_conf, templates) | ||
from app.database.models import Event, User | ||
|
||
from app.database.models import Event, User, UserEvent | ||
from app.internal.utils import get_current_user | ||
noam-y marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use Kobi's user system instead |
||
mail = FastMail(email_conf) | ||
|
||
|
||
def send( | ||
session: Session, event_used: int, user_to_send: int, | ||
title: str, background_tasks: BackgroundTasks = BackgroundTasks | ||
title: str, content: str = "", | ||
background_tasks: BackgroundTasks = BackgroundTasks | ||
noam-y marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> bool: | ||
"""This function is being used to send emails in the background. | ||
It takes an event and a user and it sends the event to the user. | ||
|
@@ -48,10 +49,45 @@ def send( | |
background_tasks.add_task(send_internal, | ||
subject=subject, | ||
recipients=recipients, | ||
body=body) | ||
body=body + content) | ||
return True | ||
|
||
|
||
def send_email_to_event_participants( | ||
yammesicka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
session: Session, event_id: int, | ||
title: str, content: str) -> int: | ||
"""This function sends emails to a mailing list of all event participants. | ||
it uses the function send above to do this and avoid double codes.. | ||
Args: | ||
session(Session): The session to redirect to the database. | ||
event_id (int): Id number of the event that is used. | ||
title (str): Title of the email that is being sent. | ||
content (str): body of email sent. | ||
Returns: | ||
int: Returns the number of emails sent | ||
(number of valid emails in event's participants) | ||
""" | ||
event_owner = session.query(Event.owner).filter(id == event_id).first() | ||
if event_owner != get_current_user(session): | ||
return 0 | ||
# makes sure only event owner can send an email via this func. | ||
mailing_list = session.query(User.id, User.email).join( | ||
UserEvent, User.id == UserEvent.user_id | ||
).filter( | ||
event_id == event_id).all() | ||
valid_mailing_list = list(filter(verify_email_pattern, mailing_list.email)) | ||
if not valid_mailing_list: | ||
return 0 | ||
# making sure app doesn't crash if emails are invalid | ||
|
||
event = session.query(Event).get(event_id) | ||
subject = f"{event.title}: {title}" | ||
for r in valid_mailing_list: | ||
send(session, event, r.id, subject, content) | ||
# sends the send email function parameters to send on the mailing list | ||
return len(valid_mailing_list) | ||
|
||
|
||
def send_email_invitation(sender_name: str, | ||
recipient_name: str, | ||
recipient_mail: str, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import calendar | ||
from datetime import datetime | ||
|
||
import pytest | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from app.config import PSQL_ENVIRONMENT | ||
from app.database.models import Base | ||
from app.routers.event import create_event | ||
from app.routers.user import create_user | ||
|
||
pytest_plugins = [ | ||
'tests.user_fixture', | ||
|
@@ -80,3 +83,70 @@ def sqlite_engine(): | |
@pytest.fixture | ||
def Calendar(): | ||
return calendar.Calendar(0) | ||
|
||
|
||
@pytest.fixture | ||
def no_event_user(session): | ||
"""a user made for testing who doesn't own any event.""" | ||
user = create_user( | ||
session=session, | ||
username='new_test_username', | ||
password='new_test_password', | ||
email='[email protected]', | ||
language_id='english' | ||
) | ||
|
||
return user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't create a new fixture, use one of the others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have to use several different users since i'm testing the use of the mailing list. |
||
|
||
|
||
@pytest.fixture | ||
def event_owning_user(session): | ||
"""a user made for testing who already owns an event.""" | ||
user = create_user( | ||
session=session, | ||
username='new_test_username2', | ||
password='new_test_password2', | ||
email='[email protected]', | ||
language_id='english' | ||
) | ||
|
||
data = { | ||
'title': 'event_owning_user event', | ||
'start': datetime.strptime('2021-05-05 14:59', '%Y-%m-%d %H:%M'), | ||
'end': datetime.strptime('2021-05-05 15:01', '%Y-%m-%d %H:%M'), | ||
'location': 'https://us02web.zoom.us/j/875384596', | ||
'content': 'content', | ||
'owner_id': user.id, | ||
} | ||
|
||
create_event(session, **data) | ||
|
||
return user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't create a new fixture, use one of the others. You can use a user fixture and an event fixture in your code to create this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have to use several different users since i'm testing the use of the mailing list. __ |
||
|
||
|
||
@pytest.fixture | ||
def user1(session): | ||
"""another user made for testing""" | ||
user = create_user( | ||
session=session, | ||
username='user2user2', | ||
password='verynicepass', | ||
email='[email protected]', | ||
language_id='english' | ||
) | ||
return user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't create a new user fixture, use one of the others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have to use several different users since i'm testing mailing list. |
||
|
||
|
||
@pytest.fixture | ||
def event_example(session, event_owning_user): | ||
data = { | ||
'title': 'test event title', | ||
'start': datetime.strptime('2021-05-05 14:59', '%Y-%m-%d %H:%M'), | ||
'end': datetime.strptime('2021-05-05 15:01', '%Y-%m-%d %H:%M'), | ||
'location': 'https://us02web.zoom.us/j/87538459r6', | ||
'content': 'content', | ||
'owner_id': event_owning_user.id, | ||
} | ||
|
||
event = create_event(session, **data) | ||
return event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't create a new event fixture, use one of the others. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ | |
from app.internal.utils import delete_instance | ||
from app.main import app | ||
from app.routers import event as evt | ||
from app.routers.event import event_to_show | ||
from app.routers.event import add_new_event, add_user_to_event, event_to_show | ||
from app.routers.user import create_user | ||
|
||
CORRECT_EVENT_FORM_DATA = { | ||
"title": "test title", | ||
|
@@ -140,6 +141,36 @@ | |
] | ||
|
||
|
||
@pytest.fixture | ||
def new_event(session, new_user): | ||
event = add_new_event(TestApp.event_test_data, session) | ||
return event | ||
|
||
|
||
@pytest.fixture | ||
def new_user(session): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you can use existing fixtures? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried but didn't really find a proper user fixture inside the file. ill try going over the code again There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are enough user fixtures, use one of the others. |
||
user = create_user( | ||
session=session, | ||
username='new_test_username', | ||
password='new_test_password', | ||
email='[email protected]', | ||
language_id='english' | ||
) | ||
|
||
return user | ||
|
||
|
||
def test_joining_public_event(session, new_event, new_user): | ||
"""test in order to make sure user is added the first time | ||
he asks to join event, yet won't join the same user twice""" | ||
first_join = add_user_to_event( | ||
session, event_id=new_event.id, user_id=new_user.id) | ||
assert first_join | ||
second_join = add_user_to_event( | ||
session, event_id=new_event.id, user_id=new_user.id) | ||
assert not second_join | ||
|
||
|
||
def test_get_events(event_test_client, session, event): | ||
response = event_test_client.get("/event/") | ||
assert response.ok | ||
|
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.
Event doesn't have "friends" option?
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.
the meaning of friends is different- public event is meant to allow any user in the platform to join the event, just like the public events on facebook. so it means the owner's friends don't matter in this feature :)
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.
Can you please explain what is the meaning of public/private event? is it like busy/free?
Thanks
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.
a pubic event is event anyone can join. it means you don't need to be invited directly from the owner, you can join the event by yourself by clicking a button on event page