Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
fake data
Browse files Browse the repository at this point in the history
  • Loading branch information
JessaWitzel authored and chadwhitacre committed Dec 6, 2016
1 parent c2644b5 commit ed2a7f3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 54 deletions.
4 changes: 2 additions & 2 deletions gratipay/models/team/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ def insert(cls, owner, **fields):
INSERT INTO teams
(slug, slug_lower, name, homepage,
product_or_service, todo_url, onboarding_url,
product_or_service, onboarding_url,
owner)
VALUES (%(slug)s, %(slug_lower)s, %(name)s, %(homepage)s,
%(product_or_service)s, %(todo_url)s, %(onboarding_url)s,
%(product_or_service)s, %(onboarding_url)s,
%(owner)s)
RETURNING teams.*::teams
Expand Down
70 changes: 35 additions & 35 deletions gratipay/utils/fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ def fake_participant(db, is_admin=False, random_identities=True):


def fake_exchange_route(db, participant, network=None):

if not network:
networks = ["balanced-ba", "balanced-cc", "paypal", "bitcoin"]
network = random.sample(networks, 1)[0]

insert_fake_data( db
, "exchange_routes"
, participant = participant.id
, network = network
, network = network
, address = participant.email_address
, error = "None"
, error = "None"
)


def fake_participant_identity(participant, verification=None):
"""Pick a country and make an identity for the participant there.
Expand Down Expand Up @@ -142,6 +142,7 @@ def fake_team(db, teamowner, teamname=None):
teamname = faker.first_name() + fake_text_id(3)

ctime = teamowner.ctime + datetime.timedelta(days=7)

try:
teamslug = slugize(teamname)
homepage = 'http://www.example.org/' + fake_text_id(3)
Expand All @@ -153,7 +154,6 @@ def fake_team(db, teamowner, teamname=None):
, homepage=homepage
, ctime=ctime
, product_or_service=random.sample(productorservice,1)[0]
, todo_url=homepage + '/tickets'
, onboarding_url=homepage + '/contributing'
, owner=teamowner.username
, is_approved=random.sample(isapproved,1)[0]
Expand All @@ -169,7 +169,7 @@ def fake_team(db, teamowner, teamname=None):
def fake_payment_instruction(db, participant, team):
"""Create a fake payment_instruction
"""
start_date = max(participant.claimed_time, team.ctime)
start_date = max(participant.claimed_time, team.ctime)
ctime=faker.date_time_between(start_date)
return insert_fake_data( db
, "payment_instructions"
Expand Down Expand Up @@ -334,9 +334,9 @@ def populate_db(db, num_participants=100, ntips=200, num_teams=5):
teamowners = random.sample(participants, num_teams)
for teamowner in teamowners:
teams.append(fake_team(db, teamowner))
# Creating a fake Gratipay Team
teamowner = random.choice(participants)

# Creating a fake Gratipay Team
teamowner = random.choice(participants)
teams.append(fake_team(db, teamowner, "Gratipay"))

print("Making Payment Instructions")
Expand Down Expand Up @@ -374,64 +374,64 @@ def populate_db(db, num_participants=100, ntips=200, num_teams=5):
payday_counter += 1
end_date = date + datetime.timedelta(days=7)
week_payment_instructions = filter(lambda x: x['mtime'] < date, payment_instructions)

# Need to create the payday record before inserting payment records
params = dict(ts_start=date, ts_end=end_date)
with db.get_cursor() as cursor:
payday_id = cursor.one("""
INSERT INTO paydays
(ts_start, ts_end)
INSERT INTO paydays
(ts_start, ts_end)
VALUES (%(ts_start)s, %(ts_end)s)
RETURNING id
""", params)
""", params)
sys.stdout.write("\rMaking Paydays (%i/%i)" % (payday_id, paydays_total))
sys.stdout.flush()

week_payments = []

week_payments = []
for payment_instruction in week_payment_instructions:
participant = Participant.from_id(payment_instruction['participant_id'])
team = Team.from_id(payment_instruction['team_id'])
amount = payment_instruction['amount']
assert participant.username != team.owner
week_payments.append(fake_payment(
db=db,
participant=participant.username,
team=team.slug,
timestamp=date,
amount=amount,
db=db,
participant=participant.username,
team=team.slug,
timestamp=date,
amount=amount,
payday=payday_id,
direction='to-team'
)
)

if amount != 0:
fee = amount * D('0.02')
fee = abs(fee.quantize(D('.01')))
fake_exchange(
db=db,
participant=participant,
db=db,
participant=participant,
amount=amount,
fee=fee,
timestamp=date + datetime.timedelta(seconds=1)
fee=fee,
timestamp=date + datetime.timedelta(seconds=1)
)

for team in teams:
week_payments_to_team = filter(lambda x: x['team'] == team.slug, week_payments)
pay_out = sum(t['amount'] for t in week_payments_to_team)
if pay_out:

