def test_admin_can_modify_is_approved(self):
        assert self.gratiteam.is_approved == None

        # Change to True
        self.hit({'to': 'true'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved == True

        # Change to False
        self.hit({'to': 'false'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved == False
    def test_admin_can_modify_is_approved(self):
        assert self.gratiteam.is_approved == None

        # Change to True
        self.hit({"to": "true"})
        team = Team.from_slug("gratiteam")
        assert team.is_approved == True

        # Change to False
        self.hit({"to": "false"})
        team = Team.from_slug("gratiteam")
        assert team.is_approved == False
    def test_giving_is_updated_when_credit_card_fails(self, btd):
        alice = self.make_participant("alice", claimed_time="now", last_bill_result="")
        team = self.make_team(is_approved=True)

        alice.set_payment_instruction(team, "5.00")  # funded

        assert alice.giving == Decimal("5.00")
        assert Team.from_slug(team.slug).receiving == Decimal("5.00")

        ExchangeRoute.from_network(alice, "braintree-cc").update_error("Card expired")

        assert Participant.from_username("alice").giving == Decimal("0.00")
        assert Team.from_slug(team.slug).receiving == Decimal("0.00")
    def test_giving_is_updated_when_credit_card_is_updated(self, btd):
        alice = self.make_participant("alice", claimed_time="now", last_bill_result="fail")
        team = self.make_team(is_approved=True)

        alice.set_payment_instruction(team, "5.00")  # Not funded, failing card

        assert alice.giving == Decimal("0.00")
        assert Team.from_slug(team.slug).receiving == Decimal("0.00")

        # Alice updates her card..
        ExchangeRoute.from_network(alice, "braintree-cc").invalidate()
        ExchangeRoute.insert(alice, "braintree-cc", "/cards/bar", "")

        assert alice.giving == Decimal("5.00")
        assert Team.from_slug(team.slug).receiving == Decimal("5.00")
    def test_giving_is_updated_when_credit_card_is_updated(self, btd):
        alice = self.make_participant('alice', claimed_time='now', last_bill_result='fail')
        team = self.make_team(is_approved=True)

        alice.set_payment_instruction(team, '5.00') # Not funded, failing card

        assert alice.giving == Decimal('0.00')
        assert Team.from_slug(team.slug).receiving == Decimal('0.00')

        # Alice updates her card..
        ExchangeRoute.from_network(alice, 'braintree-cc').invalidate()
        ExchangeRoute.insert(alice, 'braintree-cc', '/cards/bar', '')

        assert alice.giving == Decimal('5.00')
        assert Team.from_slug(team.slug).receiving == Decimal('5.00')
    def test_giving_is_updated_when_credit_card_fails(self, btd):
        alice = self.make_participant('alice', claimed_time='now', last_bill_result='')
        team = self.make_team(is_approved=True)

        alice.set_payment_instruction(team, '5.00') # funded

        assert alice.giving == Decimal('5.00')
        assert Team.from_slug(team.slug).receiving == Decimal('5.00')
        assert Participant.from_username(team.owner).taking == Decimal('5.00')

        ExchangeRoute.from_network(alice, 'braintree-cc').update_error("Card expired")

        assert Participant.from_username('alice').giving == Decimal('0.00')
        assert Team.from_slug(team.slug).receiving == Decimal('0.00')
        assert Participant.from_username(team.owner).taking == Decimal('0.00')
Beispiel #7
0
    def test_giving_is_updated_when_credit_card_is_updated(self, btd):
        alice = self.make_participant('alice', claimed_time='now', last_bill_result='fail')
        team = self.make_team(is_approved=True)

        alice.set_payment_instruction(team, '5.00') # Not funded, failing card

        assert alice.giving == Decimal('0.00')
        assert Team.from_slug(team.slug).receiving == Decimal('0.00')

        # Alice updates her card..
        ExchangeRoute.from_network(alice, 'braintree-cc').invalidate()
        ExchangeRoute.insert(alice, 'braintree-cc', '/cards/bar', '')

        assert alice.giving == Decimal('5.00')
        assert Team.from_slug(team.slug).receiving == Decimal('5.00')
Beispiel #8
0
    def test_giving_is_updated_when_credit_card_fails(self, btd):
        alice = self.make_participant('alice', claimed_time='now', last_bill_result='')
        team = self.make_team(is_approved=True)

        alice.set_payment_instruction(team, '5.00') # funded

        assert alice.giving == Decimal('5.00')
        assert Team.from_slug(team.slug).receiving == Decimal('5.00')
        assert Participant.from_username(team.owner).taking == Decimal('5.00')

        ExchangeRoute.from_network(alice, 'braintree-cc').update_error("Card expired")

        assert Participant.from_username('alice').giving == Decimal('0.00')
        assert Team.from_slug(team.slug).receiving == Decimal('0.00')
        assert Participant.from_username(team.owner).taking == Decimal('0.00')
Beispiel #9
0
def fake_team(db, teamowner, teamname=None):
    """Create a fake team
    """
    isapproved = [True, False]
    productorservice = ['Product', 'Service']

    if teamname is None:
        teamname = faker.first_name() + fake_text_id(3)

    try:
        teamslug = slugize(teamname)
        homepage = 'http://www.example.org/' + fake_text_id(3)
        insert_fake_data(db,
                         "teams",
                         slug=teamslug,
                         slug_lower=teamslug.lower(),
                         name=teamname,
                         homepage=homepage,
                         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],
                         receiving=0.1,
                         nreceiving_from=3)
    except (IntegrityError, InvalidTeamName):
        return fake_team(db, teamowner)

    return Team.from_slug(teamslug)
Beispiel #10
0
def fake_team(db, teamowner):
    """Create a fake team
    """
    isapproved = [True, False]
    productorservice = ['Product', 'Service']

    teamname = faker.first_name() + fake_text_id(3)
    teamslugname = faker.city()

    try:
        #using community.slugize
        teamslug = community.slugize(teamslugname)
        homepage = 'http://www.example.org/' + fake_text_id(3)
        _fake_thing(db,
                    "teams",
                    slug=teamslug,
                    slug_lower=teamslug.lower(),
                    name=teamname,
                    homepage=homepage,
                    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],
                    receiving=0.1,
                    nreceiving_from=3)
    except IntegrityError:
        return fake_team(db, teamowner)

    return Team.from_slug(teamslug)
def fake_team(db, teamowner):
    """Create a fake team
    """
    isapproved = [True, False]
    productorservice = ['Product', 'Service']

    teamname = faker.first_name() + fake_text_id(3)
    teamslugname = faker.city()

    try:
        #using community.slugize
        teamslug = community.slugize(teamslugname)
        _fake_thing(db,
                    "teams",
                    slug=teamslug,
                    slug_lower=teamslug.lower(),
                    name=teamname,
                    homepage='www.example.org/' + fake_text_id(3),
                    product_or_service=random.sample(productorservice, 1)[0],
                    getting_involved='build',
                    getting_paid='paypal',
                    owner=teamowner.username,
                    is_approved=random.sample(isapproved, 1)[0],
                    receiving=0.1,
                    nmembers=3)
    except IntegrityError:
        return fake_team(db, teamowner)

    return Team.from_slug(teamslug)
Beispiel #12
0
def fake_team(db, teamowner, teamname=None):
    """Create a fake team
    """
    is_approved = [True, False, None]
    product_or_service = ['Product','Service']

    if teamname is 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)
        insert_fake_data( db
                        , "teams"
                        , slug=teamslug
                        , slug_lower=teamslug.lower()
                        , name=teamname
                        , homepage=homepage
                        , ctime=ctime
                        , product_or_service=random.choice(product_or_service)
                        , onboarding_url=homepage + '/contributing'
                        , owner=teamowner.username
                        , is_approved=random.choice(is_approved)
                        , receiving=6
                        , nreceiving_from=9
                         )
    except (IntegrityError, InvalidTeamName):
        return fake_team(db, teamowner)

    return Team.from_slug(teamslug)
Beispiel #13
0
def fake_team(db, teamowner, teamname=None):
    """Create a fake team
    """
    is_approved = [True, False, None]
    product_or_service = ['Product', 'Service']

    if teamname is 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)
        insert_fake_data(db,
                         "teams",
                         slug=teamslug,
                         slug_lower=teamslug.lower(),
                         name=teamname,
                         homepage=homepage,
                         ctime=ctime,
                         product_or_service=random.choice(product_or_service),
                         onboarding_url=homepage + '/contributing',
                         owner=teamowner.username,
                         is_approved=random.choice(is_approved),
                         receiving=6,
                         nreceiving_from=9)
    except (IntegrityError, InvalidTeamName):
        return fake_team(db, teamowner)

    return Team.from_slug(teamslug)
 def test_edit_needs_auth(self):
     self.make_team(slug='enterprise', is_approved=True)
     response = self.client.PxST( '/enterprise/edit/edit.json'
                                 , data={ 'name': 'Enterprise' })
     assert response.code == 401
     team = Team.from_slug('enterprise')
     assert team.name == 'The Enterprise'
