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.
Merge pull request #4155 from gratipay/projects-elsewhere
Stub out Package model
- Loading branch information
Showing
6 changed files
with
69 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- 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)) |
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 |
---|---|---|
|
@@ -181,13 +181,14 @@ def make_team(self, *a, **kw): | |
return team | ||
|
||
|
||
def make_package(self, package_manager, name, description, emails): | ||
def make_package(self, package_manager='npm', name='foo', description='Foo', | ||
emails=['[email protected]']): | ||
"""Factory for packages. | ||
""" | ||
self.db.one( 'INSERT INTO packages (package_manager, name, description, emails) ' | ||
'VALUES (%s, %s, %s, %s) RETURNING *' | ||
, (package_manager, name, description, emails) | ||
) | ||
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): | ||
|
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
class TestAnon(Harness): | ||
|
||
def setUp(self): | ||
self.make_package('npm', 'foo', 'The foo package', ['[email protected]']) | ||
self.make_package() | ||
|
||
def test_gets_signin_page(self): | ||
assert 'npm/foo</a> has not been claimed' in self.client.GET('/on/npm/foo/').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