def test_converting_custom_timezone(self): """Test converting timestamp with custom timezone.""" timestamp = datetime.datetime(2019, 1, 15, 12, 00, 00) result = data_handlers.as_user_time( timestamp, datetime_tz=pytz.timezone("US/Eastern") ) self.assertEqual(result, "01/15/2019 07:00:00 EST")
def test_converting_custom_format(self): """Test converting timestamp with custom format.""" timestamp = datetime.datetime(2019, 1, 15, 12, 00, 00) result = data_handlers.as_user_time( timestamp, datetime_format="%m/%d/%Y %I:%M:%S %p %z" ) self.assertEqual(result, "01/15/2019 04:00:00 AM -0800")
def test_converting_custom_format(self): """Test converting timestamp with custom format.""" timestamp = datetime.datetime(2019, 1, 15, 12, 00, 00) result = data_handlers.as_user_time( timestamp, datetime_format="%m/%d/%Y %I:%M:%S %p %z" ) self.assertEqual(result, "01/15/2019 04:00:00 AM -0800")
def test_converting_custom_timezone(self): """Test converting timestamp with custom timezone.""" timestamp = datetime.datetime(2019, 1, 15, 12, 00, 00) result = data_handlers.as_user_time( timestamp, datetime_tz=pytz.timezone("US/Eastern") ) self.assertEqual(result, "01/15/2019 07:00:00 EST")
def test_converting_formatter(self): """Test converting timestamp with additional formatter function.""" timestamp = datetime.datetime(2019, 1, 15, 12, 00, 00) result = data_handlers.as_user_time( timestamp, datetime_format="%m/%d/%Y %I:%M:%S %p %z", formatter="Timestamp {}".format, ) self.assertEqual(result, "Timestamp 01/15/2019 04:00:00 AM -0800")
def test_converting_formatter(self): """Test converting timestamp with additional formatter function.""" timestamp = datetime.datetime(2019, 1, 15, 12, 00, 00) result = data_handlers.as_user_time( timestamp, datetime_format="%m/%d/%Y %I:%M:%S %p %z", formatter="Timestamp {}".format, ) self.assertEqual(result, "Timestamp 01/15/2019 04:00:00 AM -0800")
def _generate_mention_email(object_name, comments_data): """Generate title and body of the email. Params: object_name: name of the object in which person was mentioned, comments_data: a set of CommentData named tuples. Returns: title: email title body: email body """ # The only way to pass the list of different comments here - is via import. # All comments created via import are authored by one user. This is why # it is safe to use any author in the email title. author = next(iter(comments_data)).author title = u"{author} mentioned you on a comment within {object_name}".format( author=author, object_name=object_name, ) body_template = ( u"{author} mentioned you on a comment within {object_name} " u"at {created_at}:\n" u"{comment_text}\n" ) body = [] for comment in sorted(comments_data): body.append(body_template.format( author=comment.author, object_name=object_name, created_at=data_handlers.as_user_time(comment.created_at), comment_text=comment.comment_text, )) return title, body
def test_converting_non_dst_timestamp(self): """Test converting timestamps in non-daylight saving time part of the year. """ timestamp = datetime(2017, 2, 13, 15, 40, 37) result = data_handlers.as_user_time(timestamp) self.assertEqual(result, "02/13/2017 07:40:37 PST")
def test_converting_dst_timestamp(self): """Test converting timestamps in daylight saving time part of the year.""" timestamp = datetime(2017, 6, 13, 15, 40, 37) result = as_user_time(timestamp) self.assertEqual(result, "06/13/2017 08:40:37 PDT")
def build_subject(): """Build notification subject.""" user_datetime = data_handlers.as_user_time(datetime.utcnow(), ) return common.prefix_subject(DIGEST_TITLE_TMPL.format(user_datetime))
def test_converting_non_dst_timestamp(self): """Test converting timestamps in non-daylight saving time part of the year. """ timestamp = datetime(2017, 2, 13, 15, 40, 37) result = as_user_time(timestamp) self.assertEqual(result, "02/13/2017 07:40:37 PST")
def test_converting_dst_timestamp(self): """Test converting timestamps in daylight saving time part of the year.""" timestamp = datetime.datetime(2017, 6, 13, 15, 40, 37) result = data_handlers.as_user_time(timestamp) self.assertEqual(result, "06/13/2017 08:40:37 PDT")
def build_subject(): """Build notification subject.""" user_datetime = data_handlers.as_user_time( datetime.utcnow(), ) return common.prefix_subject(DIGEST_TITLE_TMPL.format(user_datetime))