Beispiel #15
0
 def test_edit_needs_auth(self):
     self.make_team(slug='enterprise', is_approved=True)
     response = self.client.PxST('/enterprise/edit/edit.json',
                                 data={'name': 'Enterprise'})
     assert response.code == 401
     team = Team.from_slug('enterprise')
     assert team.name == 'The Enterprise'
Beispiel #16
0
def fake_team(db, teamowner):
    """Create a fake team
    """
    isapproved = [True, False]
    productorservice = ['Product','Service']

    teamname = faker.first_name() + fake_text_id(3)
    teamslugname = faker.city()

    try:
        teamslug = slugize(teamslugname)
        homepage = 'http://www.example.org/' + fake_text_id(3)
        _fake_thing( db
                   , "teams"
                   , slug=teamslug
                   , slug_lower=teamslug.lower()
                   , name=teamname
                   , homepage=homepage
                   , 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]
                   , receiving=0.1
                   , nreceiving_from=3
                   )
    except IntegrityError:
        return fake_team(db, teamowner)

    return Team.from_slug(teamslug)
def get_team(state):
    """Given a Request, raise Response or return Team.
    """
    request = state['request']
    user = state['user']
    slug = request.line.uri.path['team']
    qs = request.line.uri.querystring

    from gratipay.models.team import Team  # avoid circular import
    team = Team.from_slug(slug)

    if team is None:
        # Try to redirect to a Participant.
        from gratipay.models.participant import Participant # avoid circular import
        participant = Participant.from_username(slug)
        if participant is not None:
            qs = '?' + request.qs.raw if request.qs.raw else ''
            request.redirect('/~' + request.path.raw[1:] + qs)
        raise Response(404)

    canonicalize(request.line.uri.path.raw, '/', team.slug, slug, qs)

    if team.is_closed and not user.ADMIN:
        raise Response(410)

    return team
