def test_hydrating_unknown_structure_returns_same(): hydrant = DataHydrator() struct = Structure(b'?', "foo") mystery, = hydrant.hydrate([struct]) assert mystery == struct
def test_can_hydrate_node_structure(): hydrant = DataHydrator() struct = Structure(b'N', 123, ["Person"], {"name": "Alice"}) alice, = hydrant.hydrate([struct]) assert alice.id == 123 assert alice.labels == {"Person"} assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice"
class TemporalHydrationTestCase(TestCase): def setUp(self): self.hydrant = DataHydrator() def test_can_hydrate_date_time_structure(self): struct = Structure(b'd', 1539344261, 474716862) dt, = self.hydrant.hydrate([struct]) self.assertEqual(dt.year, 2018) self.assertEqual(dt.month, 10) self.assertEqual(dt.day, 12) self.assertEqual(dt.hour, 11) self.assertEqual(dt.minute, 37) self.assertEqual(dt.second, 41.474716862)
def test_can_hydrate_in_dict(): hydrant = DataHydrator() struct = Structure(b'N', 123, ["Person"], {"name": "Alice"}) alice_in_dict, = hydrant.hydrate([{"foo": struct}]) assert isinstance(alice_in_dict, dict) alice = alice_in_dict["foo"] assert alice.id == 123 assert alice.labels == {"Person"} assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice"
def test_can_hydrate_in_list(): hydrant = DataHydrator() struct = Structure(b'N', 123, ["Person"], {"name": "Alice"}) alice_in_list, = hydrant.hydrate([[struct]]) assert isinstance(alice_in_list, list) alice, = alice_in_list assert alice.id == 123 assert alice.labels == {"Person"} assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice"
class HydrationTestCase(TestCase): def setUp(self): self.hydrant = DataHydrator() def test_can_hydrate_node_structure(self): struct = Structure(b'N', 123, ["Person"], {"name": "Alice"}) alice, = self.hydrant.hydrate([struct]) self.assertEqual(alice.id, 123) self.assertEqual(alice.labels, {"Person"}) self.assertEqual(set(alice.keys()), {"name"}) self.assertEqual(alice.get("name"), "Alice") def test_hydrating_unknown_structure_returns_same(self): struct = Structure(b'?', "foo") mystery, = self.hydrant.hydrate([struct]) self.assertEqual(mystery, struct) def test_can_hydrate_in_list(self): struct = Structure(b'N', 123, ["Person"], {"name": "Alice"}) alice_in_list, = self.hydrant.hydrate([[struct]]) self.assertIsInstance(alice_in_list, list) alice, = alice_in_list self.assertEqual(alice.id, 123) self.assertEqual(alice.labels, {"Person"}) self.assertEqual(set(alice.keys()), {"name"}) self.assertEqual(alice.get("name"), "Alice") def test_can_hydrate_in_dict(self): struct = Structure(b'N', 123, ["Person"], {"name": "Alice"}) alice_in_dict, = self.hydrant.hydrate([{"foo": struct}]) self.assertIsInstance(alice_in_dict, dict) alice = alice_in_dict["foo"] self.assertEqual(alice.id, 123) self.assertEqual(alice.labels, {"Person"}) self.assertEqual(set(alice.keys()), {"name"}) self.assertEqual(alice.get("name"), "Alice")