Commit 78f01daf authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_slap_tool: Add test to call API Twice

  'since' should be unmutable.
parent 9e1ec652
......@@ -117,6 +117,7 @@
</item>
</dictionary>
</list>
<none/>
</tuple>
</pickle>
</record>
......
......@@ -7,6 +7,7 @@ from App.Common import rfc1123_date
import os
import tempfile
import time
# blurb to make nice XML comparisions
import xml.dom.ext.reader.Sax
......@@ -1574,6 +1575,92 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
def test_softwareInstanceError_twice(self):
self._makeComplexComputer()
partition_id = self.start_requested_software_instance.getAggregateValue(
portal_type='Computer Partition').getReference()
self.login(self.start_requested_software_instance.getUserId())
error_log = 'The error'
response = self.portal_slap.softwareInstanceError(self.computer_id,
partition_id, error_log)
self.assertEqual('None', response)
created_at = rfc1123_date(DateTime())
since = created_at
response = self.portal_slap.getComputerPartitionStatus(self.computer_id,
partition_id)
# check returned XML
xml_fp = StringIO.StringIO()
xml.dom.ext.PrettyPrint(xml.dom.ext.reader.Sax.FromXml(response.body),
stream=xml_fp)
xml_fp.seek(0)
got_xml = xml_fp.read()
expected_xml = """\
<?xml version='1.0' encoding='UTF-8'?>
<marshal>
<dictionary id='i2'>
<string>created_at</string>
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>text</string>
<string>#error while instanciating: The error</string>
<string>user</string>
<string>%(instance_guid)s</string>
</dictionary>
</marshal>
""" % dict(
created_at=created_at,
since = since,
instance_guid=self.start_requested_software_instance.getReference(),
)
self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
self.unpinDateTime()
time.sleep(1)
self.pinDateTime(DateTime())
response = self.portal_slap.softwareInstanceError(self.computer_id,
partition_id, error_log)
self.assertEqual('None', response)
ncreated_at = rfc1123_date(DateTime())
response = self.portal_slap.getComputerPartitionStatus(self.computer_id,
partition_id)
# check returned XML
xml_fp = StringIO.StringIO()
xml.dom.ext.PrettyPrint(xml.dom.ext.reader.Sax.FromXml(response.body),
stream=xml_fp)
xml_fp.seek(0)
got_xml = xml_fp.read()
self.assertNotEquals(created_at, ncreated_at)
self.assertNotEquals(since, ncreated_at)
self.assertEquals(since, created_at)
expected_xml = """\
<?xml version='1.0' encoding='UTF-8'?>
<marshal>
<dictionary id='i2'>
<string>created_at</string>
<string>%(created_at)s</string>
<string>since</string>
<string>%(since)s</string>
<string>text</string>
<string>#error while instanciating: The error</string>
<string>user</string>
<string>%(instance_guid)s</string>
</dictionary>
</marshal>
""" % dict(
created_at=ncreated_at,
since = since,
instance_guid=self.start_requested_software_instance.getReference(),
)
self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
def assertInstanceBangSimulator(self, args, kwargs):
stored = eval(open(self.instance_bang_simulator).read())
# do the same translation magic as in workflow
......
......@@ -46,22 +46,22 @@
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W: 27, 10: Use of eval (eval-used)</string>
<string>W:540, 13: Use of eval (eval-used)</string>
<string>W:595, 13: Use of eval (eval-used)</string>
<string>W:836, 13: Use of eval (eval-used)</string>
<string>W:1461, 13: Use of eval (eval-used)</string>
<string>W:1578, 13: Use of eval (eval-used)</string>
<string>W:1636, 13: Use of eval (eval-used)</string>
<string>W:1676, 13: Use of eval (eval-used)</string>
<string>W:2239, 13: Use of eval (eval-used)</string>
<string>W:2640, 13: Use of eval (eval-used)</string>
<string>W:2698, 13: Use of eval (eval-used)</string>
<string>W:2725, 13: Use of eval (eval-used)</string>
<string>W:2882, 13: Use of eval (eval-used)</string>
<string>W:2910, 13: Use of eval (eval-used)</string>
<string>W:2959, 13: Use of eval (eval-used)</string>
<string>W:3006, 13: Use of eval (eval-used)</string>
<string>W: 28, 10: Use of eval (eval-used)</string>
<string>W:537, 13: Use of eval (eval-used)</string>
<string>W:592, 13: Use of eval (eval-used)</string>
<string>W:829, 13: Use of eval (eval-used)</string>
<string>W:1446, 13: Use of eval (eval-used)</string>
<string>W:1649, 13: Use of eval (eval-used)</string>
<string>W:1707, 13: Use of eval (eval-used)</string>
<string>W:1747, 13: Use of eval (eval-used)</string>
<string>W:2306, 13: Use of eval (eval-used)</string>
<string>W:2699, 13: Use of eval (eval-used)</string>
<string>W:2757, 13: Use of eval (eval-used)</string>
<string>W:2784, 13: Use of eval (eval-used)</string>
<string>W:2941, 13: Use of eval (eval-used)</string>
<string>W:2969, 13: Use of eval (eval-used)</string>
<string>W:3018, 13: Use of eval (eval-used)</string>
<string>W:3065, 13: Use of eval (eval-used)</string>
</tuple>
</value>
</item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment