コード例 #1
0
ファイル: snapshot_test.py プロジェクト: tompscanlan/citest
  def test_snapshot_list(self):
    a = TestLinkedList('A')
    b = TestLinkedList('B')
    c = TestLinkedList('C')
    a.next = b
    b.next = c

    snapshot = JsonSnapshot()
    self.assertIsNone(snapshot.find_entity_for_data(b))
    self.assertIsNone(snapshot.find_entity_for_data(b)) # Still none
    snapshot.add_data(a)
    json_object = snapshot.to_json_object()

    have_b = snapshot.find_entity_for_data(b)
    self.assertEquals(2, have_b.id)
    entity_b = snapshot.make_entity_for_data(b)
    self.assertEquals(id(have_b), id(entity_b))

    have_c = snapshot.find_entity_for_data(c)
    entity_c = snapshot.make_entity_for_data(c)
    self.assertEquals(id(have_c), id(entity_c))
    self.assertEquals(3, entity_c.id)

    expect = {
        '_subject_id': 1,
        '_type': 'JsonSnapshot',
        '_entities': [
            {'_id': 1, 'name': 'A', '_edges': [{'_to': 2}]},
            {'_id': 2, 'name': 'B', '_edges': [{'_to': 3}]},
            {'_id': 3, 'name': 'C'}]}

    self.assertItemsEqual(expect, json_object)
コード例 #2
0
ファイル: snapshot_test.py プロジェクト: tompscanlan/citest
 def test_snapshot_make_entity(self):
   """Test snapshotting JsonSnapshotable objects into entities."""
   elem = TestLinkedList('Hello')
   snapshot = JsonSnapshot()
   entity = snapshot.make_entity_for_data(elem)
   found = snapshot.find_entity_for_data(elem)
   self.assertEquals(found, entity)
   self.assertEquals(id(found), id(entity))
   self.assertItemsEqual({'_subject_id': 1,
                          '_type': 'JsonSnapshot',
                          '_entities': [{'_id': 1, 'name': 'Hello'}]},
                         snapshot.to_json_object())
コード例 #3
0
ファイル: snapshot_test.py プロジェクト: tompscanlan/citest
 def test_snapshot_make_transitive_entity(self):
   """Test snapshotting compound entities."""
   elem = TestLinkedList('First', next_elem=TestLinkedList('Second'))
   snapshot = JsonSnapshot()
   snapshot.make_entity_for_data(elem)
   entity = snapshot.make_entity_for_data(elem.next)
   found = snapshot.find_entity_for_data(elem.next)
   self.assertEquals(found, entity)
   self.assertEquals(id(found), id(entity))
   self.assertItemsEqual({'_subject_id': 1,
                          '_type': 'JsonSnapshot',
                          '_entities': [{'_id': 1, 'name': 'First',
                                         '_edges':[{'_to': 2}]},
                                        {'_id': 2, 'name': 'Second'}]},
                         snapshot.to_json_object())