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
Stub out Package model #4155
Merged
Merged
Stub out Package model #4155
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
edfa226
Add team reference to pacakges.
aandis 490adfa
Add package model init.
aandis be9dd15
Add Package model
aandis 049e32f
Update insert columns. Cleanup
aandis b92e076
Dummy payment instruction method.
aandis 47c1c45
Stub out a test file
chadwhitacre fb6f9a6
Add defaults to make_package in test harness
chadwhitacre 9a53034
Clean up Package instantiation
chadwhitacre 2b40ed0
Prune stubbed out code
chadwhitacre a72e900
Smoke 'em if ya got 'em? :-)
chadwhitacre 9c05276
Use constant instead of string literal for 'npm'
chadwhitacre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Not sure how helpful it would be though.