Skip to content

Commit 2d5653d

Browse files
author
Cameron Brandon White
committed
Merge pull request #18 from cameronbwhite/master
(gh-8) gravatar
2 parents 32dfc79 + e750c4c commit 2d5653d

File tree

7 files changed

+90
-7
lines changed

7 files changed

+90
-7
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ install:
66
- pip install -r requirements.txt
77
- pip install FreezeGun
88
# command to run tests
9-
script: nosetests --with-doctest
9+
script: nosetests --with-doctest -v
1010
notifications:
1111
irc: "irc.cat.pdx.edu#acm-dev"

acmapi/fields.py

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def output(self, obj, key):
8585
'name': String,
8686
'email': String,
8787
'website': String,
88+
'gravatar_email': String,
89+
'gravatar_id': String,
90+
'avatar_url': String,
8891
}
8992

9093
membership_fields = {

acmapi/models.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from passlib.apps import custom_app_context as pwd_context
33

44
import datetime
5+
import hashlib
56

67
DB = SQLAlchemy()
78

@@ -98,6 +99,9 @@ class Person(DB.Model):
9899
email = DB.Column(DB.Unicode)
99100
website = DB.Column(DB.Unicode)
100101
password_hash = DB.Column(DB.String)
102+
gravatar_email = DB.Column(DB.Unicode)
103+
gravatar_id = DB.Column(DB.Unicode)
104+
avatar_url = DB.Column(DB.Unicode)
101105

102106
memberships = DB.relationship(
103107
'Membership',
@@ -124,14 +128,17 @@ class Person(DB.Model):
124128
)
125129

126130
@classmethod
127-
def create(cls, name, username, email, website, password):
131+
def create(cls, name, username, email, website, password,
132+
gravatar_email=None):
128133

129134
x = cls()
130135
x.name = name
131136
x.username = username
132137
x.email = email
133138
x.website = website
134139
x.password = x.hash_password(password)
140+
if gravatar_email:
141+
x.set_gravatar_email(gravatar_email)
135142
return x
136143

137144
def __repr__(self):
@@ -151,6 +158,12 @@ def isCurrentOfficer(self):
151158
return True
152159
return False
153160

161+
def set_gravatar_email(self, new_email):
162+
self.gravatar_email = new_email
163+
self.gravatar_id = hashlib.md5(self.gravatar_email).hexdigest()
164+
self.gravatar_url = 'http://www.gravatar.com/avatar/{}'.format(
165+
self.gravatar_id)
166+
154167
class Officership(DB.Model):
155168

156169
__tablename__ = "officerships"

acmapi/resources.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ def post(self):
351351
parser.add_argument('email', type=str)
352352
parser.add_argument('website', type=str)
353353
parser.add_argument('password', type=str, required=True)
354+
parser.add_argument('gravatar_email', type=str)
354355

355356
args = parser.parse_args()
356357

@@ -359,7 +360,8 @@ def post(self):
359360
name = args.name,
360361
email = args.email,
361362
website = args.website,
362-
password = args.password)
363+
password = args.password,
364+
gravatar_email = args.gravatar_email)
363365

364366
DB.session.add(person)
365367

@@ -384,6 +386,7 @@ def put(self, person_id=None, username=None):
384386
parser.add_argument('email', type=str)
385387
parser.add_argument('website', type=str)
386388
parser.add_argument('password', type=str)
389+
parser.add_argument('gravatar_email', type=str)
387390

388391
args = parser.parse_args()
389392

@@ -410,6 +413,8 @@ def put(self, person_id=None, username=None):
410413
person.website = args.website
411414
if args.password:
412415
person.password_hash = person.hash_password(args.password)
416+
if args.gravatar_email:
417+
person.set_gravatar_email(args.gravatar_email)
413418

414419
try:
415420
DB.session.commit()

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
if __name__ == "__main__":
1414
setuptools.setup(
1515
name="acmapi",
16-
version="0.1.0",
16+
version="0.2.1",
1717
description="",
1818
author="Cameron Brandon White",
1919
author_email="[email protected]",

tests/test_fields.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def test_person_fields(self):
8686
dict(marshal(person, person_fields)),
8787
{"id": 1, "username": u"johnd", "email":
8888
u"[email protected]", "website":
89-
u"http://johnd.com", 'name': u'John Doe'})
89+
u"http://johnd.com", 'name': u'John Doe',
90+
"gravatar_email": None, "gravatar_id": None,
91+
"avatar_url": None})
9092

9193
def test_event_fields(self):
9294

tests/test_resources/test_people_resource.py

+62-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131

3232
class test_people_resource(unittest.TestCase):
3333

34+
3435
@freeze_time("2012-01-14 12:00:01")
3536
def setUp(self):
3637

38+
self.maxDiff = None
39+
3740
self.app = acmapi.create_app(SQLALCHEMY_DATABASE_URI='sqlite://')
3841
self.app.testing = True
3942

@@ -83,6 +86,9 @@ def test_add_unique_person(self):
8386
'name': 'Bob Billy',
8487
'email': '[email protected]',
8588
'website': 'http://bbob.example.com',
89+
'gravatar_email': None,
90+
'gravatar_id': None,
91+
'avatar_url': None,
8692
})
8793

8894
@freeze_time("2012-01-14 12:00:01")
@@ -143,6 +149,9 @@ def test_find_existing_person_by_id(self):
143149
'name': 'Bob Billy',
144150
'email': '[email protected]',
145151
'website': 'http://bbob.example.com',
152+
'gravatar_email': None,
153+
'gravatar_id': None,
154+
'avatar_url': None,
146155
})
147156