Beispiel #18
0
def get_team(state):
    """Given a Request, raise Response or return Team.
    """
    redirect = state['website'].redirect
    request = state['request']
    user = state['user']
    slug = request.line.uri.path['team']
    qs = request.line.uri.querystring

    from gratipay.models.team import Team  # avoid circular import
    team = Team.from_slug(slug)

    if team is None:
        # Try to redirect to a Participant.
        from gratipay.models.participant import Participant  # avoid circular import
        participant = Participant.from_username(slug)
        if participant is not None:
            qs = '?' + request.qs.raw if request.qs.raw else ''
            redirect('/~' + request.path.raw[1:] + qs)
        raise Response(404)

    canonicalize(redirect, request.line.uri.path.raw, '/', team.slug, slug, qs)

    if team.is_closed and not user.ADMIN:
        raise Response(410)

    return team
Beispiel #19
0
def fake_team(db, teamowner):
    """Create a fake team
    """
    isapproved = [True, False]
    productorservice = ['Product','Service']

    teamname = faker.first_name() + fake_text_id(3)
    teamslugname = faker.city()

    try:
        #using community.slugize
        teamslug = community.slugize(teamslugname)
        _fake_thing( db
                   , "teams"
                   , slug=teamslug
                   , slug_lower=teamslug.lower()
                   , name=teamname
                   , homepage='www.example.org/' + fake_text_id(3)
                   , product_or_service=random.sample(productorservice,1)[0]
                   , getting_involved='build'
                   , getting_paid='paypal'
                   , owner=teamowner.username
                   , is_approved=random.sample(isapproved,1)[0]
                   , receiving=0.1
                   , nmembers=3
                   )
    except IntegrityError:
        return fake_team(db, teamowner)

    return Team.from_slug(teamslug)
 def test_edit_with_empty_values_raises_error(self):
     self.make_team(slug='enterprise', is_approved=True)
     response = self.client.PxST( '/enterprise/edit/edit.json'
                                 , data={ 'name': '   ' }
                                 , auth_as='picard')
     assert response.code == 400
     team = Team.from_slug('enterprise')
     assert team.name == 'The Enterprise'
 def test_can_edit_teams_under_review(self):
     self.make_team(slug='enterprise', is_approved=None)
     response = self.client.POST( '/enterprise/edit/edit.json'
                                 , data={ 'name': 'Enterprise' }
                                 , auth_as='picard')
     assert response.code == 200
     team = Team.from_slug('enterprise')
     assert team.name == 'Enterprise'
