def test_idempotent(self): alice = TwitterAccount(self.db, 1, dict(screen_name='alice')) bob = GitHubAccount(self.db, 2, dict(screen_name='bob')) alice_participant = alice.opt_in('alice')[0].participant alice_participant.take_over(bob, have_confirmation=True) alice_participant.take_over(bob, have_confirmation=True) self.db.self_check()
def test_cross_tip_doesnt_become_self_tip(self): alice = TwitterAccount(self.db, 1, dict(screen_name='alice')) bob = TwitterAccount(self.db, 2, dict(screen_name='bob')) alice_participant = alice.opt_in('alice')[0].participant bob_participant = bob.opt_in('bob')[0].participant alice_participant.set_tip_to('bob', '1.00') bob_participant.take_over(alice, have_confirmation=True) self.db.self_check()
def test_get_participant_gets_participant(self): expected = TwitterAccount(self.db, "alice", {}).opt_in("alice")[0].participant request = load_request(b'/alice/') actual = utils.get_participant(request, restrict=False) assert actual == expected
def setUp(self): super(Harness, self).setUp() now = utcnow() for idx, username in enumerate(['alice', 'bob', 'carl'], start=1): self.make_participant(username, claimed_time=now) twitter_account = TwitterAccount(idx, {'screen_name': username}) Participant(username).take_over(twitter_account)
def test_do_not_take_over_zero_tips_receiving(self): alice = TwitterAccount(self.db, 1, dict(screen_name='alice')) bob = TwitterAccount(self.db, 2, dict(screen_name='bob')) carl = TwitterAccount(self.db, 3, dict(screen_name='carl')) alice_participant = alice.opt_in('alice')[0].participant bob_participant = bob.opt_in('bob')[0].participant carl_participant = carl.opt_in('carl')[0].participant bob_participant.set_tip_to('carl', '1.00') bob_participant.set_tip_to('carl', '0.00') alice_participant.take_over(carl, have_confirmation=True) ntips = self.db.one("select count(*) from tips") assert 2 == ntips self.self_test()
def test_get_participant_canonicalizes(self): expected, ignored = TwitterAccount("alice", {}).opt_in("alice") request = load_request('/Alice/') with self.assertRaises(Response) as cm: utils.get_participant(request, restrict=False) actual = cm.exception.code assert actual == 302, actual
def test_homepage_with_anonymous_giver(self): TwitterAccount("bob", {}).opt_in("bob") alice = self.make_participant('alice', anonymous=True, last_bill_result='') alice.set_tip_to('bob', 1) update_homepage_queries_once(self.db) actual = self.client.get('/').body expected = "???" assert expected in actual, actual
def setUp(self): super(Harness, self).setUp() now = utcnow() hour_ago = now - datetime.timedelta(hours=1) for username in ['alice', 'bob', 'carl']: self.make_participant(username, claimed_time=hour_ago, last_bill_result='') deadbeef = TwitterAccount('1', {'screen_name': 'deadbeef'}) self.deadbeef_original_username = deadbeef.participant Participant('carl').set_tip_to('bob', '1.00') Participant('alice').set_tip_to(self.deadbeef_original_username, '1.00') Participant('bob').take_over(deadbeef, have_confirmation=True)
def test_cross_tip_doesnt_become_self_tip(self): alice = TwitterAccount(self.db, 1, dict(screen_name='alice')) bob = TwitterAccount(self.db, 2, dict(screen_name='bob')) alice_participant = alice.opt_in('alice')[0].participant bob_participant = bob.opt_in('bob')[0].participant alice_participant.set_tip_to('bob', '1.00') bob_participant.take_over(alice, have_confirmation=True) self.self_test()
def hit_anonymous(self, method='GET', expected_code=200): user, ignored = TwitterAccount('alice', {}).opt_in('alice') client = TestClient() response = client.get('/') csrf_token = response.request.context['csrf_token'] if method == 'GET': response = client.get("/alice/anonymous.json", user='******') else: assert method == 'POST' response = client.post("/alice/anonymous.json", {'csrf_token': csrf_token}, user='******') if response.code != expected_code: print(response.body) return response
def test_associate_confirms_on_connect(self, track, get, post): TwitterAccount('1234', {'screen_name': 'alice'}).opt_in('alice') self.make_participant('bob') self.website.oauth_cache = {"deadbeef": ("deadbeef", "connect", "")} post.return_value.status_code = 200 post.return_value.text = "oauth_token=foo&oauth_token_secret=foo&user_id=foo" get.return_value.status_code = 200 get.return_value.text = '{"id": 1234, "screen_name": "alice"}' self.client.get('/') # populates cookies['csrf_token'] response = self.client.get( "/on/twitter/associate?oauth_token=deadbeef&" "oauth_verifier=donald_trump", user="******") assert "Please Confirm" in response.body, response.body
def test_do_not_take_over_zero_tips_receiving(self): alice = TwitterAccount(self.db, 1, dict(screen_name='alice')) bob = TwitterAccount(self.db, 2, dict(screen_name='bob')) carl = TwitterAccount(self.db, 3, dict(screen_name='carl')) alice_participant = alice.opt_in('alice')[0].participant bob_participant = bob.opt_in('bob')[0].participant carl_participant = carl.opt_in('carl')[0].participant bob_participant.set_tip_to('carl', '1.00') bob_participant.set_tip_to('carl', '0.00') alice_participant.take_over(carl, have_confirmation=True) ntips = self.db.one("select count(*) from tips") assert 2 == ntips self.db.self_check()
def test_can_post_to_take_over(self): TwitterAccount('1234', {'screen_name': 'alice'}).opt_in('alice') self.make_participant('bob') self.website.connect_tokens = {("bob", "twitter", "1234"): "deadbeef"} csrf_token = self.client.get('/').request.context['csrf_token'] response = self.client.post("/on/take-over.html", data={ "platform": "twitter", "user_id": "1234", "csrf_token": csrf_token, "connect_token": "deadbeef", "should_reconnect": "yes" }, user="******") assert response.code == 302, response.body expected = '/about/me.html' actual = response.headers['Location'] assert actual == expected
def test_confirmation_properly_displays_remaining_bitbucket( self, track, get, post): alice, foo = TwitterAccount('1234', { 'screen_name': 'alice' }).opt_in('alice') alice.participant.take_over( BitbucketAccount('1234', {'username': '******'})) self.make_participant('bob') self.website.oauth_cache = {"deadbeef": ("deadbeef", "connect", "")} post.return_value.status_code = 200 post.return_value.text = "oauth_token=foo&oauth_token_secret=foo&user_id=foo" get.return_value.status_code = 200 get.return_value.text = '{"id": 1234, "screen_name": "alice"}' self.client.get('/') # populates cookies['csrf_token'] response = self.client.get( "/on/twitter/associate?oauth_token=deadbeef&" "oauth_verifier=donald_trump", user="******") assert response.body.count("alice_bb<br />") == 2, response.body
def test_ru_returns_twitter_url_for_stub_from_twitter(self): unclaimed = TwitterAccount('1234', {'screen_name': 'alice'}) stub = Participant.from_username(unclaimed.participant) actual = stub.resolve_unclaimed() assert actual == "/on/twitter/alice/"
def test_opt_in_doesnt_have_to_change_username(self): self.make_participant("bob") account = TwitterAccount("alice", {}) expected = account.participant # A random one. actual = account.opt_in("bob")[0].participant.username assert actual == expected
def test_opt_in_can_change_username(self): account = TwitterAccount("alice", {}) expected = "bob" actual = account.opt_in("bob")[0].participant.username assert actual == expected
def test_opt_in_doesnt_have_to_change_username(self): self.make_participant("bob") account = TwitterAccount("alice", {}) expected = account.participant # A random one. actual = account.opt_in("bob")[0].participant.username assert actual == expected, actual
def test_opt_in_can_change_username(self): account = TwitterAccount("alice", {}) expected = "bob" actual = account.opt_in("bob")[0].participant.username assert actual == expected, actual
def test_opt_in_can_changes_username(self): account = TwitterAccount("alice", {}) expected = "bob" actual = account.opt_in("bob").id assert actual == expected, actual