148157
@freeze_time("2012-01-14 12:00:01")
@@ -171,6 +180,9 @@ def test_find_existing_person_by_username(self):
171180
'name': 'Bob Billy',
172181
'email': '[email protected]',
173182
'website': 'http://bbob.example.com',
183+
'gravatar_email': None,
184+
'gravatar_id': None,
185+
'avatar_url': None,
174186
})
175187

176188
@freeze_time("2012-01-14 12:00:01")
@@ -217,6 +229,9 @@ def test_list_everything_0(self):
217229
'name': None,
218230
'email': None,
219231
'website': None,
232+
'gravatar_email': None,
233+
'gravatar_id': None,
234+
'avatar_url': None,
220235
}])
221236

222237
@freeze_time("2012-01-14 12:00:01")
@@ -245,13 +260,19 @@ def test_list_everything_1(self):
245260
'name': None,
246261
'email': None,
247262
'website': None,
263+
'gravatar_email': None,
264+
'gravatar_id': None,
265+
'avatar_url': None,
248266
},
249267
{
250268
'id': 2,
251269
'username': 'bob',
252270
'name': 'Bob Billy',
253271
'email': '[email protected]',
254272
'website': 'http://bbob.example.com',
273+
'gravatar_email': None,
274+
'gravatar_id': None,
275+
'avatar_url': None,
255276
}])
256277

257278
@freeze_time("2012-01-14 12:00:01")
@@ -291,20 +312,29 @@ def test_list_everything_2(self):
291312
'name': None,
292313
'email': None,
293314
'website': None,
315+
'gravatar_email': None,
316+
'gravatar_id': None,
317+
'avatar_url': None,
294318
},
295319
{
296320
'id': 2,
297321
'username': 'bob',
298322
'name': 'Bob Billy',
299323
'email': '[email protected]',
300324
'website': 'http://bbob.example.com',
325+
'gravatar_email': None,
326+
'gravatar_id': None,
327+
'avatar_url': None,
301328
},
302329
{
303330
'id': 3,
304331
'username': 'foo',
305332
'name': 'Foo Bar',
306333
'email': '[email protected]',
307334
'website': 'http://foobar.example.com',
335+
'gravatar_email': None,
336+
'gravatar_id': None,
337+
'avatar_url': None,
308338
}])
309339

310340
@freeze_time("2012-01-14 12:00:01")
@@ -340,6 +370,9 @@ def test_delete_existing_by_id(self):
340370
'name': None,
341371
'email': None,
342372
'website': None,
373+
'gravatar_email': None,
374+
'gravatar_id': None,
375+
'avatar_url': None,
343376
}])
344377

345378
@freeze_time("2012-01-14 12:00:01")
@@ -375,6 +408,9 @@ def test_delete_existing_by_username(self):
375408
'name': None,
376409
'email': None,
377410
'website': None,
411+
'gravatar_email': None,
412+
'gravatar_id': None,
413+
'avatar_url': None,
378414
}])
379415

380416
@freeze_time("2012-01-14 12:00:01")
@@ -400,6 +436,9 @@ def test_delete_non_existing_by_id(self):
400436
'name': None,
401437
'email': None,
402438
'website': None,
439+
'gravatar_email': None,
440+
'gravatar_id': None,
441+
'avatar_url': None,
403442
}])
404443

405444
@freeze_time("2012-01-14 12:00:01")
@@ -425,6 +464,9 @@ def test_delete_non_existing_by_username(self):
425464
'name': None,
426465
'email': None,
427466
'website': None,
467+
'gravatar_email': None,
468+
'gravatar_id': None,
469+
'avatar_url': None,
428470
}])
429471

430472
@freeze_time("2012-01-14 12:00:01")
@@ -449,6 +491,9 @@ def test_invalid_delete(self):
449491
'name': None,
450492
'email': None,
451493
'website': None,
494+
'gravatar_email': None,
495+
'gravatar_id': None,
496+
'avatar_url': None,
452497
}])
453498

454499
@freeze_time("2012-01-14 12:00:01")
@@ -482,7 +527,11 @@ def test_update_existing_person_by_id(self):
482527
'id': 2,
483528
'name': 'Jim Billy',
484529
'username': 'bob',
485-
'website': 'http://jbob.example.com'})
530+
'website': 'http://jbob.example.com',
531+
'gravatar_email': None,
532+
'gravatar_id': None,
533+
'avatar_url': None,
534+
})
486535

487536

488537
response = client.get(
@@ -496,6 +545,9 @@ def test_update_existing_person_by_id(self):
496545
'name': 'Jim Billy',
497546
'email': '[email protected]',
498547
'website': 'http://jbob.example.com',
548+
'gravatar_email': None,
549+
'gravatar_id': None,
550+
'avatar_url': None,
499551
})
500552

501553
@freeze_time("2012-01-14 12:00:01")
@@ -529,7 +581,12 @@ def test_update_existing_person_by_username(self):
529581
'id': 2,
530582
'name': 'Jim Billy',
531583
'username': 'bob',
532-
'website': 'http://jbob.example.com'})
584+
'website': 'http://jbob.example.com',
585+
'gravatar_email': None,
586+
'gravatar_id': None,
587+
'avatar_url': None,
588+
})
589+
533590

534591
response = client.get(
535592
'http://localhost:5000/people/bob')
@@ -542,6 +599,9 @@ def test_update_existing_person_by_username(self):
542599
'name': 'Jim Billy',
543600
'email': '[email protected]',
544601
'website': 'http://jbob.example.com',
602+
'gravatar_email': None,
603+
'gravatar_id': None,
604+
'avatar_url': None,
545605
})
546606

547607
@freeze_time("2012-01-14 12:00:01")

0 commit comments

Comments
 (0)