Esempio n. 1
0
def test_credittransfer_model(app):
    monty = models.User(email='*****@*****.**',
                        first_name='Monty',
                        last_name='Python',
                        balance=10000)

    brian = models.User(email='*****@*****.**',
                        first_name='Brian',
                        last_name='Smith',
                        balance=0)

    models.db.session.add(monty)
    models.db.session.add(brian)
    models.db.session.commit()

    transfer = models.CreditTransfer.create(
        payer=monty,
        payee=brian,
        created_by=monty,
        value=1000,
        message="Always look on the bright side of life!")

    assert monty.balance == 9000
    assert brian.balance == 1000

    assert transfer.payer_transaction.user == monty
    assert transfer.payee_transaction.user == brian

    transfer.void()

    assert monty.balance == 10000
    assert brian.balance == 0

    assert transfer.payer_transaction.voided
    assert transfer.payee_transaction.voided
Esempio n. 2
0
def test_user_model(app):
    user = models.User(
        email='*****@*****.**',
        first_name='Monty',
        last_name='Python',
        phone='074-345 32 10',
    )

    models.db.session.add(user)
    models.db.session.commit()

    assert user.id > 0

    # Valid phone numbers are automatically normalized.
    assert user.phone == '+46743453210'

    # Invalid phone numbers are allowed as well (but not normalized).
    invalid_example_number = '+4674-876 543 226 189 416 854 65'
    user.phone = invalid_example_number
    models.db.session.commit()
    assert user.phone == invalid_example_number

    # Phone number is not required.
    user.phone = ''
    models.db.session.commit()
    assert user.phone == ''
Esempio n. 3
0
def test_transaction_model(app):
    user = models.User(email='*****@*****.**',
                       first_name='Monty',
                       last_name='Python',
                       balance=0)

    models.db.session.add(user)
    models.db.session.commit()

    transaction = models.Transaction(text='1 alcohol',
                                     value=-1000,
                                     user_id=user.id,
                                     created_by_id=user.id)

    models.db.session.add(transaction)
    models.db.session.commit()

    assert transaction.id > 0
    assert transaction.user == user
    assert transaction.created_by == user

    transaction.void_and_refund()

    assert transaction.voided
    assert user.balance == 1000
def test_index_page(app, client):
    import json

    monty = models.User(
        email='*****@*****.**',
        first_name='Monty',
        last_name='Python',
        phone='0700011223',
        balance=10000,
    )

    rick = models.User(
        email='*****@*****.**',
        first_name='Rick',
        nickname='Roll',
        last_name='Astley',
        phone='0703322110',
    )

    streque = models.Streque(value=400)

    models.db.session.add_all([monty, rick, streque])
    models.db.session.commit()

    rv = client.get('/')
    assert b'Monty' in rv.data
    assert b'Roll' in rv.data

    rv = client.post('/strequa',
                     data=json.dumps(dict(user_id=monty.id, amount=4)),
                     content_type='application/json')

    data = json.loads(rv.data)
    assert data['user_id'] == monty.id
    assert data['amount'] == 4
    assert data['balance'] == 8400
    assert monty.balance == 8400

    rv = client.post('/strequa',
                     data=json.dumps(dict(user_id=rick.id, amount=1)),
                     content_type='application/json')

    data = json.loads(rv.data)
    assert data['user_id'] == rick.id
    assert data['amount'] == 1
    assert data['balance'] == -400
    assert rick.balance == -400
def test_user_model(app):
    user = models.User(
            email='*****@*****.**',
            first_name='Monty',
            last_name='Python',
            phone='0700011223',
    )

    models.db.session.add(user)
    models.db.session.commit()

    assert user.id > 0
def test_void(app):
    streque = models.Streque(value=400)
    user = models.User(email='*****@*****.**', balance=10000)
    models.db.session.add_all([streque, user])
    models.db.session.commit()

    transaction = user.strequa(4)

    assert user.balance == 8400

    transaction.void_and_refund()

    assert user.balance == 10000
    assert len(models.Transaction.query.all()) == 0
Esempio n. 7
0
def test_profilepicture_model(app):
    brian = models.User(email='*****@*****.**',
                        first_name='Brian',
                        last_name='Smith',
                        balance=0)

    models.db.session.add(brian)
    models.db.session.commit()

    pic = models.ProfilePicture(filename='brian.gif', user_id=brian.id)

    models.db.session.add(pic)
    models.db.session.commit()

    assert pic.id > 0
    assert pic.user == brian
Esempio n. 8
0
    def createadmin_command():
        from flasquelistan import models
        print("Creating a new admin user...")
        first_name = click.prompt("First name")
        last_name = click.prompt("Last name")
        email = click.prompt("Email address")
        password = click.prompt("Password", hide_input=True)
        user = models.User(
            first_name=first_name,
            last_name=last_name,
            email=email,
            password=password,
            is_admin=True,
            active=True,
        )

        models.db.session.add(user)
        models.db.session.commit()
