Beispiel #1
0
def dummy_newdle(db_session, dummy_uid):
    newdle = Newdle(
        code='dummy',
        title='Test event',
        creator_uid=dummy_uid,
        creator_name='Dummy',
        duration=timedelta(minutes=60),
        timezone='Europe/Zurich',
        timeslots=[
            datetime(2019, 9, 11, 13, 0),
            datetime(2019, 9, 11, 14, 0),
            datetime(2019, 9, 12, 13, 0),
            datetime(2019, 9, 12, 13, 30),
        ],
        participants={
            Participant(code='part1', name='Tony Stark'),
            Participant(code='part2', name='Albert Einstein'),
            Participant(
                code='part3',
                name='Guinea Pig',
                email='*****@*****.**',
                auth_uid='pig',
            ),
        },
    )
    db_session.add(newdle)
    db_session.flush()
    return newdle
Beispiel #2
0
def test_participant_email_uid(dummy_newdle, db_session):
    participant = Participant(
        name='John Doe', email='*****@*****.**', auth_uid='john', newdle=dummy_newdle
    )
    db_session.add(participant)
    db_session.flush()

    participant = Participant(name='Paul Doe', newdle=dummy_newdle)
    db_session.add(participant)
    db_session.flush()

    participant = Participant(name='Jane Doe', auth_uid='jane', newdle=dummy_newdle)
    db_session.add(participant)
    with pytest.raises(Exception) as e:
        db_session.flush()
    assert 'violates check constraint' in str(e.value)
Beispiel #3
0
def test_create_participant(dummy_newdle, db_session):
    dummy_newdle.participants.clear()
    participant = Participant(name='John Doe', newdle=dummy_newdle)
    db_session.add(participant)
    db_session.flush()

    participant = Participant.query.get(participant.id)
    assert participant.newdle == dummy_newdle
    assert dummy_newdle.participants == {participant}
Beispiel #4
0
def test_create_participant_newdle_no_duplicate(flask_client, dummy_newdle,
                                                dummy_uid):
    dummy_newdle.participants.add(
        Participant(
            code='part4',
            name='Guinea Pig',
            email='*****@*****.**',
            auth_uid=dummy_uid,
        ))
    nb_participant = Participant.query.count()
    resp = flask_client.put(url_for('api.create_participant', code='dummy'),
                            **make_test_auth(dummy_uid))
    assert resp.status_code == 200
    assert Participant.query.count() == nb_participant
Beispiel #5
0
 def _create_newdle(id=None, **kwargs):
     kwargs.setdefault(
         'participants',
         {
             Participant(
                 code=f'part1{id}' if id is not None else 'part1',
                 name='Guinea Pig',
                 email='*****@*****.**',
                 auth_uid='pig',
             ),
         },
     )
     kwargs.setdefault(
         'timeslots',
         [
             datetime(2019, 9, 11, 13, 0),
             datetime(2019, 9, 11, 14, 0),
             datetime(2019, 9, 12, 13, 0),
             datetime(2019, 9, 12, 13, 30),
         ],
     )
     kwargs.setdefault('code', f'dummy#{id}' if id is not None else 'dummy')
     kwargs.setdefault(
         'title', f'Test event {id}' if id is not None else 'Test event')
     kwargs.setdefault('creator_name', 'Dummy')
     kwargs.setdefault('duration', timedelta(minutes=60))
     kwargs.setdefault('private', True)
     kwargs.setdefault('timezone', 'Europe/Zurich')
     newdle = Newdle(
         id=id,
         creator_uid=dummy_uid,
         **kwargs,
     )
     db_session.add(newdle)
     db_session.flush()
     return newdle