Beispiel #22
0
 def test_edit_with_empty_values_raises_error(self):
     self.make_team(slug='enterprise', is_approved=True)
     response = self.client.PxST('/enterprise/edit/edit.json',
                                 data={'name': '   '},
                                 auth_as='picard')
     assert response.code == 400
     team = Team.from_slug('enterprise')
     assert team.name == 'The Enterprise'
 def test_cant_edit_rejected_teams(self):
     self.make_team(slug='enterprise', is_approved=False)
     response = self.client.PxST( '/enterprise/edit/edit.json'
                                 , data={ 'name': 'Enterprise' }
                                 , auth_as='picard')
     assert response.code == 403
     team = Team.from_slug('enterprise')
     assert team.name == 'The Enterprise'
Beispiel #24
0
 def test_casing_of_slug_survives(self):
     self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='')
     data = dict(self.valid_data)
     data['name'] = 'GratiTeam'
     self.post_new(dict(data))
     team = Team.from_slug('GratiTeam')
     assert team is not None
     assert team.slug_lower == 'gratiteam'
Beispiel #25
0
 def test_can_edit_teams_under_review(self):
     self.make_team(slug='enterprise', is_approved=None)
     response = self.client.POST('/enterprise/edit/edit.json',
                                 data={'name': 'Enterprise'},
                                 auth_as='picard')
     assert response.code == 200
     team = Team.from_slug('enterprise')
     assert team.name == 'Enterprise'
Beispiel #26
0
 def test_cant_edit_rejected_teams(self):
     self.make_team(slug='enterprise', is_approved=False)
     response = self.client.PxST('/enterprise/edit/edit.json',
                                 data={'name': 'Enterprise'},
                                 auth_as='picard')
     assert response.code == 403
     team = Team.from_slug('enterprise')
     assert team.name == 'The Enterprise'
Beispiel #27
0
 def test_all_fields_persist(self):
     self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='')
     self.post_new(dict(self.valid_data))
     team = Team.from_slug('gratiteam')
     assert team.name == 'Gratiteam'
     assert team.homepage == 'http://gratipay.com/'
     assert team.product_or_service == 'We make widgets.'
     fallback = 'https://github.com/gratipay/team-review/issues#error-401'
     assert team.review_url in (REVIEW_URL, fallback)
    def test_only_admin_and_owner_can_edit(self):
        self.make_participant('alice', claimed_time='now')
        self.make_participant('admin', claimed_time='now', is_admin=True)
        self.make_team(slug='enterprise', is_approved=True)

        response = self.client.PxST( '/enterprise/edit/edit.json'
                                    , data={ 'name': 'Enterprise' }
                                    , auth_as='alice')
        assert response.code == 403
        team = Team.from_slug('enterprise')
        assert team.name == 'The Enterprise'

        response = self.client.POST( '/enterprise/edit/edit.json'
                                    , data={ 'name': 'Enterprise' }
                                    , auth_as='admin')
        assert response.code == 200
        team = Team.from_slug('enterprise')
        assert team.name == 'Enterprise'
