Ejemplo n.º 1
0
 def test_snapshot_make_transitive_entity(self):
     """Test snapshotting compound entities."""
     elem = TestLinkedList('First', next_elem=TestLinkedList('Second'))
     snapshot = JsonSnapshot()
     snapshot.make_entity_for_object(elem)
     entity = snapshot.make_entity_for_object(elem.next)
     found = snapshot.find_entity_for_object(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())
Ejemplo n.º 2
0
  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_object(b))
    self.assertIsNone(snapshot.find_entity_for_object(b)) # Still none
    snapshot.add_object(a)
    json_object = snapshot.to_json_object()

    have_b = snapshot.find_entity_for_object(b)
    self.assertEquals(2, have_b.id)
    entity_b = snapshot.make_entity_for_object(b)
    self.assertEquals(id(have_b), id(entity_b))

    have_c = snapshot.find_entity_for_object(c)
    entity_c = snapshot.make_entity_for_object(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)
Ejemplo n.º 3
0
  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_object(b))
    self.assertIsNone(snapshot.find_entity_for_object(b)) # Still none
    snapshot.add_object(a)
    json_object = snapshot.to_json_object()

    have_b = snapshot.find_entity_for_object(b)
    self.assertEquals(2, have_b.id)
    entity_b = snapshot.make_entity_for_object(b)
    self.assertEquals(id(have_b), id(entity_b))

    have_c = snapshot.find_entity_for_object(c)
    entity_c = snapshot.make_entity_for_object(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)
Ejemplo n.º 4
0
  def test_process_snapshot(self):
    """Test the conversion of a snapshot into HTML."""
    tail = TestLinkedList(name='tail')
    head = TestLinkedList(name='head', next_elem=tail)
    snapshot = JsonSnapshot()
    snapshot.make_entity_for_object(head)
    json_snapshot = snapshot.to_json_object()

    entity_manager = ProcessedEntityManager()
    processor = ProcessToRenderInfo(
        HtmlDocumentManager('test_json'), entity_manager)
    processor.max_uncollapsable_json_lines = 20
    processor.max_uncollapsable_metadata_rows = 20
    processor.max_uncollapsable_entity_rows = 20
    processor.default_force_top_level_collapse = False

    in_relation = None
    entity_manager.push_entity_map(json_snapshot['_entities'])
    html_info = processor.process_entity_id(json_snapshot['_subject_id'],
                                            json_snapshot, in_relation)
    entity_manager.pop_entity_map(json_snapshot['_entities'])

    expect = """<table>
  <tr>
    <th><i>metadata</i></th>
    <td>
      <table>
        <tr><th>_id</th><td>1</td></tr>
        <tr><th>class</th><td>type TestLinkedList</td></tr>
        <tr><th>name</th><td>head</td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <th>Next</th>
    <td>
      <table>
        <tr>
          <th><i>metadata</i></th>
          <td>
            <table>
              <tr><th>_id</th><td>2</td></tr>
              <tr><th>class</th><td>type TestLinkedList</td></tr>
              <tr><th>name</th><td>tail</td></tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
"""
    # Test without regard to whitespace formatting.
    self.assertEquals(''.join(expect.split()),
                      ''.join(str(html_info.detail_block).split()))
Ejemplo n.º 5
0
    def test_process_snapshot(self):
        """Test the conversion of a snapshot into HTML."""
        tail = TestLinkedList(name='tail')
        head = TestLinkedList(name='head', next_elem=tail)
        snapshot = JsonSnapshot()
        snapshot.make_entity_for_object(head)
        json_snapshot = snapshot.to_json_object()

        entity_manager = ProcessedEntityManager()
        processor = ProcessToRenderInfo(HtmlDocumentManager('test_json'),
                                        entity_manager)
        processor.max_uncollapsable_json_lines = 20
        processor.max_uncollapsable_metadata_rows = 20
        processor.max_uncollapsable_entity_rows = 20
        processor.default_force_top_level_collapse = False

        in_relation = None
        entity_manager.push_entity_map(json_snapshot['_entities'])
        html_info = processor.process_entity_id(json_snapshot['_subject_id'],
                                                json_snapshot, in_relation)
        entity_manager.pop_entity_map(json_snapshot['_entities'])

        expect = """<table>
  <tr>
    <th><i>metadata</i></th>
    <td>
      <table>
        <tr><th>_id</th><td>1</td></tr>
        <tr><th>class</th><td>type TestLinkedList</td></tr>
        <tr><th>name</th><td>head</td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <th>Next</th>
    <td>
      <table>
        <tr>
          <th><i>metadata</i></th>
          <td>
            <table>
              <tr><th>_id</th><td>2</td></tr>
              <tr><th>class</th><td>type TestLinkedList</td></tr>
              <tr><th>name</th><td>tail</td></tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
"""
        # Test without regard to whitespace formatting.
        self.assertEquals(''.join(expect.split()),
                          ''.join(str(html_info.detail_block).split()))
Ejemplo n.º 6
0
    def test_cycle(self):
        tail = TestLinkedList(name='tail')
        head = TestLinkedList(name='head', next_elem=tail)
        tail.next = head
        snapshot = JsonSnapshot()

        entity_manager = ProcessedEntityManager()
        processor = ProcessToRenderInfo(HtmlDocumentManager('test_json'),
                                        entity_manager)

        snapshot.make_entity_for_object(head)
        json_snapshot = snapshot.to_json_object()
        self.assertEqual(1, json_snapshot.get('_subject_id'))
        entity_manager.push_entity_map(json_snapshot.get('_entities'))
        info = processor.process_entity_id(1, snapshot)
Ejemplo n.º 7
0
 def test_snapshot_make_transitive_entity(self):
   """Test snapshotting compound entities."""
   elem = TestLinkedList('First', next_elem=TestLinkedList('Second'))
   snapshot = JsonSnapshot()
   snapshot.make_entity_for_object(elem)
   entity = snapshot.make_entity_for_object(elem.next)
   found = snapshot.find_entity_for_object(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())
Ejemplo n.º 8
0
  def test_cycle(self):
    tail = TestLinkedList(name='tail')
    head = TestLinkedList(name='head', next_elem=tail)
    tail.next = head
    snapshot = JsonSnapshot()

    entity_manager = ProcessedEntityManager()
    processor = ProcessToRenderInfo(
        HtmlDocumentManager('test_json'), entity_manager)

    snapshot.make_entity_for_object(head)
    json_snapshot = snapshot.to_json_object()
    self.assertEqual(1, json_snapshot.get('_subject_id'))
    entity_manager.push_entity_map(json_snapshot.get('_entities'))

    in_relation = None
    info = processor.process_entity_id(1, snapshot, in_relation)
Ejemplo n.º 9
0
 def test_snapshot_make_entity(self):
   """Test snapshotting JsonSnapshotableEntity objects into entities."""
   elem = TestLinkedList('Hello')
   snapshot = JsonSnapshot()
   entity = snapshot.make_entity_for_object(elem)
   found = snapshot.find_entity_for_object(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())
Ejemplo n.º 10
0
 def test_snapshot_make_entity(self):
   """Test snapshotting JsonSnapshotableEntity objects into entities."""
   elem = TestLinkedList('Hello')
   snapshot = JsonSnapshot()
   entity = snapshot.make_entity_for_object(elem)
   found = snapshot.find_entity_for_object(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())