Ejemplo n.º 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
Ejemplo n.º 2
0
def test_code_generation(db_session, monkeypatch):
    newdle = Newdle(
        title='foo',
        creator_uid='bar',
        creator_name='Dummy',
        duration=timedelta(minutes=30),
        timezone='Europe/Zurich',
        timeslots=[],
    )
    db_session.add(newdle)
    db_session.flush()

    assert len(newdle.code) == 8
    current_app.config['NEWDLE_CODE_LENGTH'] = 16
    assert len(generate_random_newdle_code()) == 16

    db_session.flush()

    # simulate a situation in which there is a collision with the code
    # of an existing newdle
    class _MockRandom(object):
        def __init__(self):
            self.collision = True

        def __call__(self, pop, k=1):
            if self.collision:
                self.collision = False
                return newdle.code
            return 'something else'

    mock_random = _MockRandom()
    from newdle.models import random as _random

    monkeypatch.setattr(_random, 'choices', mock_random)
    assert generate_random_newdle_code() == 'something else'
Ejemplo n.º 3
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