Beispiel #29
0
 def test_all_fields_persist(self):
     self.make_participant("alice", claimed_time="now", email_address="", last_paypal_result="")
     self.post_new(dict(self.valid_data))
     team = Team.from_slug("gratiteam")
     assert team.name == "Gratiteam"
     assert team.homepage == "http://gratipay.com/"
     assert team.product_or_service == "We make widgets."
     fallback = "https://github.com/gratipay/team-review/issues#error-401"
     assert team.review_url in (REVIEW_URL, fallback)
Beispiel #30
0
 def test_all_fields_persist(self):
     self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='')
     self.post_new(dict(self.valid_data))
     team = Team.from_slug('gratiteam')
     assert team.name == 'Gratiteam'
     assert team.homepage == 'http://gratipay.com/'
     assert team.product_or_service == 'We make widgets.'
     fallback = 'https://github.com/gratipay/team-review/issues#error-401'
     assert team.review_url in (REVIEW_URL, fallback)
Beispiel #31
0
    def test_only_admin_and_owner_can_edit(self):
        self.make_participant('alice', claimed_time='now')
        self.make_participant('admin', claimed_time='now', is_admin=True)
        self.make_team(slug='enterprise', is_approved=True)

        response = self.client.PxST('/enterprise/edit/edit.json',
                                    data={'name': 'Enterprise'},
                                    auth_as='alice')
        assert response.code == 403
        team = Team.from_slug('enterprise')
        assert team.name == 'The Enterprise'

        response = self.client.POST('/enterprise/edit/edit.json',
                                    data={'name': 'Enterprise'},
                                    auth_as='admin')
        assert response.code == 200
        team = Team.from_slug('enterprise')
        assert team.name == 'Enterprise'
 def test_all_fields_persist(self):
     self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='')
     self.post_new(dict(self.valid_data))
     team = Team.from_slug('gratiteam')
     assert team.name == 'Gratiteam'
     assert team.homepage == 'http://gratipay.com/'
     assert team.product_or_service == 'We make widgets.'
     assert team.onboarding_url == 'http://inside.gratipay.com/'
     assert team.todo_url == 'https://github.com/gratipay'
Beispiel #33
0
 def test_all_fields_persist(self):
     self.make_participant('alice', claimed_time='now', email_address='', last_ach_result='')
     self.post_new(dict(self.valid_data))
     team = Team.from_slug('gratiteam')
     assert team.name == 'Gratiteam'
     assert team.homepage == 'http://gratipay.com/'
     assert team.product_or_service == 'We make widgets.'
     assert team.revenue_model == 'People pay us.'
     assert team.getting_involved == 'People do stuff.'
     assert team.getting_paid == 'We pay people.'
    def test_cant_edit_closed_teams(self):
        self.make_team(slug='enterprise', is_approved=True)
        self.db.run("UPDATE teams SET is_closed = true WHERE slug = 'enterprise'")

        response = self.client.PxST( '/enterprise/edit/edit.json'
                                    , data={ 'name': 'Enterprise' }
                                    , auth_as='picard')
        assert response.code in (403, 410)
        team = Team.from_slug('enterprise')
        assert team.name == 'The Enterprise'
Beispiel #35
0
 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'
                        ))
     team = Team.from_slug('gratiteam')
     assert team.homepage == 'Http://gratipay.com/'
     assert team.onboarding_url == 'http://INSIDE.GRATipay.com/'
     assert team.todo_url == 'hTTPS://github.com/GRATIPAY'