Esempio n. 9
0
def logged_in(client):
    """Fixture for a signed in user"""
    user = models.User(
        email='*****@*****.**',
        first_name='Monty',
        last_name='Python',
    )

    models.db.session.add(user)
    models.db.session.commit()

    user.password = '******'
    models.db.session.commit()

    with client:
        rv = login(client, '*****@*****.**', 'solidsnake')
        assert rv.status_code == 302
        yield user
Esempio n. 10
0
def test_strequa(app):
    import datetime

    streque = models.Streque(value=400)
    user = models.User(email='*****@*****.**', balance=10000)
    models.db.session.add(streque)
    models.db.session.add(user)
    models.db.session.commit()

    time_before = datetime.datetime.utcnow()
    transaction = user.strequa(3)
    time_after = datetime.datetime.utcnow()

    assert transaction.amount == 3
    assert transaction.value == 400
    assert transaction.user == user
    assert time_after > transaction.timestamp > time_before

    assert user.balance == 8800
    assert user.transactions[0] == transaction
Esempio n. 11
0
def add_user(request_id=None):
    request = (models.RegistrationRequest.query.get_or_404(request_id)
               if request_id else None)

    form = forms.AddUserForm(obj=request, group_id=-1)

    form.group_id.choices = [(g.id, g.name) for g in models.Group.query]
    form.group_id.choices.insert(0, (-1, 'Ingen'))

    if form.validate_on_submit():
        user = models.User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            nickname=form.nickname.data,
            email=form.email.data,
            phone=form.phone.data,
            active=form.active.data,
            group_id=form.group_id.data if form.group_id.data != -1 else None,
        )

        models.db.session.add(user)
        models.db.session.commit()

        if request:
            models.db.session.delete(request)
            models.db.session.commit()
            flask.flash("{} skapad och förfrågan borttagen!".format(user),
                        'success')
            return flask.redirect(flask.url_for('strequeadmin.requests'))

        else:
            flask.flash("{} skapad!".format(user), 'success')
            # Redirect to clear form
            return flask.redirect(flask.url_for('strequeadmin.add_user'))

    elif form.is_submitted():
        forms.flash_errors(form)

    return flask.render_template('admin/add_user.html',
                                 form=form,
                                 is_request=bool(request_id))
Esempio n. 12
0
def populate_testdb():
    from flasquelistan import models
    monty = models.User(
        email='*****@*****.**',
        first_name='Monty',
        last_name='Python',
        phone='+468-46500400',
        balance=10000,
        active=True,
    )

    rick = models.User(
        email='*****@*****.**',
        first_name='Rick',
        nickname='The Roll',
        last_name='Astley',
        phone='0710001122',  # Invalid phone number
        balance=20050,
        active=True,
    )

    barack = models.User(
        email='*****@*****.**',
        first_name='Barack',
        last_name='Obama',
        nickname='Barry',
        phone='+1 (808) 555-2643',
        balance=100000,
        active=True,
    )

    kor = models.User(
        email='*****@*****.**',
        first_name='Kor',
        last_name='Ist',
        nickname="Party-'pranen",
        phone='074 876 54 32',
        balance=-1000,
        active=True,
    )

    malvina = models.User(
        email='*****@*****.**',
        first_name='Malvina',
        last_name='Teknolog',
        nickname='Osqulda',
        phone='',
        balance=-10000,
        active=True,
    )

    soprano = models.Group(name='Sopran', weight='40')
    alto = models.Group(name='Alt', weight='30')
    tenor = models.Group(name='Tenor', weight='20')
    bass = models.Group(name='Bas', weight='10')

    beer = models.Article(name='Öl', value=1600, weight=50, standardglas=1)
    cider = models.Article(name='Cider', value=1500, weight=40, standardglas=1)
    wine = models.Article(name='Vin', value=1400, weight=30, standardglas=1)
    shot = models.Article(name='4 cl', value=1300, weight=20, standardglas=1)
    soft = models.Article(name='Alkfritt',
                          value=1200,
                          weight=10,
                          standardglas=0)

    quote1 = models.Quote(
        text="Kom igen, testa citaten, det blir kul!",
        who="Någon, om Strequelistan",
    )

    quote2 = models.Quote(text="Ett citat utan upphovsman, spännade!")

    quote3 = models.Quote(
        text=("Explicabo possimus dolorem voluptate. "
              "Aut perferendis mollitia dolor nulla. "
              "Perferendis at consequuntur ea aliquam "
              "aut inventore quis neque."),
        who="Godtycklig medietekniker",
    )

    quote4 = models.Quote(text="much quote, such fun", who="shibe")

    models.db.session.add_all([
        monty, rick, barack, kor, malvina, soprano, alto, tenor, bass, beer,
        cider, wine, shot, soft, quote1, quote2, quote3, quote4
    ])
    models.db.session.commit()

    kor.group = soprano
    malvina.group = alto
    monty.group = tenor
    rick.group = bass
    barack.group = bass

    models.db.session.commit()