|
4 | 4 | from stream.exceptions import ApiKeyException, InputException |
5 | 5 | import random |
6 | 6 | import jwt |
| 7 | +import pytz |
7 | 8 |
|
8 | 9 | try: |
9 | 10 | from unittest.case import TestCase |
@@ -831,7 +832,7 @@ def test_uniqueness(self): |
831 | 832 | b.) The same time and foreign id |
832 | 833 | """ |
833 | 834 |
|
834 | | - utcnow = datetime.datetime.utcnow() |
| 835 | + utcnow = datetime.datetime.now(tz=pytz.utc) |
835 | 836 | activity_data = {"actor": 1, "verb": "tweet", "object": 1, "time": utcnow} |
836 | 837 | self.user1.add_activity(activity_data) |
837 | 838 | self.user1.add_activity(activity_data) |
@@ -869,7 +870,7 @@ def test_uniqueness_topic(self): |
869 | 870 |
|
870 | 871 | def test_uniqueness_foreign_id(self): |
871 | 872 | now = datetime.datetime.now(tzlocal()) |
872 | | - utcnow = (now - now.utcoffset()).replace(tzinfo=None) |
| 873 | + utcnow = now.astimezone(pytz.utc) |
873 | 874 |
|
874 | 875 | activity_data = { |
875 | 876 | "actor": 1, |
@@ -900,15 +901,15 @@ def test_uniqueness_foreign_id(self): |
900 | 901 |
|
901 | 902 | def test_time_ordering(self): |
902 | 903 | """ |
903 | | - datetime.datetime.utcnow() is our recommended approach |
| 904 | + datetime.datetime.now(tz=pytz.utc) is our recommended approach |
904 | 905 | so if we add an activity |
905 | 906 | add one using time |
906 | 907 | add another activity it should be in the right spot |
907 | 908 | """ |
908 | 909 |
|
909 | 910 | # timedelta is used to "make sure" that ordering is known even though |
910 | 911 | # server time is not |
911 | | - custom_time = datetime.datetime.utcnow() - dt.timedelta(days=1) |
| 912 | + custom_time = datetime.datetime.now(tz=pytz.utc) - dt.timedelta(days=1) |
912 | 913 |
|
913 | 914 | feed = self.user2 |
914 | 915 | for index, activity_time in enumerate([None, custom_time, None]): |
@@ -952,8 +953,8 @@ def test_wrong_feed_spec(self): |
952 | 953 |
|
953 | 954 | def test_serialization(self): |
954 | 955 | today = datetime.date.today() |
955 | | - then = datetime.datetime.now().replace(microsecond=0) |
956 | | - now = datetime.datetime.now() |
| 956 | + now = datetime.datetime.now(tz=pytz.utc) |
| 957 | + then = now.replace(microsecond=0) |
957 | 958 | data = dict( |
958 | 959 | string="string", |
959 | 960 | float=0.1, |
|
0 commit comments