Skip to content

Commit

Permalink
Merge pull request #83 from taller2-2c2018/addDateToStories
Browse files Browse the repository at this point in the history
Adding mPublicationDate to stories
  • Loading branch information
fcancel authored Jul 12, 2018
2 parents 420046b + 76bdd52 commit 63a90ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/appserver/time/Time.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Time(object):
def now():
return datetime.now(pytz.timezone(zone='America/Argentina/Buenos_Aires'))

@staticmethod
def convert_time_argentina_time(date_time):
return date_time.astimezone(pytz.timezone("America/Argentina/Buenos_Aires"))

@staticmethod
def timedelta(hours):
return timedelta(hours=hours)
Expand Down
5 changes: 4 additions & 1 deletion src/appserver/transformer/MobileTransformer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from appserver.time.Time import Time

DEFAULT_IMAGE = os.environ.get('DEFAULT_IMAGE', 'https://firebasestorage.googleapis.com/v0/b/taller2-199117.appspot.com/o/default_image.jpeg?alt=media&token=d5147918-820e-44c6-8ef2-7ba3ef625891')
DEFAULT_IMAGE_TYPE = os.environ.get('DEFAULT_IMAGE_TYPE', 'jpeg')

Expand Down Expand Up @@ -36,7 +38,8 @@ def database_story_to_mobile(story):
'mProfilePicture': MobileTransformer.__optional_value(story, 'profile_picture', DEFAULT_IMAGE),
'mFileTypeProfilePicture': MobileTransformer.__optional_value(story, 'file_type_profile_picture', DEFAULT_IMAGE_TYPE),
'mFirstName': story['first_name'],
'mLastName': story['last_name']
'mLastName': story['last_name'],
'mPublicationDate': Time.convert_time_argentina_time(story['publication_date'])
}

@staticmethod
Expand Down
5 changes: 5 additions & 0 deletions src/tests/app/StoryTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_post_new_story(self):
self.assertEqual(story['file_type'], 'jpg')
self.assertEqual(story['location'], 'San Telmo, Buenos Aires')
self.assertEqual(story['total_friends'], 1)
self.assertTrue(story['publication_date'] is not None)
self.assertEqual(story['stories_posted_today'], 0)

def test_post_new_story_shared_server_gives_wrong_response(self):
Expand Down Expand Up @@ -213,6 +214,7 @@ def test_get_all_stories_for_requester_gets_permanent_story(self):
self.assertEqual(story['mFileTypeProfilePicture'], 'jpg')
self.assertTrue('mFirstName' in story)
self.assertTrue('mLastName' in story)
self.assertTrue(story['mPublicationDate'] is not None)

def test_get_all_stories_for_requester_with_no_facebook_user_id_in_header_gives_bad_request(self):
TestsCommons.create_default_user()
Expand Down Expand Up @@ -257,6 +259,7 @@ def test_get_all_stories_for_requester_gets_flash_story(self):
self.assertTrue('mProfilePictureId' in story)
self.assertTrue('mFirstName' in story)
self.assertTrue('mLastName' in story)
self.assertTrue(story['mPublicationDate'] is not None)

@patch('appserver.time.Time.Time.now', mock_time_now)
def test_get_all_stories_for_requester_gets_stories_ordered_by_relevance(self):
Expand Down Expand Up @@ -285,6 +288,7 @@ def test_get_all_stories_for_requester_gets_stories_ordered_by_relevance(self):
self.assertTrue('mProfilePictureId' in first_story)
self.assertTrue('mFirstName' in first_story)
self.assertTrue('mLastName' in first_story)
self.assertTrue(first_story['mPublicationDate'] is not None)

second_story = stories_list[1]
self.assertTrue(second_story['mStoryId'] is not None)
Expand All @@ -301,6 +305,7 @@ def test_get_all_stories_for_requester_gets_stories_ordered_by_relevance(self):
self.assertTrue('mProfilePictureId' in second_story)
self.assertTrue('mFirstName' in second_story)
self.assertTrue('mLastName' in second_story)
self.assertTrue(second_story['mPublicationDate'] is not None)

self.assertTrue(second_story['mRelevance'] < first_story['mRelevance'])

Expand Down

0 comments on commit 63a90ed

Please sign in to comment.