From ed2a7f30f3db0ae5c6d315d1d2e4c15b1d770c95 Mon Sep 17 00:00:00 2001 From: Jessa Witzel Date: Wed, 30 Nov 2016 23:30:29 -0500 Subject: [PATCH] fake data --- gratipay/models/team/__init__.py | 4 +- gratipay/utils/fake_data.py | 70 ++++++++++++++++---------------- sql/schema.sql | 1 - tests/py/test_teams.py | 12 +----- www/new.spt | 4 -- www/teams/create.json.spt | 3 +- 6 files changed, 40 insertions(+), 54 deletions(-) diff --git a/gratipay/models/team/__init__.py b/gratipay/models/team/__init__.py index 56ad8ce03b..496a6978d8 100644 --- a/gratipay/models/team/__init__.py +++ b/gratipay/models/team/__init__.py @@ -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 diff --git a/gratipay/utils/fake_data.py b/gratipay/utils/fake_data.py index 5172e7762c..5b65600c4f 100644 --- a/gratipay/utils/fake_data.py +++ b/gratipay/utils/fake_data.py @@ -100,7 +100,7 @@ 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] @@ -108,11 +108,11 @@ def fake_exchange_route(db, participant, network=None): 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. @@ -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) @@ -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] @@ -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" @@ -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") @@ -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() @@ -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("") diff --git a/sql/schema.sql b/sql/schema.sql index b8df2ab550..83bda02a3e 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -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; diff --git a/tests/py/test_teams.py b/tests/py/test_teams.py index 0fa8452c04..b5eb9db302 100644 --- a/tests/py/test_teams.py +++ b/tests/py/test_teams.py @@ -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', @@ -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='') @@ -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='alice@example.com', last_paypal_result='') data = dict(self.valid_data) @@ -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') @@ -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') diff --git a/www/new.spt b/www/new.spt index b116af13ba..9c39338763 100644 --- a/www/new.spt +++ b/www/new.spt @@ -68,10 +68,6 @@ suppress_sidebar = True ) }}

- -

{{ _("Where can people find a list of available work to do for your Team?") }}

- -

{{ _("Agreements") }}