Beispiel #36
0
    def test_cant_edit_closed_teams(self):
        self.make_team(slug='enterprise', is_approved=True)
        self.db.run(
            "UPDATE teams SET is_closed = true WHERE slug = 'enterprise'")

        response = self.client.PxST('/enterprise/edit/edit.json',
                                    data={'name': 'Enterprise'},
                                    auth_as='picard')
        assert response.code in (403, 410)
        team = Team.from_slug('enterprise')
        assert team.name == 'The Enterprise'
Beispiel #37
0
 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'
                        ))
     team = Team.from_slug('gratiteam')
     assert team.homepage == 'Http://gratipay.com/'
     assert team.onboarding_url == 'http://INSIDE.GRATipay.com/'
     assert team.todo_url == 'hTTPS://github.com/GRATIPAY'
Beispiel #38
0
 def test_casing_of_slug_survives(self):
     self.make_participant('alice',
                           claimed_time='now',
                           email_address='',
                           last_paypal_result='')
     data = dict(self.valid_data)
     data['name'] = 'GratiTeam'
     self.post_new(dict(data))
     team = Team.from_slug('GratiTeam')
     assert team is not None
     assert team.slug_lower == 'gratiteam'
    def test_edit_with_bad_url_raises_error(self):
        self.make_team( slug='enterprise'
                      , is_approved=True
                      , homepage='http://starwars-enterprise.com/')

        r = self.client.PxST( '/enterprise/edit/edit.json'
                            , data={ 'homepage': 'foo' }
                            , auth_as='picard')
        assert r.code == 400
        assert "Please enter an http[s]:// URL for the 'Homepage' field." in r.body
        team = Team.from_slug('enterprise')
        assert team.homepage == 'http://starwars-enterprise.com/'
Beispiel #40
0
    def test_edit_with_bad_url_raises_error(self):
        self.make_team(slug='enterprise',
                       is_approved=True,
                       homepage='http://starwars-enterprise.com/')

        r = self.client.PxST('/enterprise/edit/edit.json',
                             data={'homepage': 'foo'},
                             auth_as='picard')
        assert r.code == 400
        assert "Please enter an http[s]:// URL for the 'Homepage' field." in r.body
        team = Team.from_slug('enterprise')
        assert team.homepage == 'http://starwars-enterprise.com/'
