Esempio n. 1
0
def user1(session):
    # a user made for testing who doesn't own any event.
    user = create_user(session=session,
                       username='******',
                       password='******',
                       email='*****@*****.**',
                       language_id='english')

    return user
Esempio n. 2
0
 def test_create_user(self, session):
     user = create_user(session=session,
                        username='******',
                        password='******',
                        email='*****@*****.**',
                        language_id=1)
     assert user.username == 'new_test_username'
     assert user.password == 'new_test_password'
     assert user.email == '*****@*****.**'
     assert user.language_id == 1
     session.delete(user)
     session.commit()
Esempio n. 3
0
def test_create_google_event(session):
    user = create_user(session=session,
                       username='******',
                       password='******',
                       email='*****@*****.**',
                       language_id=1)

    event = google_connect.create_google_event('title',
                                               datetime(2021, 1, 1, 15, 15),
                                               datetime(2021, 1, 1, 15, 30),
                                               user, 'location', session)

    assert event.title == 'title'
Esempio n. 4
0
def test_google_sync(mocker, google_connect_test_client, session, credentials):
    create_user(session=session,
                username='******',
                password='******',
                email='*****@*****.**',
                language_id=1)

    mocker.patch('app.routers.google_connect.get_credentials',
                 return_value=credentials)
    mocker.patch('app.routers.google_connect.fetch_save_events',
                 return_value=None)
    connect = google_connect_test_client.get(
        'google/sync', headers={"referer": 'http://testserver/'})
    assert connect.ok

    # second case
    mocker.patch('app.routers.google_connect.get_credentials',
                 return_value=None)

    connect = google_connect_test_client.get(
        'google/sync', headers={"referer": 'http://testserver/'})
    assert connect.ok
Esempio n. 5
0
def create_data(session):
    _ = [
        create_user("user" + str(_), "password" + str(_),
                    "email" + str(_) + '@' + 'gmail.com', "Hebrew", session)
        for _ in range(1, 4)
    ]
    start = datetime.datetime.now() + datetime.timedelta(hours=-1)
    end = datetime.datetime.now() + datetime.timedelta(hours=1)
    create_events_and_user_events(session, start, end, 1,
                                  ["*****@*****.**", "*****@*****.**"])
    start = datetime.datetime.now() + datetime.timedelta(days=-1)
    end = datetime.datetime.now() + datetime.timedelta(days=-1, hours=2)
    create_events_and_user_events(session, start, end, 1,
                                  ["*****@*****.**", "*****@*****.**"])
    start = datetime.datetime.now() + datetime.timedelta(hours=1)
    end = datetime.datetime.now() + datetime.timedelta(hours=1.5)
    create_events_and_user_events(session, start, end, 2, ["*****@*****.**"])
    for invitation in get_all_invitations(session):
        accept(invitation, session)
Esempio n. 6
0
async def create_new_event(request: Request, session=Depends(get_db)):
    data = await request.form()
    title = data['title']
    content = data['description']
    start = dt.strptime(data['start_date'] + ' ' + data['start_time'],
                        TIME_FORMAT)
    end = dt.strptime(data['end_date'] + ' ' + data['end_time'], TIME_FORMAT)
    user = session.query(User).filter_by(id=1).first()
    user = user if user else create_user(username="******",
                                         password="******",
                                         email="*****@*****.**",
                                         language="",
                                         language_id=1,
                                         session=session)
    owner_id = user.id
    location_type = data['location_type']
    is_zoom = location_type == 'vc_url'
    location = data['location']
    category_id = data.get('category_id')

    invited_emails = get_invited_emails(data['invited'])
    uninvited_contacts = get_uninvited_regular_emails(session, owner_id, title,
                                                      invited_emails)

    if is_zoom:
        raise_if_zoom_link_invalid(location)

    event = create_event(session,
                         title,
                         start,
                         end,
                         owner_id,
                         content,
                         location,
                         invited_emails,
                         category_id=category_id)
    message = ''
    if uninvited_contacts:
        message = f'Forgot to invite {", ".join(uninvited_contacts)} maybe?'
    return RedirectResponse(
        router.url_path_for('eventview', event_id=event.id) + f'?{message}',
        status_code=status.HTTP_302_FOUND)
Esempio n. 7
0
def test_can_show_calendar_private(session, user):
    another_user = create_user(session=session,
                               username='******',
                               email='*****@*****.**',
                               password='******',
                               language_id=1)
    current_user = user
    # TODO to be replaced after user system is merged:
    # current_user = CurrentUser(**user.__dict__)

    result_a = can_show_calendar(requested_user_username='******',
                                 db=session,
                                 current_user=current_user)
    result_b = can_show_calendar(requested_user_username='******',
                                 db=session,
                                 current_user=current_user)
    assert result_a is False
    assert result_b is True
    session.delete(another_user)
    session.commit()
Esempio n. 8
0
def test_get_credentials_from_db(session):
    user = create_user(session=session,
                       username='******',
                       password='******',
                       email='*****@*****.**',
                       language_id=1)

    credentials = OAuthCredentials(owner=user,
                                   token="somecode",
                                   refresh_token="somecode",
                                   token_uri="some_uri",
                                   client_id="somecode",
                                   client_secret="some_secret",
                                   expiry=datetime(2021, 2, 22))
    session.add(credentials)
    session.commit()
    assert user.oauth_credentials is not None
    session.close()
    return_val = google_connect.get_credentials_from_db(user)
    assert return_val
Esempio n. 9
0
def user2(session):
    # a user made for testing who already owns an event.
    user = create_user(session=session,
                       username='******',
                       password='******',
                       email='*****@*****.**',
                       language_id='english')

    data = {
        'title': 'user2 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
Esempio n. 10
0
def test_get_credentials(mocker, session, user, credentials):
    user = create_user(session=session,
                       username='******',
                       password='******',
                       email='*****@*****.**',
                       language_id=1)

    mocker.patch(
        'app.internal.google_connect.get_credentials_from_consent_screen',
        return_value=credentials)

    assert google_connect.get_credentials(user=user,
                                          session=session) == credentials

    mocker.patch('app.internal.google_connect.get_credentials',
                 return_value=credentials)
    mocker.patch('app.internal.google_connect.refresh_token',
                 return_value=credentials)

    assert google_connect.get_credentials(user=user,
                                          session=session) == credentials
Esempio n. 11
0
async def create_new_event(request: Request, session=Depends(get_db)):
    data = await request.form()
    title = data['title']
    content = data['description']
    start = datetime.strptime(data['start_date'] + ' ' + data['start_time'],
                              '%Y-%m-%d %H:%M')
    end = datetime.strptime(data['end_date'] + ' ' + data['end_time'],
                            '%Y-%m-%d %H:%M')
    user = session.query(User).filter_by(id=1).first()
    user = user if user else create_user("u", "p", "*****@*****.**", session)
    owner_id = user.id
    location_type = data['location_type']
    is_zoom = location_type == 'vc_url'
    location = data['location']

    if is_zoom:
        validate_zoom_link(location)

    event = create_event(session, title, start, end, owner_id, content,
                         location)
    return RedirectResponse(router.url_path_for('eventview',
                                                event_id=event.id),
                            status_code=status.HTTP_302_FOUND)