Ejemplo n.º 1
0
def create_event(db: Session,
                 title: str,
                 start,
                 end,
                 owner_id: int,
                 content: str = None,
                 location: str = None,
                 invitees: List[str] = None,
                 category_id: int = None):
    """Creates an event and an association."""

    invitees_concatenated = ','.join(invitees or [])

    event = create_model(
        db,
        Event,
        title=title,
        start=start,
        end=end,
        content=content,
        owner_id=owner_id,
        location=location,
        invitees=invitees_concatenated,
        category_id=category_id,
    )
    create_model(db, UserEvent, user_id=owner_id, event_id=event.id)
    return event
Ejemplo n.º 2
0
 def test_create_model(self, session: Session) -> None:
     assert session.query(User).first() is None
     info = {
         'username': '******',
         'email': '*****@*****.**',
         'password': '******'
     }
     utils.create_model(session, User, **info)
     assert session.query(User).first()
Ejemplo n.º 3
0
def comment(session: Session, event: Event, user: User) -> Iterator[Comment]:
    data = {
        'user': user,
        'event': event,
        'content': 'test comment',
        'time': datetime(2021, 1, 1, 0, 1),
    }
    create_model(session, Comment, **data)
    comment = session.query(Comment).first()
    yield comment
    delete_instance(session, comment)
Ejemplo n.º 4
0
def create_comment(session: Session, event: Event, content: str) -> None:
    """Creates a comment instance in the DB.

    Args:
        session (Session): DB session.
        event (Event): Instance of the event to create a comment for.
        content (str): The content of the comment.
    """
    data = {
        'user': utils.get_current_user(session),
        'event': event,
        'content': content,
        'time': datetime.datetime.now()
    }
    utils.create_model(session, Comment, **data)
Ejemplo n.º 5
0
def create_event(db, title, start, end, owner_id, content=None, location=None):
    """Creates an event and an association."""

    event = create_model(
        db,
        Event,
        title=title,
        start=start,
        end=end,
        content=content,
        owner_id=owner_id,
        location=location,
    )
    create_model(db, UserEvent, user_id=owner_id, event_id=event.id)
    return event
Ejemplo n.º 6
0
async def add_comment(
        request: Request,
        event_id: int,
        session: Session = Depends(get_db),
) -> Response:
    """Creates a comment instance in the DB. Redirects back to the event's
    comments tab upon creation."""
    form = await request.form()
    data = {
        "user_id": get_current_user(session).id,
        "event_id": event_id,
        "content": form["comment"],
        "time": dt.now(),
    }
    create_model(session, Comment, **data)
    path = router.url_path_for("view_comments", event_id=str(event_id))
    return RedirectResponse(path, status_code=status.HTTP_303_SEE_OTHER)
Ejemplo n.º 7
0
def add_new_event(values: dict, db: Session) -> Optional[Event]:
    """Get User values and the DB Session insert the values
    to the DB and refresh it exception in case that the keys
    in the dict is not match to the fields in the DB
    return the Event Class item"""

    if not is_date_before(values['start'], values['end']):
        return None
    try:
        new_event = create_model(db, Event, **values)
        create_model(db,
                     UserEvent,
                     user_id=values['owner_id'],
                     event_id=new_event.id)
        return new_event
    except (AssertionError, AttributeError, TypeError) as e:
        logger.exception(e)
        return None
Ejemplo n.º 8
0
def salary_user(salary_session: Session):
    test_user = create_model(
        salary_session, User,
        username='******',
        password='******',
        email='*****@*****.**',
    )
    yield test_user
    delete_instance(salary_session, test_user)
Ejemplo n.º 9
0
def sender(session: Session) -> Generator[User, None, None]:
    mock_user = create_model(
        session, User,
        username='******',
        password='******',
        email='*****@*****.**',
        language_id=1,
    )
    yield mock_user
    delete_instance(session, mock_user)
Ejemplo n.º 10
0
def create_event(
    db: Session,
    title: str,
    start,
    end,
    owner_id: int,
    all_day: bool = False,
    content: Optional[str] = None,
    location: Optional[str] = None,
    vc_link: str = None,
    color: Optional[str] = None,
    invitees: List[str] = None,
    category_id: Optional[int] = None,
    availability: bool = True,
    is_google_event: bool = False,
    privacy: str = PrivacyKinds.Public.name,
):
    """Creates an event and an association."""

    invitees_concatenated = ",".join(invitees or [])

    event = create_model(
        db,
        Event,
        title=title,
        start=start,
        end=end,
        privacy=privacy,
        content=content,
        owner_id=owner_id,
        location=location,
        vc_link=vc_link,
        color=color,
        emotion=get_emotion(title, content),
        invitees=invitees_concatenated,
        all_day=all_day,
        category_id=category_id,
        availability=availability,
        is_google_event=is_google_event,
    )
    create_model(db, UserEvent, user_id=owner_id, event_id=event.id)
    return event
Ejemplo n.º 11
0
def add_quote(session: Session, id_quote: int, text: str,
              author: str) -> Quote:
    quote = create_model(
        session,
        Quote,
        id=id_quote,
        text=text,
        author=author,
    )
    yield quote
    delete_instance(session, quote)
Ejemplo n.º 12
0
def bad_user(session: Session) -> User:
    test_user = create_model(
        session,
        User,
        username='******',
        password='******',
        email='test.email#gmail.com',
        language_id=1,
    )
    yield test_user
    delete_instance(session, test_user)
Ejemplo n.º 13
0
def wage(salary_session: Session,
         salary_user: User) -> Iterator[SalarySettings]:
    wage = create_model(
        salary_session,
        SalarySettings,
        user_id=salary_user.id,
        category_id=CATEGORY_ID,
        wage=30,
        off_day=config.SATURDAY,
        holiday_category_id=config.ISRAELI_JEWISH,
        regular_hour_basis=config.REGULAR_HOUR_BASIS,
        night_hour_basis=config.NIGHT_HOUR_BASIS,
        night_start=config.NIGHT_START,
        night_end=config.NIGHT_END,
        night_min_len=config.NIGHT_MIN_LEN,
        first_overtime_amount=config.FIRST_OVERTIME_AMOUNT,
        first_overtime_pay=config.FIRST_OVERTIME_PAY,
        second_overtime_pay=config.SECOND_OVERTIME_PAY,
        week_working_hours=config.WEEK_WORKING_HOURS,
        daily_transport=config.STANDARD_TRANSPORT,
    )
    yield wage
    delete_instance(salary_session, wage)
Ejemplo n.º 14
0
def invitation(
        event: Event, user: User, session: Session
) -> Generator[Invitation, None, None]:
    """Returns an Invitation object after being created in the database.

    Args:
        event: An Event instance.
        user: A user instance.
        session: A database connection.

    Returns:
        An Invitation object.
    """
    invitation = create_model(
        session, Invitation,
        creation=datetime.now(),
        recipient=user,
        event=event,
        event_id=event.id,
        recipient_id=user.id,
    )
    yield invitation
    delete_instance(session, invitation)
Ejemplo n.º 15
0
def add_joke(session: Session, id_joke: int, text: str) -> Joke:
    joke = create_model(session, Joke, id=id_joke, text=text)
    yield joke
    delete_instance(session, joke)