Changeset 7dc1f81 in OpenWorkouts-current


Ignore:
Timestamp:
Feb 17, 2019, 6:25:52 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
bfbf428
Parents:
23b5569
Message:

Better str and repr representation for the User model.

This is basically useful for developers using pshell for debugging
purposes, as adding the email address to the repr makes easier
(faster) to spot who a given user object is.

Location:
ow
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ow/models/user.py

    r23b5569 r7dc1f81  
    4242
    4343    def __str__(self):
    44         return u'User: %s (%s)' % (self.email, self.uid)
     44        return u'User: %s (%s)' % (self.uid, self.email)
     45
     46    def __repr__(self):
     47        return u'<%s.%s: %s (%s)>' % (
     48            self.__class__.__module__,
     49            self.__class__.__name__,
     50            self.uid, self.email
     51        )
    4552
    4653    @property
  • ow/tests/models/test_user.py

    r23b5569 r7dc1f81  
    4343        email = root['john'].email
    4444        uid = str(root['john'].uid)
    45         assert root['john'].__str__() == u'User: ' + email + ' (' + uid + ')'
     45        assert root['john'].__str__() == u'User: ' + uid + ' (' + email + ')'
     46
     47    def test__repr__(self, root):
     48        email = root['john'].email
     49        uid = str(root['john'].uid)
     50        expected = u'<ow.models.user.User: ' + uid + ' (' + email + ')>'
     51        assert root['john'].__repr__() == expected
    4652
    4753    def test_fullname(self, root):
Note: See TracChangeset for help on using the changeset viewer.