Example #1
0
 def test_create_violation_hash_with_full_name_not_string(self):
     expected_hash = (
         'f8813c34ab225002fb2c04ee392691b4e37c9a0eee1a08b277c36'
         'b7bb0309f9150a88231dbd3f4ec5e908a5a39a8e38515b8e532d5'
         '09aa3220e71ab4844a0284')
     returned_hash = scanner_dao._create_violation_hash(
         None, self.test_inventory_data, self.test_violation_data)
     self.assertEquals(expected_hash, returned_hash)
Example #2
0
 def test_create_violation_hash_with_inventory_data_not_string(self):
     expected_hash = (
         'fc59c859e9a088d14627f363d629142920225c8b1ea40f2df8b45'
         '0ff7296c3ad99addd6a1ab31b5b8ffb250e1f25f2a8a6ecf2068a'
         'fd5f0c46bc2d810f720b9a')
     returned_hash = scanner_dao._create_violation_hash(
         self.test_violation_full_name, ['aaa', 'bbb', 'ccc'],
         self.test_violation_data)
     self.assertEquals(expected_hash, returned_hash)
Example #3
0
    def test_create_violation_hash_with_invalid_algorithm(self, mock_hashlib):
        """Test _create_violation_hash with an invalid algorithm."""
        mock_hashlib.side_effect = ValueError

        returned_hash = scanner_dao._create_violation_hash(
            self.test_violation_full_name, self.test_inventory_data,
            self.test_violation_data)

        self.assertEqual('', returned_hash)
Example #4
0
    def test_create_violation_hash_invalid_violation_data(self, mock_json):
        """Test _create_violation_hash returns '' when it can't hash."""
        expected_hash = ''

        # Mock json.loads has an error, e.g. invalid violation_data data.:w
        mock_json.side_effect = TypeError()

        returned_hash = scanner_dao._create_violation_hash(
            self.test_violation_full_name, self.test_inventory_data,
            self.test_violation_data)

        self.assertEqual(expected_hash, returned_hash)
Example #5
0
    def test_create_violation_hash_with_default_algorithm(self):
        """Test _create_violation_hash."""
        test_hash = hashlib.new('sha512')
        test_hash.update(
            json.dumps(self.test_violation_full_name) +
            json.dumps(self.test_inventory_data) +
            json.dumps(self.test_violation_data))
        expected_hash = test_hash.hexdigest()

        returned_hash = scanner_dao._create_violation_hash(
            self.test_violation_full_name, self.test_inventory_data,
            self.test_violation_data)

        self.assertEqual(expected_hash, returned_hash)