def test_format_timezoned_nonutc(self): t = xso.DateTime() self.assertEqual( "2014-01-26T19:40:10Z", t.format( pytz.timezone("Europe/Berlin").localize( datetime(2014, 1, 26, 20, 40, 10))))
class EventSubscription(xso.XSO): TAG = (namespaces.xep0060_event, "subscription") jid = xso.Attr( "jid", type_=xso.JID() ) node = xso.Attr( "node", default=None ) subid = xso.Attr( "subid", default=None ) subscription = xso.Attr( "subscription", validator=xso.RestrictToSet({ "none", "pending", "subscribed", "unconfigured", }), default=None ) expiry = xso.Attr( "expiry", type_=xso.DateTime(), )
def test_emit_legacy_format_with_switch(self): t = xso.DateTime(legacy=True) self.assertEqual( "19690721T02:56:15", t.format(datetime(1969, 7, 21, 2, 56, 15, tzinfo=pytz.utc))) self.assertEqual( "20140126T19:40:10", t.format( pytz.timezone("Europe/Berlin").localize( datetime(2014, 1, 26, 20, 40, 10))))
def test_require_datetime(self): t = xso.DateTime() values = [ 1, "foo", "2014-01-26T19:47:10Z", 12.3, ] for value in values: with self.assertRaisesRegex(TypeError, "must be a datetime object"): t.coerce(value)
class History(xso.XSO): TAG = (namespaces.xep0045_muc, "history") maxchars = xso.Attr( "maxchars", type_=xso.Integer(), default=None, ) maxstanzas = xso.Attr( "maxstanzas", type_=xso.Integer(), default=None, ) seconds = xso.Attr( "seconds", type_=xso.Integer(), default=None, ) since = xso.Attr( "since", type_=xso.DateTime(), default=None, ) def __init__(self, *, maxchars=None, maxstanzas=None, seconds=None, since=None): super().__init__() self.maxchars = maxchars self.maxstanzas = maxstanzas self.seconds = seconds self.since = since
class Delay(xso.XSO): """ A marker indicating delayed delivery of a stanza. .. attribute:: from_ The address as :class:`aioxmpp.JID` of the entity where the stanza was delayed. May be :data:`None`. .. attribute:: stamp The timestamp (as :class:`datetime.datetime`) at which the stanza was originally sent or intended to be sent. .. attribute:: reason The reason for which the stanza was delayed or :data:`None`. .. warning:: Please take the security considerations of :xep:`203` into account. """ TAG = namespaces.xep0203_delay, "delay" from_ = xso.Attr( "from", type_=xso.JID(), default=None, ) stamp = xso.Attr( "stamp", type_=xso.DateTime(), ) reason = xso.Text(default=None)
def test_format_naive(self): t = xso.DateTime() self.assertEqual("2014-01-26T19:40:10", t.format(datetime(2014, 1, 26, 19, 40, 10)))
def test_pass_datetime(self): t = xso.DateTime() dt = datetime.utcnow() self.assertIs(dt, t.coerce(dt))
def test_parse_local(self): t = xso.DateTime() self.assertEqual(datetime(2014, 1, 26, 20, 40, 10), t.parse("2014-01-26T20:40:10"))
def test_parse_milliseconds(self): t = xso.DateTime() self.assertEqual(datetime(2014, 1, 26, 20, 40, 10, 123456), t.parse("2014-01-26T20:40:10.123456"))
def test_parse_legacy_format(self): t = xso.DateTime() self.assertEqual(t.parse("19690721T02:56:15"), datetime(1969, 7, 21, 2, 56, 15, tzinfo=pytz.utc))
def test_parse_xep0082_examples(self): t = xso.DateTime() self.assertEqual(t.parse("1969-07-21T02:56:15Z"), datetime(1969, 7, 21, 2, 56, 15, tzinfo=pytz.utc)) self.assertEqual(t.parse("1969-07-20T21:56:15-05:00"), datetime(1969, 7, 21, 2, 56, 15, tzinfo=pytz.utc))
def test_parse_milliseconds_timezoned(self): t = xso.DateTime() self.assertEqual( datetime(2014, 1, 26, 19, 40, 10, 123456, tzinfo=pytz.utc), t.parse("2014-01-26T20:40:10.123456+01:00"))
def test_parse_example(self): t = xso.DateTime() self.assertEqual(datetime(2014, 1, 26, 19, 40, 10, tzinfo=pytz.utc), t.parse("2014-01-26T19:40:10Z"))
def test_format_timezoned_microseconds(self): t = xso.DateTime() self.assertEqual( "2014-01-26T19:40:10.1234Z", t.format(datetime(2014, 1, 26, 19, 40, 10, 123400, tzinfo=pytz.utc)))
def test_parse_need_date(self): t = xso.DateTime() with self.assertRaises(ValueError): t.parse("20:40:10")
def test_parse_need_time(self): t = xso.DateTime() with self.assertRaises(ValueError): t.parse("2014-01-26")
def test_format_naive_microseconds(self): t = xso.DateTime() self.assertEqual("2014-01-26T19:40:10.1234", t.format(datetime(2014, 1, 26, 19, 40, 10, 123400)))
def test_is_abstract_type(self): self.assertIsInstance(xso.DateTime(), xso.AbstractType)