Skip to content

Commit

Permalink
PEP8.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Jun 23, 2013
1 parent 63dc668 commit 71c7cb9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
29 changes: 15 additions & 14 deletions tahrir_api/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_person_email(self, person_id):

if self.person_exists(id=person_id):
return self.session.query(Person).filter_by(
id=person_id).one().email
id=person_id).one().email
return None

def get_person(self, person_email=None, id=None, nickname=None):
Expand Down Expand Up @@ -221,7 +221,7 @@ def issuer_exists(self, origin, name):
"""

return self.session.query(Issuer)\
.filter_by(origin=origin, name=name).count() != 0
.filter_by(origin=origin, name=name).count() != 0

def add_invitation(self, badge_id, created_on=None, expires_on=None,
created_by=None):
Expand All @@ -242,13 +242,12 @@ def add_invitation(self, badge_id, created_on=None, expires_on=None,
"""


if not self.badge_exists(badge_id):
raise ValueError("No such badge %r" % badge_id)

created_on = created_on or datetime.now()
expires_on = expires_on or (created_on + timedelta(hours=1))
created_by = created_by or "1" # This should be fine
created_by = created_by or "1" # This should be fine

invitation = Invitation(
created_on=created_on,
Expand All @@ -269,7 +268,7 @@ def invitation_exists(self, invitation_id):
"""

return self.session.query(Invitation)\
.filter_by(id=invitation_id).count() != 0
.filter_by(id=invitation_id).count() != 0

def get_issuer(self, issuer_id):
"""
Expand Down Expand Up @@ -318,17 +317,17 @@ def add_issuer(self, origin, name, org, contact):

if not self.issuer_exists(origin, name):
new_issuer = Issuer(
origin=origin,
name=name,
org=org,
contact=contact
)
origin=origin,
name=name,
org=org,
contact=contact
)
self.session.add(new_issuer)
self.session.commit()
return new_issuer.id

return self.session.query(Issuer)\
.filter_by(name=name, origin=origin).one().id
.filter_by(name=name, origin=origin).one().id

def get_all_assertions(self):
"""
Expand All @@ -347,9 +346,9 @@ def get_assertions_by_email(self, person_email):

if self.person_exists(email=person_email):
person_id = self.session.query(Person).filter_by(
email=person_email).one().id
email=person_email).one().id
return self.session.query(Assertion).filter_by(
person_id=person_id).all()
person_id=person_id).all()
else:
return False

Expand All @@ -365,10 +364,12 @@ def assertion_exists(self, badge_id, email):
"""

person = self.get_person(email)

if not person:
return False

return self.session.query(Assertion).filter_by(
person_id=person.id, badge_id=badge_id).count() != 0
person_id=person.id, badge_id=badge_id).count() != 0

def add_assertion(self, badge_id, person_email, issued_on):
"""
Expand Down
2 changes: 1 addition & 1 deletion tahrir_api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Invitation(DeclarativeBase):
expires_on = Column(DateTime, nullable=False)
badge_id = Column(Unicode(128), ForeignKey('badges.id'), nullable=False)
created_by = Column(Unicode(128), ForeignKey('persons.id'),
nullable=False)
nullable=False)

@property
def expired(self):
Expand Down
12 changes: 8 additions & 4 deletions tests/test_dbai.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@

try:
from subprocess import check_output as _check_output

def check_output(cmd):
try:
return _check_output(cmd)
except:
return None
except:
import subprocess

def check_output(cmd):
try:
return subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
return subprocess.Popen(
cmd, stdout=subprocess.PIPE).communicate()[0]
except:
return None


class TestDBInit(object):

def setUp(self):
Expand All @@ -40,11 +44,11 @@ def test_AddBadges(self):
1337
)

assert self.api.badge_exists("testbadge") == True
assert self.api.badge_exists("testbadge") is True

def test_AddPerson(self):
self.api.add_person("test@tester.com")
assert self.api.person_exists("test@tester.com") == True
assert self.api.person_exists("test@tester.com") is True

def test_AddIssuer(self):
_id = self.api.add_issuer(
Expand All @@ -53,7 +57,7 @@ def test_AddIssuer(self):
"TestOrg",
"TestContact"
)
assert self.api.issuer_exists("TestOrigin", "TestName") == True
assert self.api.issuer_exists("TestOrigin", "TestName") is True

def test_addInvitation(self):
badge_id = self.api.add_badge(
Expand Down

0 comments on commit 71c7cb9

Please sign in to comment.