Beispiel #41
0
 def test_update_works(self):
     team = self.make_team(slug='enterprise')
     update_data = {
         'name': 'Enterprise',
         '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 = Team.from_slug('enterprise')
     for field in update_data:
         assert getattr(team, field) == update_data[field]
Beispiel #42
0
    def test_admin_can_modify_is_approved(self):
        assert self.gratiteam.is_approved is None

        # Change to Approved
        self.hit({'status': 'approved'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved is True

        # Change to Rejected
        self.hit({'status': 'rejected'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved is False

        # Change back to Approved
        self.hit({'status': 'approved'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved is True

        # Change to Under Review
        self.hit({'status': 'unreviewed'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved is None
Beispiel #43
0
 def test_all_fields_persist(self):
     self.make_participant('alice',
                           claimed_time='now',
                           email_address='',
                           last_paypal_result='')
     self.post_new(dict(self.valid_data))
     team = Team.from_slug('gratiteam')
     assert team.name == 'Gratiteam'
     assert team.homepage == 'http://gratipay.com/'
     assert team.product_or_service == 'We make widgets.'
     assert team.revenue_model == 'People pay us.'
     assert team.getting_involved == 'People do stuff.'
     assert team.getting_paid == 'We pay people.'
Beispiel #44
0
 def test_update_works(self):
     team = self.make_team(slug='enterprise')
     update_data = {
         'name': 'Enterprise',
         '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 = Team.from_slug('enterprise')
     for field in update_data:
         assert getattr(team, field) == update_data[field]
    def test_admin_can_modify_is_approved(self):
        assert self.gratiteam.is_approved is None

        # Change to Approved
        self.hit({'status': 'approved'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved is True

        # Change to Rejected
        self.hit({'status': 'rejected'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved is False

        # Change back to Approved
        self.hit({'status': 'approved'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved is True

        # Change to Under Review
        self.hit({'status': 'unreviewed'})
        team = Team.from_slug('gratiteam')
        assert team.is_approved is None
Beispiel #46
0
 def test_update_works(self):
     team = self.make_team(slug="enterprise")
     update_data = {
         "name": "Enterprise",
         "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 = Team.from_slug("enterprise")
     for field in update_data:
         assert getattr(team, field) == update_data[field]
Beispiel #47
0
 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",
         )
     )
     team = Team.from_slug("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_can_only_edit_allowed_fields(self):
        allowed_fields = set(['name', 'image', 'product_or_service',
            'homepage', 'onboarding_url', 'todo_url'])

        team = self.make_team(slug='enterprise', is_approved=None)

        fields = vars(team).keys()
        for field in fields:
            if field not in allowed_fields:
                response = self.client.POST( '/enterprise/edit/edit.json'
                                            , data={ field: 'foo' }
                                            , auth_as='picard')
                new_team = Team.from_slug('enterprise')
                assert response.code == 200
                assert getattr(new_team, field) == getattr(team, field)
Beispiel #49
0
    def test_can_only_edit_allowed_fields(self):
        allowed_fields = set([
            'name', 'image', 'product_or_service', 'homepage',
            'onboarding_url', 'todo_url'
        ])

        team = self.make_team(slug='enterprise', is_approved=None)

        fields = vars(team).keys()
        for field in fields:
            if field not in allowed_fields:
                response = self.client.POST('/enterprise/edit/edit.json',
                                            data={field: 'foo'},
                                            auth_as='picard')
                new_team = Team.from_slug('enterprise')
                assert response.code == 200
                assert getattr(new_team, field) == getattr(team, field)
    def test_edit_supports_partial_updates(self):
        self.make_team(slug='enterprise', is_approved=True)
        edit_data = {
            'product_or_service': 'We save galaxies.',
            'homepage': 'http://starwars-enterprise.com/',
            'image': FileUpload(IMAGE, 'logo.png'),
        }
        self.client.POST( '/enterprise/edit/edit.json'
                         , data=edit_data
                         , auth_as='picard')

        team = Team.from_slug('enterprise')
        assert team.name == 'The Enterprise'
        assert team.product_or_service == 'We save galaxies.'
        assert team.homepage == 'http://starwars-enterprise.com/'
        assert team.onboarding_url == ''
        assert team.todo_url == ''
        assert team.load_image('original') == IMAGE
Beispiel #51
0
    def test_edit_supports_partial_updates(self):
        self.make_team(slug='enterprise', is_approved=True)
        edit_data = {
            'product_or_service': 'We save galaxies.',
            'homepage': 'http://starwars-enterprise.com/',
            'image': FileUpload(IMAGE, 'logo.png'),
        }
        self.client.POST('/enterprise/edit/edit.json',
                         data=edit_data,
                         auth_as='picard')

        team = Team.from_slug('enterprise')
        assert team.name == 'The Enterprise'
        assert team.product_or_service == 'We save galaxies.'
        assert team.homepage == 'http://starwars-enterprise.com/'
        assert team.onboarding_url == ''
        assert team.todo_url == ''
        assert team.load_image('original') == IMAGE
Beispiel #52
0
    def test_edit_with_empty_data_does_nothing(self):
        team_data = {
            'slug': 'enterprise',
            'is_approved': True,
            'name': 'Enterprise',
            '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',
        }
        self.make_team(**team_data)
        r = self.client.POST('/enterprise/edit/edit.json',
                             data={},
                             auth_as='picard')
        assert r.code == 200

        team = Team.from_slug('enterprise')
        for field in team_data:
            assert getattr(team, field) == team_data[field]
    def test_edit_with_empty_data_does_nothing(self):
        team_data = {
            'slug': 'enterprise',
            'is_approved': True,
            'name': 'Enterprise',
            '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',
        }
        self.make_team(**team_data)
        r = self.client.POST( '/enterprise/edit/edit.json'
                            , data={}
                            , auth_as='picard')
        assert r.code == 200

        team = Team.from_slug('enterprise')
        for field in team_data:
            assert getattr(team, field) == team_data[field]
Beispiel #54
0
    def get_or_create_linked_team(self, cursor, owner):
        """Given a db cursor and a :py:class:`Participant`, return a
        :py:class:`~gratipay.models.team.Team`.
        """
        team = self.load_team(cursor)
        if team:
            return team

        def slug_options():
            # Having analyzed existing names, we should never get `@` without
            # `/`. Be conservative in what we accept! Oh, wait ...
            base_name = self.name.split('/')[1] if self.name.startswith(
                '@') else self.name
            yield base_name
            for i in range(1, 10):
                yield '{}-{}'.format(base_name, i)
            yield uuid.uuid4().hex

        for slug in slug_options():
            if cursor.one('SELECT count(*) FROM teams WHERE slug=%s',
                          (slug, )) == 0:
                break

        team = _Team.insert(slug=slug,
                            slug_lower=slug.lower(),
                            name=slug,
                            homepage='https://www.npmjs.com/package/' +
                            self.name,
                            product_or_service=self.description,
                            owner=owner,
                            _cursor=cursor)
        cursor.run(
            'INSERT INTO teams_to_packages (team_id, package_id) '
            'VALUES (%s, %s)', (team.id, self.id))
        self.app.add_event(
            cursor, 'package',
            dict(id=self.id, action='link', values=dict(team_id=team.id)))
        return team
    def test_edit(self):
        self.make_team(slug='enterprise', is_approved=True)
        edit_data = {
            'name': 'Enterprise',
            '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',
            'image': FileUpload(IMAGE, 'logo.png'),
        }
        data = json.loads(self.client.POST( '/enterprise/edit/edit.json'
                                          , data=edit_data
                                          , auth_as='picard').body)

        team = Team.from_slug('enterprise')
        assert data == team.to_dict()

        assert team.name == 'Enterprise'
        assert team.product_or_service == 'We save galaxies.'
        assert team.homepage == 'http://starwars-enterprise.com/'
        assert team.onboarding_url == 'http://starwars-enterprise.com/onboarding'
        assert team.todo_url == 'http://starwars-enterprise.com/todos'
        assert team.load_image('original') == IMAGE
Beispiel #56
0
    def test_edit(self):
        self.make_team(slug='enterprise', is_approved=True)
        edit_data = {
            'name': 'Enterprise',
            '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',
            'image': FileUpload(IMAGE, 'logo.png'),
        }
        data = json.loads(
            self.client.POST('/enterprise/edit/edit.json',
                             data=edit_data,
                             auth_as='picard').body)

        team = Team.from_slug('enterprise')
        assert data == team.to_dict()

        assert team.name == 'Enterprise'
        assert team.product_or_service == 'We save galaxies.'
        assert team.homepage == 'http://starwars-enterprise.com/'
        assert team.onboarding_url == 'http://starwars-enterprise.com/onboarding'
        assert team.todo_url == 'http://starwars-enterprise.com/todos'
        assert team.load_image('original') == IMAGE
Beispiel #57
0
 def test_can_construct_from_slug(self):
     self.make_team()
     team = Team.from_slug('TheATeam')
     assert team.name == 'The A Team'
     assert team.owner == 'hannibal'
Beispiel #58
0
 def test_can_construct_from_id(self):
     team = Team.from_id(self.make_team().id)
     assert team.name == 'The A Team'
     assert team.owner == 'hannibal'
Beispiel #59
0
from gratipay.wireup import db, env
from gratipay.models.team import Team, AlreadyMigrated

db = db(env())

slugs = db.all("""
    SELECT slug
      FROM teams
     WHERE is_approved IS TRUE
""")

for slug in slugs:
    team = Team.from_slug(slug)
    try:
        ntips = team.migrate_tips()
        print("Migrated {} tip(s) for '{}'".format(ntips, slug))
    except AlreadyMigrated:
        print("'%s' already migrated." % slug)

print("Done.")