if pay_out:
week_payments.append(fake_payment(
db=db,
participant=team.owner,
team=team.slug,
timestamp=date,
amount=pay_out,
participant=team.owner,
team=team.slug,
timestamp=date,
amount=pay_out,
payday=payday_id,
direction= 'to-participant'
)
)

actives=set()


Expand All @@ -446,8 +446,8 @@ def populate_db(db, num_participants=100, ntips=200, num_teams=5):
UPDATE paydays
SET nusers=%(nusers)s, volume=%(volume)s
WHERE id=%(payday_id)s
""", params)
""", params)

date = end_date
print("")

Expand Down
1 change: 0 additions & 1 deletion sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ BEGIN;
ALTER TABLE teams ALTER COLUMN getting_paid DROP NOT NULL;

ALTER TABLE teams ADD COLUMN onboarding_url text NOT NULL DEFAULT '';
ALTER TABLE teams ADD COLUMN todo_url text NOT NULL DEFAULT '';

END;

Expand Down
12 changes: 2 additions & 10 deletions tests/py/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ class TestTeams(Harness):
'product_or_service': 'We make widgets.',
'homepage': 'http://gratipay.com/',
'onboarding_url': 'http://inside.gratipay.com/',
'todo_url': 'https://github.com/gratipay',
'agree_public': 'true',
'agree_payroll': 'true',
'agree_terms': 'true',
Expand Down Expand Up @@ -226,13 +225,10 @@ def test_casing_of_urls_survives(self):
self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='')
self.post_new(dict( self.valid_data
, homepage='Http://gratipay.com/'
, onboarding_url='http://INSIDE.GRATipay.com/'
, todo_url='hTTPS://github.com/GRATIPAY'
))
, onboarding_url='http://INSIDE.GRATipay.com/'))
team = T('gratiteam')
assert team.homepage == 'Http://gratipay.com/'
assert team.onboarding_url == 'http://INSIDE.GRATipay.com/'
assert team.todo_url == 'hTTPS://github.com/GRATIPAY'

def test_casing_of_slug_survives(self):
self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='')
Expand Down Expand Up @@ -301,9 +297,6 @@ def test_error_message_for_bad_url(self):
r = self.post_new(dict(self.valid_data, onboarding_url='foo'), expected=400)
assert "an http[s]:// URL for the 'Self-onboarding Documentation URL' field." in r.body

r = self.post_new(dict(self.valid_data, todo_url='foo'), expected=400)
assert "Please enter an http[s]:// URL for the 'To-do URL' field." in r.body

def test_error_message_for_invalid_team_name(self):
self.make_participant('alice', claimed_time='now', email_address='[email protected]', last_paypal_result='')
data = dict(self.valid_data)
Expand Down Expand Up @@ -451,7 +444,6 @@ def test_update_works(self):
'product_or_service': 'We save galaxies.',
'homepage': 'http://starwars-enterprise.com/',
'onboarding_url': 'http://starwars-enterprise.com/onboarding',
'todo_url': 'http://starwars-enterprise.com/todos',
}
team.update(**update_data)
team = T('enterprise')
Expand All @@ -460,7 +452,7 @@ def test_update_works(self):

def test_can_only_update_allowed_fields(self):
allowed_fields = set(['name', 'product_or_service', 'homepage',
'onboarding_url', 'todo_url'])
'onboarding_url',])

team = self.make_team(slug='enterprise')

Expand Down
4 changes: 0 additions & 4 deletions www/new.spt
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ suppress_sidebar = True
) }}</i></p>
<input type="text" name="onboarding_url" required>

<label><h2>{{ _("To-do URL") }}</h2></label>
<p><i>{{ _("Where can people find a list of available work to do for your Team?") }}</i></p>
<input type="text" name="todo_url" required>

<h2>{{ _("Agreements") }}</h2>
<input type="checkbox" value="true" name="agree_public" id="agree_public">
<label for="agree_public">
Expand Down
3 changes: 1 addition & 2 deletions www/teams/create.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ field_names = {
'product_or_service': 'Product or Service',
'homepage': 'Homepage',
'onboarding_url': 'Self-onboarding Documentation URL',
'todo_url': 'To-do URL',
}

if user.ANON:
Expand Down Expand Up @@ -64,7 +63,7 @@ if request.method == 'POST':
raise Response(400, _("Please fill out the '{}' field.", field_names[field]))
fields[field] = value

for field in ('homepage', 'onboarding_url', 'todo_url'):
for field in ('homepage', 'onboarding_url'):
if not any(map(fields[field].lower().startswith, ('http://', 'https://'))):
raise Response(400, _( "Please enter an http[s]:// URL for the '{}' field."
, field_names[field]
Expand Down

0 comments on commit ed2a7f3

Please sign in to comment.