Exemple #1
0
def validate_input(
    db: Session,
    userid: int,
    start: datetime.datetime = None,
    end: datetime.datetime = None,
) -> ValidationResult:
    """1. input validations:
            valid userid.
            end date > start date.
        2. date range preparation:
            start: will be at 00:00 on input date (today if None).
            end: will be at 23:59:59 on input date (today if None).
    All statistics are based on full days (00:00:00-23:59:59).

    Args:
        db: db session.
        userid: requested user id number for statistics.
        start: start of date range.
        end: end of date range.

    Returns: NamedTuple with the following data:
        valid_input: boolean stating if input values are valid.
        error_text: str (relevant ib case of error).
        start: start of date range.
        end: end of date range.
    """
    if not does_user_exist(session=db, user_id=userid):
        return ValidationResult(
            valid_input=False,
            error_text=INVALID_USER,
            start=start,
            end=end,
        )
    date = start or datetime.datetime.now()
    start = datetime.datetime(date.year, date.month, date.day)
    single_day = datetime.timedelta(days=1, seconds=-1)
    date = end or start
    end = datetime.datetime(date.year, date.month, date.day) + single_day
    if start >= end:
        return ValidationResult(
            valid_input=False,
            error_text=INVALID_DATE_RANGE,
            start=start,
            end=end,
        )
    return ValidationResult(valid_input=True,
                            error_text="",
                            start=start,
                            end=end)
Exemple #2
0
def sort_emails(
    participants: List[str],
    session: Session,
) -> Dict[str, List[str]]:
    """Sorts emails to registered and unregistered users."""

    emails = {'registered': [], 'unregistered': []}  # type: ignore
    for participant in participants:

        if does_user_exist(email=participant, session=session):
            temp: list = emails['registered']
        else:
            temp: list = emails['unregistered']

        temp.append(participant)

    return emails
Exemple #3
0
 def test_does_user_exist_failure(self, session):
     assert not does_user_exist(username='******', session=session)
     assert not does_user_exist(session=session)
Exemple #4
0
 def test_does_user_exist_success(self, user, session):
     assert does_user_exist(username=user.username, session=session)
     assert does_user_exist(user_id=user.id, session=session)
     assert does_user_exist(email=user.email, session=session)