Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Refactor participant mixins
Browse files Browse the repository at this point in the history
Flat is better than nested.
  • Loading branch information
chadwhitacre committed Feb 20, 2017
1 parent 436475f commit 0cf5c2b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions gratipay/models/participant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from gratipay.models.exchange_route import ExchangeRoute
from gratipay.models.team import Team
from gratipay.models.team.mixins.takes import ZERO
from gratipay.models.participant import mixins
from gratipay.security.crypto import constant_time_compare
from gratipay.utils import (
i18n,
Expand All @@ -51,6 +50,7 @@
)
from gratipay.utils.username import safely_reserve_a_username

from .identity import Identity

ASCII_ALLOWED_IN_USERNAME = set("0123456789"
"abcdefghijklmnopqrstuvwxyz"
Expand All @@ -63,7 +63,7 @@
USERNAME_MAX_SIZE = 32


class Participant(Model, mixins.Identity):
class Participant(Model, Identity):
"""Represent a Gratipay participant.
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _validate_info(schema_name, info):
return None


class IdentityMixin(object):
class Identity(object):
"""This mixin provides management of national identities for
:py:class:`~gratipay.models.participant.Participant` objects.
Expand Down
3 changes: 0 additions & 3 deletions gratipay/models/participant/mixins/__init__.py

This file was deleted.

3 changes: 1 addition & 2 deletions gratipay/wireup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
from gratipay.models.community import Community
from gratipay.models.country import Country
from gratipay.models.exchange_route import ExchangeRoute
from gratipay.models.participant import Participant
from gratipay.models.participant.mixins import Identity
from gratipay.models.participant import Participant, Identity
from gratipay.models.team import Team
from gratipay.models import GratipayDB
from gratipay.security.crypto import EncryptingPacker
Expand Down
10 changes: 5 additions & 5 deletions tests/py/test_participant_identities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from cryptography.fernet import InvalidToken
from gratipay.testing import Harness, P
from gratipay.models.participant.mixins import identity, Identity
from gratipay.models.participant.mixins.identity import _validate_info, rekey
from gratipay.models.participant.mixins.identity import ParticipantIdentityInfoInvalid
from gratipay.models.participant.mixins.identity import ParticipantIdentitySchemaUnknown
from gratipay.models.participant import identity
from gratipay.models.participant.identity import _validate_info, rekey
from gratipay.models.participant.identity import ParticipantIdentityInfoInvalid
from gratipay.models.participant.identity import ParticipantIdentitySchemaUnknown
from gratipay.security.crypto import EncryptingPacker, Fernet
from postgres.orm import ReadOnly
from psycopg2 import IntegrityError
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_sii_validates_identity(self):
)

def test_sii_happily_overwrites_schema_name(self):
packed = Identity.encrypting_packer.pack({'name': 'Crusher'})
packed = identity.Identity.encrypting_packer.pack({'name': 'Crusher'})
self.db.run( "INSERT INTO participant_identities "
"(participant_id, country_id, schema_name, info) "
"VALUES (%s, %s, %s, %s)"
Expand Down
2 changes: 1 addition & 1 deletion tests/py/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from base64 import urlsafe_b64decode
from cryptography.fernet import Fernet, InvalidToken
from gratipay import security
from gratipay.models.participant.mixins import Identity
from gratipay.models.participant import Identity
from gratipay.security.crypto import EncryptingPacker
from gratipay.testing import Harness
from pytest import raises
Expand Down

0 comments on commit 0cf5c2b

Please sign in to comment.