Example #1
0
import random
import string
import sys

from faker import Factory
from psycopg2 import IntegrityError

from liberapay.billing.transactions import (record_exchange_result,
                                            lock_bundles,
                                            _record_transfer_result)
from liberapay.constants import D_CENT, DONATION_LIMITS, PERIOD_CONVERSION_RATES
from liberapay.models.exchange_route import ExchangeRoute
from liberapay.models.participant import Participant
from liberapay.models import community

DONATION_PERIODS = tuple(PERIOD_CONVERSION_RATES.keys())

faker = Factory.create()


def _fake_thing(db, tablename, **kw):
    cols, vals = zip(*kw.items())
    cols = ', '.join(cols)
    placeholders = ', '.join(['%s'] * len(vals))
    return db.one(
        """
        INSERT INTO {} ({}) VALUES ({}) RETURNING *
    """.format(tablename, cols, placeholders), vals)


def fake_text_id(size=6, chars=string.ascii_lowercase + string.digits):
Example #2
0
import string
import sys

from faker import Factory
from psycopg2 import IntegrityError

from liberapay.billing.transactions import (
    record_exchange_result, lock_bundles, _record_transfer_result
)
from liberapay.constants import D_CENT, DONATION_LIMITS, PERIOD_CONVERSION_RATES
from liberapay.i18n.currencies import Money, MoneyBasket
from liberapay.models.exchange_route import ExchangeRoute
from liberapay.models import community


DONATION_PERIODS = tuple(PERIOD_CONVERSION_RATES.keys())


faker = Factory.create()


def _fake_thing(db, tablename, **kw):
    _cast = kw.pop('_cast', False)
    cols, vals = zip(*kw.items())
    cols = ', '.join(cols)
    placeholders = ', '.join(['%s']*len(vals))
    if _cast:
        tablename += ' AS r'
    returning = 'r' if _cast else '*'
    return db.one("""
        INSERT INTO {} ({}) VALUES ({}) RETURNING {}