Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'contact': {
'phone': '082345234',
'address': {
'country': 'uk',
'postcode': 'sg1 3ab',
}
},
'signup_date': '2014-06-12T19:06:02'
}
serializer = UserSerializer()
result = serializer.marshal(data)
self.assertTrue(isinstance(result, User))
self.assertEqual(result.name, 'bob')
self.assertEqual(result.signup_date, datetime(2014, 6, 12, 19, 6, 2, tzinfo=Utc()))
contact_details = result.contact_details
self.assertTrue(isinstance(contact_details, ContactDetail))
self.assertEqual(contact_details.phone, '082345234')
address = result.contact_details.address
self.assertTrue(isinstance(address, Address))
self.assertEqual(address.country, 'uk')
self.assertEqual(address.postcode, 'sg1 3ab')
self.assertIsNone(result.id)
self.session.add(result)
self.session.commit()
self.assertIsNotNone(result.id)
def test_parse_invalid_date():
try:
iso8601.parse_date(None)
except iso8601.ParseError:
pass
else:
assert 1 == 2
def test_query2_query_categorize(datastore):
bid = "test_bucket"
qname = "test"
starttime = iso8601.parse_date("1970")
endtime = starttime + timedelta(hours=1)
example_query = """
events = query_bucket("{bid}");
events = sort_by_timestamp(events);
events = categorize(events, [[["test"], {{"regex": "test"}}], [["test", "subtest"], {{"regex": "test2"}}]]);
events_by_cat = merge_events_by_keys(events, ["$category"]);
RETURN = {{"events": events, "events_by_cat": events_by_cat}};
""".format(
bid=bid, bid_escaped=bid.replace("'", "\\'")
)
try:
bucket = datastore.create_bucket(
bucket_id=bid, type="test", client="test", hostname="test", name="asd"
)
events = [
def test_query2_return_value():
qname = "asd"
starttime = iso8601.parse_date("1970-01-01")
endtime = iso8601.parse_date("1970-01-02")
example_query = "RETURN = 1;"
result = query(qname, example_query, starttime, endtime, None)
assert result == 1
example_query = "RETURN = 'testing 123'"
result = query(qname, example_query, starttime, endtime, None)
assert result == "testing 123"
example_query = "RETURN = {'a': 1}"
result = query(qname, example_query, starttime, endtime, None)
assert result == {"a": 1}
# Nothing to return
with pytest.raises(QueryParseException):
example_query = "a=1"
def test_parse_no_timezone_different_default():
tz = iso8601.FixedOffset(2, 0, "test offset")
d = iso8601.parse_date("2007-01-01T08:00:00", default_timezone=tz)
assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, tz)
assert d.tzinfo == tz
def test_parse_invalid_date(invalid_date, error_string):
assert isinstance(invalid_date, str) or invalid_date is None # Why? 'cos I've screwed up the parametrize before :)
with pytest.raises(iso8601.ParseError) as exc:
iso8601.parse_date(invalid_date)
assert exc.errisinstance(iso8601.ParseError)
assert str(exc.value).startswith(error_string)
def test_parse_invalid_date(invalid_date, error_string):
assert isinstance(invalid_date, str) or invalid_date is None # Why? 'cos I've screwed up the parametrize before :)
with pytest.raises(iso8601.ParseError) as exc:
iso8601.parse_date(invalid_date)
assert exc.errisinstance(iso8601.ParseError)
assert str(exc.value).startswith(error_string)
def test_parse_no_timezone_different_default():
tz = iso8601.FixedOffset(2, 0, "test offset")
d = iso8601.parse_date("2007-01-01T08:00:00", default_timezone=tz)
assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, tz)
assert d.tzinfo == tz
def test_parse_isotime(self):
expect = timeutils.parse_isotime(self.skynet_self_aware_time_str)
skynet_self_aware_time_utc = self.skynet_self_aware_time.replace(
tzinfo=iso8601.iso8601.UTC)
self.assertEqual(skynet_self_aware_time_utc, expect)
def now():
"""Return datetime instance for current time in UTC.
"""
return datetime.datetime.utcnow().replace(tzinfo=iso8601.Utc())