This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0522511
commit fe6cc36
Showing
15 changed files
with
236 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from postgres.orm import Model | ||
|
||
|
||
NPM = 'npm' # We are starting with a single package manager. If we see | ||
# traction we will expand. | ||
|
||
|
||
class Package(Model): | ||
"""Represent a gratipackage. :-) | ||
""" | ||
|
||
typname = 'packages' | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, Package): | ||
return False | ||
return self.id == other.id | ||
|
||
def __ne__(self, other): | ||
if not isinstance(other, Package): | ||
return True | ||
return self.id != other.id | ||
|
||
|
||
# Constructors | ||
# ============ | ||
|
||
@classmethod | ||
def from_id(cls, id): | ||
"""Return an existing package based on id. | ||
""" | ||
return cls.db.one("SELECT packages.*::packages FROM packages WHERE id=%s", (id,)) | ||
|
||
@classmethod | ||
def from_names(cls, package_manager, name): | ||
"""Return an existing package based on package manager and package names. | ||
""" | ||
return cls.db.one("SELECT packages.*::packages FROM packages " | ||
"WHERE package_manager=%s and name=%s", (package_manager, name)) | ||
|
||
|
||
# Emails | ||
# ====== | ||
|
||
def send_confirmation_email(self, address): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,16 @@ def make_team(self, *a, **kw): | |
return team | ||
|
||
|
||
def make_package(self, package_manager='npm', name='foo', description='Foo', | ||
emails=['[email protected]']): | ||
"""Factory for packages. | ||
""" | ||
return self.db.one( 'INSERT INTO packages (package_manager, name, description, emails) ' | ||
'VALUES (%s, %s, %s, %s) RETURNING *' | ||
, (package_manager, name, description, emails) | ||
) | ||
|
||
|
||
def make_participant(self, username, **kw): | ||
"""Factory for :py:class:`~gratipay.models.participant.Participant`. | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Gratipay.packages = {}; | ||
|
||
Gratipay.packages.post = function(e) { | ||
e.preventDefault(); | ||
var $this = $(this); | ||
var action = 'add-email-and-claim-package'; | ||
var package_id = $('input[name=package_id]').val(); | ||
var email = $('input[name=email]:checked').val(); | ||
|
||
var $inputs = $('input, button'); | ||
$inputs.prop('disabled', true); | ||
|
||
$.ajax({ | ||
url: '/~' + Gratipay.username + '/emails/modify.json', | ||
type: 'POST', | ||
data: {action: action, address: email, package_id: package_id}, | ||
dataType: 'json', | ||
success: function (msg) { | ||
if (msg) { | ||
Gratipay.notification(msg, 'success'); | ||
} | ||
$inputs.prop('disabled', false); | ||
}, | ||
error: [ | ||
function () { $inputs.prop('disabled', false); }, | ||
Gratipay.error | ||
], | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
.sorry { | ||
text-align: center; | ||
font: normal 12px/15px $Ideal; | ||
color: $medium-gray; | ||
} | ||
|
||
table.listing { | ||
width: 100%; | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#package { | ||
.emails { | ||
margin: 1em 0; | ||
li { | ||
list-style: none; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from gratipay.models.package import NPM, Package | ||
from gratipay.testing import Harness | ||
|
||
|
||
class TestPackage(Harness): | ||
|
||
def test_can_be_instantiated_from_id(self): | ||
p = self.make_package() | ||
assert Package.from_id(p.id).id == p.id | ||
|
||
def test_can_be_instantiated_from_names(self): | ||
self.make_package() | ||
assert Package.from_names(NPM, 'foo').name == 'foo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from gratipay.models.package import NPM | ||
from gratipay.testing import Harness | ||
|
||
|
||
class TestClaimingWorkflow(Harness): | ||
|
||
def setUp(self): | ||
self.make_package() | ||
|
||
def test_anon_gets_signin_page_from_unclaimed(self): | ||
body = self.client.GET('/on/npm/foo/').body | ||
assert 'npm/foo</a> has not been claimed' in body | ||
assert 'with a couple clicks' in body | ||
|
||
def test_auth_gets_send_confirmation_page_from_unclaimed(self): | ||
self.make_participant('bob', claimed_time='now') | ||
body = self.client.GET('/on/npm/foo/', auth_as='bob').body | ||
assert 'npm/foo</a> has not been claimed' in body | ||
assert 'using any email address' in body | ||
assert '[email protected]' in body | ||
|
||
def test_auth_gets_multiple_options_if_present(self): | ||
self.make_package(NPM, 'bar', 'Bar', ['[email protected]', '[email protected]']) | ||
self.make_participant('bob', claimed_time='now') | ||
body = self.client.GET('/on/npm/bar/', auth_as='bob').body | ||
assert 'using any email address' in body | ||
assert '[email protected]' in body | ||
assert '[email protected]' in body | ||
|
||
def test_auth_gets_something_if_no_emails(self): | ||
self.make_package(NPM, 'bar', 'Bar', []) | ||
self.make_participant('bob', claimed_time='now') | ||
body = self.client.GET('/on/npm/bar/', auth_as='bob').body | ||
assert "didn't find any email addresses" in body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from gratipay.testing import BrowserHarness | ||
|
||
|
||
class TestSendConfirmationLink(BrowserHarness): | ||
|
||
def check(self, choice=0): | ||
self.make_participant('bob', claimed_time='now') | ||
self.sign_in('bob') | ||
self.visit('/on/npm/foo/') | ||
self.css('input[type=radio]')[choice].click() | ||
self.css('button')[0].click() | ||
assert self.has_element('.notification.notification-success', 1) | ||
assert self.has_text('Check [email protected] for a confirmation link.') | ||
|
||
def test_appears_to_work(self): | ||
self.make_package() | ||
self.check() | ||
|
||
def test_works_when_there_are_multiple_addresses(self): | ||
self.make_package(emails=['[email protected]', '[email protected]']) | ||
self.check() | ||
|
||
def test_can_send_to_second_email(self): | ||
self.make_package(emails=['[email protected]', '[email protected]']) | ||
self.check(choice=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters