<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals

import pickle
from gratipay.testing import BrowserHarness, P
from gratipay.models.package import NPM, Package
from gratipay.models.participant import email


class Test(BrowserHarness):

    def check(self, choice=0):
        self.make_participant('alice', claimed_time='now')
        self.sign_in('alice')
        self.visit('/on/npm/foo/')
        self.css('label')[0].click() # activate select
        self.css('label')[choice].click()
        self.css('button')[0].click()
        address = ('alice' if choice == 0 else 'bob') + '@example.com'
        assert self.wait_for_success() == 'Check {} for a verification link.'.format(address)
        return self.db.one('select address from claims c join emails e on c.nonce = e.nonce')

    def finish_claiming(self):
        alice = P('alice')
        nonce = alice.get_email('<EMAIL>').nonce
        return alice.finish_email_verification('<EMAIL>', nonce)


    def test_appears_to_work(self):
        self.make_package()
        assert self.check() == '<EMAIL>'

    def test_works_when_there_are_multiple_addresses(self):
        self.make_package(emails=['<EMAIL>', '<EMAIL>'])
        assert self.check() == '<EMAIL>'

    def test_can_send_to_second_email(self):
        self.make_package(emails=['<EMAIL>', '<EMAIL>'])
        assert self.check(choice=1) == '<EMAIL>'

    def test_disabled_items_are_disabled(self):
        self.make_package(emails=['<EMAIL>', '<EMAIL>'])
        alice = self.make_participant('alice', claimed_time='now')
        self.add_and_verify_email(alice, '<EMAIL>', '<EMAIL>')
        self.sign_in('alice')
        self.visit('/on/npm/foo/')
        self.css('label')[0].click()            # activate select
        self.css('label')[1].click()            # click second item
        self.css('li')[0].has_class('selected') # first item is still selected
        self.css('ul')[0].has_class('open')     # still open
        self.css('button').has_class('disabled')
        assert self.db.all('select * from claims') == []


    def test_claimed_packages_can_be_given_to(self):
        package = self.make_package()
        self.check()
        self.finish_claiming()

        self.make_participant('admin', claimed_time='now', is_admin=True)
        self.sign_in('admin')
        self.visit(package.team.url_path)
        self.css('#status-knob select').select('approved')
        self.css('#status-knob button').click()

        self.make_participant('bob', claimed_time='now')
        self.sign_in('bob')
        self.visit('/on/npm/foo/')

        self.css('.your-payment button.edit').click()
        self.wait_for('.your-payment input.amount').fill('10')
        self.css('.your-payment button.save').click()
        assert self.wait_for_success() == 'Payment changed to $10.00 per week. ' \
                                          'Thank you so much for supporting foo!'

<commit_msg>Scope ttw tests to #content<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals

import pickle
from gratipay.testing import BrowserHarness, P
from gratipay.models.package import NPM, Package
from gratipay.models.participant import email


class Test(BrowserHarness):

    def check(self, choice=0):
        self.make_participant('alice', claimed_time='now')
        self.sign_in('alice')
        self.visit('/on/npm/foo/')
        self.css('#content label')[0].click() # activate select
        self.css('#content label')[choice].click()
        self.css('#content button')[0].click()
        address = ('alice' if choice == 0 else 'bob') + '@example.com'
        assert self.wait_for_success() == 'Check {} for a verification link.'.format(address)
        return self.db.one('select address from claims c join emails e on c.nonce = e.nonce')

    def finish_claiming(self):
        alice = P('alice')
        nonce = alice.get_email('<EMAIL>').nonce
        return alice.finish_email_verification('<EMAIL>', nonce)


    def test_appears_to_work(self):
        self.make_package()
        assert self.check() == '<EMAIL>'

    def test_works_when_there_are_multiple_addresses(self):
        self.make_package(emails=['<EMAIL>', '<EMAIL>'])
        assert self.check() == '<EMAIL>'

    def test_can_send_to_second_email(self):
        self.make_package(emails=['<EMAIL>', '<EMAIL>'])
        assert self.check(choice=1) == '<EMAIL>'

    def test_disabled_items_are_disabled(self):
        self.make_package(emails=['<EMAIL>', '<EMAIL>'])
        alice = self.make_participant('alice', claimed_time='now')
        self.add_and_verify_email(alice, '<EMAIL>', '<EMAIL>')
        self.sign_in('alice')
        self.visit('/on/npm/foo/')
        self.css('#content label')[0].click()            # activate select
        self.css('#content label')[1].click()            # click second item
        self.css('#content li')[0].has_class('selected') # first item is still selected
        self.css('#content ul')[0].has_class('open')     # still open
        self.css('#content button').has_class('disabled')
        assert self.db.all('select * from claims') == []


    def test_claimed_packages_can_be_given_to(self):
        package = self.make_package()
        self.check()
        self.finish_claiming()

        self.make_participant('admin', claimed_time='now', is_admin=True)
        self.sign_in('admin')
        self.visit(package.team.url_path)
        self.css('#status-knob select').select('approved')
        self.css('#status-knob button').click()

        self.make_participant('bob', claimed_time='now')
        self.sign_in('bob')
        self.visit('/on/npm/foo/')

        self.css('.your-payment button.edit').click()
        self.wait_for('.your-payment input.amount').fill('10')
        self.css('.your-payment button.save').click()
        assert self.wait_for_success() == 'Payment changed to $10.00 per week. ' \
                                          'Thank you so much for supporting foo!'


{'fraction_non_alphanumeric': 0.15489487516425757, 'fraction_numerical': 0.005256241787122208, 'mean_word_length': 2.9719504240052186, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7230005', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1855, 'n_words': 350}