Skip to content

Commit

Permalink
RuntimeConfig: tests with microseconds and nanoseconds (#5150)
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelnucfin authored Apr 4, 2018
1 parent 9a6acfa commit 4750fc4
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions runtimeconfig/tests/unit/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _make_one(self, *args, **kw):

def _verifyResourceProperties(self, variable, resource):
import base64
from google.cloud._helpers import _rfc3339_to_datetime
from google.api_core import datetime_helpers

if 'name' in resource:
self.assertEqual(variable.full_name, resource['name'])
Expand All @@ -50,7 +50,8 @@ def _verifyResourceProperties(self, variable, resource):
if 'updateTime' in resource:
self.assertEqual(
variable.update_time,
_rfc3339_to_datetime(resource['updateTime']))
datetime_helpers.DatetimeWithNanoseconds.from_rfc3339(
resource['updateTime']))
else:
self.assertIsNone(variable.update_time)

Expand Down Expand Up @@ -178,6 +179,32 @@ def test_reload_w_alternate_client(self):
self.assertEqual(req['path'], '/%s' % (self.PATH,))
self._verifyResourceProperties(variable, RESOURCE)

def test_with_microseconds(self):
from google.cloud.runtimeconfig.config import Config

resource = {
'updateTime': '2016-04-14T21:21:54.123456Z',
}
conn = _Connection(resource)
client = _Client(project=self.PROJECT, connection=conn)
config = Config(name=self.CONFIG_NAME, client=client)
variable = self._make_one(name=self.VARIABLE_NAME, config=config)
variable.reload(client=client)
self._verifyResourceProperties(variable, resource)

def test_with_nanoseconds(self):
from google.cloud.runtimeconfig.config import Config

resource = {
'updateTime': '2016-04-14T21:21:54.123456789Z',
}
conn = _Connection(resource)
client = _Client(project=self.PROJECT, connection=conn)
config = Config(name=self.CONFIG_NAME, client=client)
variable = self._make_one(name=self.VARIABLE_NAME, config=config)
variable.reload(client=client)
self._verifyResourceProperties(variable, resource)


class _Client(object):

Expand Down

0 comments on commit 4750fc4

Please sign in to comment.