def test_iter(self): j = json.loads("""{ "a": 1, "b": 2, "c": 3 }""") uut = jsonify(j) for (k, v) in uut: if k == 'a': self.assertEqual(1, v) elif k == 'b': self.assertEqual(2, v) elif k == 'c': self.assertEqual(3, v) else: self.fail("Unexpected entry (%r, %r)" % (k, v))
def test_values(self): j = json.loads("""{ "a": 1, "b": 2, "c": 3 }""") uut = jsonify(j) self.assertEqual([1, 2, 3], sorted(uut.values()))
def test_items(self): j = json.loads("""{ "a": 1, "b": 2, "c": 3 }""") uut = jsonify(j) self.assertEqual([('a', 1), ('b', 2), ('c', 3)], sorted(uut.items()))
def test_get_field_names(self): j = json.loads("""{ "a": 1, "b": 2, "c": 3 }""") uut = jsonify(j) self.assertEqual(['a', 'b', 'c'], sorted(uut.get_field_names()))
def test_subscript(self): j = json.loads("""{ "a": 1, "b": 2, "c": 3 }""") uut = jsonify(j) self.assertEqual(2, uut['b']) self.assertEqual(None, uut['z'])
def test_in(self): j = json.loads("""{ "a": 1 }""") uut = jsonify(j) self.assertTrue('a' in uut) self.assertFalse('z' in uut)
def test_array(self): j = json.loads("""[ { "a": 1 }, 2, "c" ]""") uut = jsonify(j) self.assertEqual(1, uut[0].a) self.assertEqual(2, uut[1]) self.assertEqual("c", uut[2])
def test_object(self): j = json.loads("""{ "a": 1 }""") uut = jsonify(j) self.assertEqual(1, uut.a)
def process_resource_listing(self, resources): jsonified = jsonify(resources) for processor in self.processors: processor.apply(jsonified) return jsonified