Exemple #1
0
 def test_mandatory_fields(self):
     record = CloudRecord()
     record.set_field('VMUUID', 'host.example.org/cr/87912469269276')
     record.set_field('SiteName', 'MySite')
     record.set_field('MachineName', 'MyMachine')
     
     try:
         record._check_fields()
     except Exception, e:
         self.fail('_check_fields method failed: %s [%s]' % (str(e), str(type(e))))
Exemple #2
0
 def test_load_from_msg_value_check(self):
     """Check for correct values in CloudRecords generated from messages."""
     for msg in self.cases.keys():
     
         cr = CloudRecord()
         cr.load_from_msg(msg)
         
         cont = cr._record_content
     
         for key in self.cases[msg].keys():
             self.assertEqual(cont[key], self.cases[msg][key], "%s != %s for key %s" % (cont[key], self.cases[msg][key], key))
Exemple #3
0
 def test_load_from_msg(self):
     
     for msg in self.cases.keys():
     
         cr = CloudRecord()
         cr.load_from_msg(msg)
         
         cont = cr._record_content
     
         for key in self.cases[msg].keys():
             self.assertEqual(cont[key], self.cases[msg][key], "%s != %s for key %s" % (cont[key], self.cases[msg][key], key))
Exemple #4
0
    def test_load_from_msg_value_check(self):
        """Check for correct values in CloudRecords generated from messages."""
        for msg in self.cases.keys():

            cr = CloudRecord()
            cr.load_from_msg(msg)

            cont = cr._record_content

            for key in self.cases[msg].keys():
                self.assertEqual(
                    cont[key], self.cases[msg][key], "%s != %s for key %s" %
                    (cont[key], self.cases[msg][key], key))
Exemple #5
0
 def test_mandatory_fields(self):
     record = CloudRecord()
     record.set_field('VMUUID', 'host.example.org/cr/87912469269276')
     record.set_field('SiteName', 'MySite')
     record.set_field('MachineName', 'MyMachine')
     
     try:
         record._check_fields()
     except Exception, e:
         self.fail('_check_fields method failed: %s [%s]' % (str(e), str(type(e))))
Exemple #6
0
    def test_load_from_msg_type_check(self):
        """Check the fields of a parsed message are of the correct type."""
        for msg in self.cases.keys():

            cr = CloudRecord()
            cr.load_from_msg(msg)

            for key in cr._int_fields:
                value = cr._record_content[key]
                # Check the value we are going to be passing to MySQL
                # is an integer or None. MySQL 5.6.x rejects the value
                # otherwise, whereas 5.1.x interprets it as integer 0.
                valid_value = isinstance(value, int) or value is None
                # Use 'repr' to show quote marks if value is a string.
                self.assertTrue(
                    valid_value,
                    'Integer %s with value: %s\n%s' % (key, repr(value), msg))

            for key in cr._float_fields:
                value = cr._record_content[key]
                # Check the value we are going to be passing to MySQL
                # is a float or None. MySQL 5.6.x rejects the value
                # otherwise, whereas 5.1.x interprets it as 0.00.
                valid_value = isinstance(value, float) or value is None
                # Use 'repr' to show quote marks if value is a string.
                self.assertTrue(
                    valid_value,
                    'Decimal %s with value: %s\n%s' % (key, repr(value), msg))

            for key in cr._datetime_fields:
                value = cr._record_content[key]
                # Check the value we are going to be passing to MySQL
                # is a datetime or None. MySQL 5.6.x rejects the value
                # otherwise, whereas 5.1.x interprets it as a zero timestamp.
                valid_value = isinstance(value, datetime) or value is None
                # Use 'repr' to show quote marks if value is a string.
                self.assertTrue(
                    valid_value,
                    'Datetime %s with value: %s\n%s' % (key, repr(value), msg))
Exemple #7
0
    def test_load_from_msg_type_check(self):
        """Check the fields of a parsed message are of the correct type."""
        for msg in self.cases.keys():

            cr = CloudRecord()
            cr.load_from_msg(msg)

            for key in cr._int_fields:
                value = cr._record_content[key]
                # Check the value we are going to be passing to MySQL
                # is an integer or None. MySQL 5.6.x rejects the value
                # otherwise, whereas 5.1.x interprets it as integer 0.
                valid_value = isinstance(value, int) or value is None
                # Use 'repr' to show quote marks if value is a string.
                self.assertTrue(valid_value, 'Integer %s with value: %s\n%s' %
                                (key, repr(value), msg))

            for key in cr._float_fields:
                value = cr._record_content[key]
                # Check the value we are going to be passing to MySQL
                # is a float or None. MySQL 5.6.x rejects the value
                # otherwise, whereas 5.1.x interprets it as 0.00.
                valid_value = isinstance(value, float) or value is None
                # Use 'repr' to show quote marks if value is a string.
                self.assertTrue(valid_value, 'Decimal %s with value: %s\n%s' %
                                (key, repr(value), msg))

            for key in cr._datetime_fields:
                value = cr._record_content[key]
                # Check the value we are going to be passing to MySQL
                # is a datetime or None. MySQL 5.6.x rejects the value
                # otherwise, whereas 5.1.x interprets it as a zero timestamp.
                valid_value = isinstance(value, datetime) or value is None
                # Use 'repr' to show quote marks if value is a string.
                self.assertTrue(valid_value, 'Datetime %s with value: %s\n%s' %
                                (key, repr(value), msg))