From 76bdd5281df35ac9147e85a1733eef1bf7a9eccc Mon Sep 17 00:00:00 2001 From: Fernando Cancellara Date: Thu, 12 Jul 2018 01:54:32 -0300 Subject: [PATCH] Adding mPublicationDate to stories --- src/appserver/time/Time.py | 4 ++++ src/appserver/transformer/MobileTransformer.py | 5 ++++- src/tests/app/StoryTests.py | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/appserver/time/Time.py b/src/appserver/time/Time.py index 9a47076..f5bf8a8 100644 --- a/src/appserver/time/Time.py +++ b/src/appserver/time/Time.py @@ -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) diff --git a/src/appserver/transformer/MobileTransformer.py b/src/appserver/transformer/MobileTransformer.py index 8e2356a..8d91679 100644 --- a/src/appserver/transformer/MobileTransformer.py +++ b/src/appserver/transformer/MobileTransformer.py @@ -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') @@ -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 diff --git a/src/tests/app/StoryTests.py b/src/tests/app/StoryTests.py index 021e300..f806aa0 100644 --- a/src/tests/app/StoryTests.py +++ b/src/tests/app/StoryTests.py @@ -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): @@ -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() @@ -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): @@ -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) @@ -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'])