~kissiel/checkbox/session-assistant-fix

« back to all changes in this revision

Viewing changes to plainbox/plainbox/impl/exporter/test_hexr.py

  • Committer: Daniel Manrique
  • Author(s): Pierre Equoy
  • Date: 2015-08-25 11:54:37 UTC
  • mfrom: (3944.2.1 checkbox)
  • Revision ID: daniel_manrique-20150825115437-laf7n12rfux46dix
"automatic merge of lp:~pierre-equoy/checkbox/fix-1479719-crash-when-exporting-session-if-empty-resources/ by tarmac [r=zyga][bug=1479719][author=pierre-equoy]"

Show diffs side-by-side

added added

removed removed

Lines of Context:
147
147
            'link': 'requirement.1.LINK',
148
148
        })])
149
149
 
 
150
    def _make_cert_empty_resources(self):
 
151
        # Create empty resources, as experienced when the tested system
 
152
        # freezes and corrupts the content of the session. (lp:1479719)
 
153
        state = self.manager.default_device_context.state
 
154
        ns = CERTIFICATION_NS
 
155
        state.set_resource_list(ns + 'cpuinfo', [])
 
156
        state.set_resource_list(ns + 'dpkg', [])
 
157
        state.set_resource_list(ns + 'lsb', [])
 
158
        state.set_resource_list(ns + 'uname', [])
 
159
        state.set_resource_list(ns + 'package', [])
 
160
        state.set_resource_list(ns + 'requirements', [])
 
161
 
150
162
    def _make_cert_attachments(self):
151
163
        state = self.manager.default_device_context.state
152
164
        partial_id_list = ['dmi_attachment', 'sysfs_attachment',
227
239
        evil_actual = stream.getvalue().decode("utf-8")
228
240
        self.assertMultiLineEqual(_evil_expected, evil_actual)
229
241
 
 
242
    def test_empty_resources(self):
 
243
        """Empty resources don't break the correctness of the XML document."""
 
244
        self._make_representative_jobs()
 
245
        self._make_cert_empty_resources()
 
246
        self._make_cert_attachments()
 
247
        stream = BytesIO()
 
248
        self.exporter.dump_from_session_manager(self.manager, stream)
 
249
        empty_resources_actual = stream.getvalue().decode("utf-8")
 
250
        self.assertMultiLineEqual(_empty_resources_expected, empty_resources_actual)
 
251
 
230
252
    def test_xml_parsability(self):
231
253
        """Each produced output can be parsed with an XML parser."""
232
254
        stream1 = BytesIO(_smoke_expected.encode("utf-8"))
529
551
    <system_id value="{evil}"/>
530
552
  </summary>
531
553
</system>""".format(evil=_escaped_evil_text)
 
554
 
 
555
_empty_resources_expected = """\
 
556
<?xml version="1.0"?>
 
557
<system version="1.0">
 
558
  <context>
 
559
    <info command="2013.com.canonical.plainbox::representative/plugin/attachment">IO-LOG-STDOUT
 
560
</info>
 
561
  </context>
 
562
  <hardware>
 
563
    <dmi>STDOUT-dmi_attachment
 
564
</dmi>
 
565
    <sysfs-attributes>STDOUT-sysfs_attachment
 
566
</sysfs-attributes>
 
567
    <udev>STDOUT-udev_attachment
 
568
</udev>
 
569
    <!-- cpuinfo resource is not available, not producing the <processors> section -->
 
570
  </hardware>
 
571
  <questions>
 
572
    <question name="2013.com.canonical.plainbox::representative/plugin/manual">
 
573
      <answer type="multiple_choice">pass</answer>
 
574
      <answer_choices>
 
575
        <value type="str">none</value>
 
576
        <value type="str">pass</value>
 
577
        <value type="str">fail</value>
 
578
        <value type="str">skip</value>
 
579
      </answer_choices>
 
580
      <comment>IO-LOG-STDOUT
 
581
IO-LOG-STDERR
 
582
</comment>
 
583
    </question>
 
584
    <question name="2013.com.canonical.plainbox::representative/plugin/qml">
 
585
      <answer type="multiple_choice">pass</answer>
 
586
      <answer_choices>
 
587
        <value type="str">none</value>
 
588
        <value type="str">pass</value>
 
589
        <value type="str">fail</value>
 
590
        <value type="str">skip</value>
 
591
      </answer_choices>
 
592
      <comment>IO-LOG-STDOUT
 
593
IO-LOG-STDERR
 
594
</comment>
 
595
    </question>
 
596
    <question name="2013.com.canonical.plainbox::representative/plugin/shell">
 
597
      <answer type="multiple_choice">pass</answer>
 
598
      <answer_choices>
 
599
        <value type="str">none</value>
 
600
        <value type="str">pass</value>
 
601
        <value type="str">fail</value>
 
602
        <value type="str">skip</value>
 
603
      </answer_choices>
 
604
      <comment>IO-LOG-STDOUT
 
605
IO-LOG-STDERR
 
606
</comment>
 
607
    </question>
 
608
    <question name="2013.com.canonical.plainbox::representative/plugin/user-interact">
 
609
      <answer type="multiple_choice">pass</answer>
 
610
      <answer_choices>
 
611
        <value type="str">none</value>
 
612
        <value type="str">pass</value>
 
613
        <value type="str">fail</value>
 
614
        <value type="str">skip</value>
 
615
      </answer_choices>
 
616
      <comment>IO-LOG-STDOUT
 
617
IO-LOG-STDERR
 
618
</comment>
 
619
    </question>
 
620
    <question name="2013.com.canonical.plainbox::representative/plugin/user-interact-verify">
 
621
      <answer type="multiple_choice">pass</answer>
 
622
      <answer_choices>
 
623
        <value type="str">none</value>
 
624
        <value type="str">pass</value>
 
625
        <value type="str">fail</value>
 
626
        <value type="str">skip</value>
 
627
      </answer_choices>
 
628
      <comment>IO-LOG-STDOUT
 
629
IO-LOG-STDERR
 
630
</comment>
 
631
    </question>
 
632
    <question name="2013.com.canonical.plainbox::representative/plugin/user-verify">
 
633
      <answer type="multiple_choice">pass</answer>
 
634
      <answer_choices>
 
635
        <value type="str">none</value>
 
636
        <value type="str">pass</value>
 
637
        <value type="str">fail</value>
 
638
        <value type="str">skip</value>
 
639
      </answer_choices>
 
640
      <comment>COMMENTS</comment>
 
641
    </question>
 
642
  </questions>
 
643
  <software>
 
644
    <!-- lsb resource is not available, not producing the <lsbrelease> tag -->
 
645
    <packages>
 
646
    </packages>
 
647
    <requirements>
 
648
    </requirements>
 
649
  </software>
 
650
  <summary>
 
651
    <client name="CLIENT_NAME" version="CLIENT_VERSION"/>
 
652
    <date_created value="TIMESTAMP"/>
 
653
    <!-- dpkg resource is not available, not producing the <architecture> tag -->
 
654
    <!-- lsb resource is not available, not producing <distribution> and <distroseries> tags -->
 
655
    <!-- uname resource is not available, not producing the <kernel-release> tag -->
 
656
    <private value="False"/>
 
657
    <contactable value="False"/>
 
658
    <live_cd value="False"/>
 
659
    <system_id value="SYSTEM_ID"/>
 
660
  </summary>
 
661
</system>"""