-
Notifications
You must be signed in to change notification settings - Fork 308
Stub out Package model #4155
Stub out Package model #4155
Changes from 9 commits
edfa226
490adfa
be9dd15
049e32f
b92e076
47c1c45
fb6f9a6
9a53034
2b40ed0
a72e900
9c05276
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from postgres.orm import Model | ||
|
||
|
||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there plan to create table for package manager and reference its id in packages table? Before making that change, shall we make 'npm' a constant shared across the app to avoid issue with raw string? Like using "Npm" by mistake, etc. Or maybe, we use API from_name(cls, name) before adding support for other package managers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not before May. We won't look at expanding beyond npm until later this year or possibly next.
Like 9c05276? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. Not sure how helpful it would be though. |
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): | ||
|
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 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' |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😀