Example #1
0
 def test_unicode_decodes(self):
     """Unicode should decode plain strings."""
     a = u"\N{HIRAGANA LETTER A}"
     self.assertEqual(Unicode().coerce(a.encode("utf-8")), a)
     letter = u"\N{LATIN SMALL LETTER A WITH GRAVE}"
     self.assertEqual(
         Unicode(encoding="latin-1").coerce(letter.encode("latin-1")),
         letter)
Example #2
0
 def test_message_is_actually_coerced(self):
     """
     The message that eventually gets sent should be the result of
     the coercion.
     """
     self.store.add_schema(Message("data", {"data": Unicode()}))
     self.store.add({"type": "data",
                     "data": u"\N{HIRAGANA LETTER A}".encode("utf-8"),
                     "api": b"3.2"})
     self.assertEqual(self.store.get_pending_messages(),
                      [{"type": "data", "api": b"3.2",
                        "data": u"\N{HIRAGANA LETTER A}"}])
Example #3
0
 def test_unicode_or_str_bad_encoding(self):
     """Decoding errors should be converted to InvalidErrors."""
     self.assertRaises(InvalidError, Unicode().coerce, b"\xff")
Example #4
0
 def test_unicode_bad_value(self):
     """Invalid values raise an errors."""
     self.assertRaises(InvalidError, Unicode().coerce, 32)
Example #5
0
 def test_unicode_with_str(self):
     """Unicode accept byte strings and return a unicode."""
     self.assertEqual(Unicode().coerce(b"foo"), u"foo")
Example #6
0
 def test_unicode(self):
     self.assertEqual(Unicode().coerce(u"foo"), u"foo")
Example #7
0
 def test_any_bad(self):
     schema = Any(Constant(None), Unicode())
     self.assertRaises(InvalidError, schema.coerce, object())
Example #8
0
 def test_any(self):
     schema = Any(Constant(None), Unicode())
     self.assertEqual(schema.coerce(None), None)
     self.assertEqual(schema.coerce(u"foo"), u"foo")
Example #9
0
 def test_list_multiple_items(self):
     a = u"\N{HIRAGANA LETTER A}"
     schema = List(Unicode())
     self.assertEqual(schema.coerce([a, a.encode("utf-8")]), [a, a])
Example #10
0
    "KEYSTONE_TOKEN",
    "JUJU_UNITS_INFO",
    "CLOUD_METADATA",
]

# When adding a new schema, which deprecates an older schema, the recommended
# naming convention, is to name it SCHEMA_NAME_ and the last API version that
# the schema works with.
#
# i.e. if I have USERS and I'm deprecating it, in API 2.2, then USERS becomes
# USERS_2_1

process_info = KeyDict(
    {
        "pid": Int(),
        "name": Unicode(),
        "state": Bytes(),
        "sleep-average": Int(),
        "uid": Int(),
        "gid": Int(),
        "vm-size": Int(),
        "start-time": Int(),
        "percent-cpu": Float()
    },
    # Optional for backwards compatibility
    optional=["vm-size", "sleep-average", "percent-cpu"])

ACTIVE_PROCESS_INFO = Message(
    "active-process-info",
    {
        "kill-processes": List(Int()),