Commit 0393a23c by Ali Mohammad

TIMEZONES

parent bf074d47
...@@ -34,7 +34,7 @@ class XBlockUserState(namedtuple('_XBlockUserState', ['username', 'block_key', ' ...@@ -34,7 +34,7 @@ class XBlockUserState(namedtuple('_XBlockUserState', ['username', 'block_key', '
state: A dict mapping field names to the values of those fields for this XBlock. state: A dict mapping field names to the values of those fields for this XBlock.
updated: A :class:`datetime.datetime`. We guarantee that the fields updated: A :class:`datetime.datetime`. We guarantee that the fields
that were returned in "state" have not been changed since that were returned in "state" have not been changed since
this time. this time (in UTC).
scope: A :class:`xblock.fields.Scope` identifying which XBlock scope this state is coming from. scope: A :class:`xblock.fields.Scope` identifying which XBlock scope this state is coming from.
""" """
__slots__ = () __slots__ = ()
......
...@@ -17,6 +17,7 @@ test suite, use the snippet: ...@@ -17,6 +17,7 @@ test suite, use the snippet:
from datetime import datetime from datetime import datetime
from unittest import TestCase from unittest import TestCase
import pytz
from contracts import contract from contracts import contract
from edx_user_state_client.interface import XBlockUserStateClient, XBlockUserState from edx_user_state_client.interface import XBlockUserStateClient, XBlockUserState
...@@ -353,9 +354,9 @@ class _UserStateClientTestCRUD(_UserStateClientTestUtils): ...@@ -353,9 +354,9 @@ class _UserStateClientTestCRUD(_UserStateClientTestUtils):
self.assertItemsEqual(self.get_many(user=0, blocks=[0, 1]), []) self.assertItemsEqual(self.get_many(user=0, blocks=[0, 1]), [])
def test_get_mod_date(self): def test_get_mod_date(self):
start_time = datetime.utcnow() start_time = datetime.now(pytz.utc)
self.set_many(user=0, block_to_state={0: {'a': 'b'}, 1: {'b': 'c'}}) self.set_many(user=0, block_to_state={0: {'a': 'b'}, 1: {'b': 'c'}})
end_time = datetime.utcnow() end_time = datetime.now(pytz.utc)
mod_dates = self.get(user=0, block=0) mod_dates = self.get(user=0, block=0)
...@@ -364,15 +365,15 @@ class _UserStateClientTestCRUD(_UserStateClientTestUtils): ...@@ -364,15 +365,15 @@ class _UserStateClientTestCRUD(_UserStateClientTestUtils):
self.assertLess(mod_dates.updated, end_time) self.assertLess(mod_dates.updated, end_time)
def test_get_many_mod_date(self): def test_get_many_mod_date(self):
start_time = datetime.utcnow() start_time = datetime.now(pytz.utc)
self.set_many( self.set_many(
user=0, user=0,
block_to_state={0: {'a': 'b'}}) block_to_state={0: {'a': 'b'}})
mid_time = datetime.utcnow() mid_time = datetime.now(pytz.utc)
self.set_many( self.set_many(
user=0, user=0,
block_to_state={1: {'a': 'c'}}) block_to_state={1: {'a': 'c'}})
end_time = datetime.utcnow() end_time = datetime.now(pytz.utc)
mod_dates = list(self.get_many( mod_dates = list(self.get_many(
user=0, user=0,
...@@ -621,7 +622,7 @@ class DictUserStateClient(XBlockUserStateClient): ...@@ -621,7 +622,7 @@ class DictUserStateClient(XBlockUserStateClient):
Add the specified state to the state history of this block. Add the specified state to the state history of this block.
""" """
history_list = self._history.setdefault((username, block_key, scope), []) history_list = self._history.setdefault((username, block_key, scope), [])
history_list.insert(0, XBlockUserState(username, block_key, state, datetime.utcnow(), scope)) history_list.insert(0, XBlockUserState(username, block_key, state, datetime.now(pytz.utc), scope))
def get_many(self, username, block_keys, scope=Scope.user_state, fields=None): def get_many(self, username, block_keys, scope=Scope.user_state, fields=None):
for key in block_keys: for key in block_keys:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment