Files
monasca-api/monasca_api/tests/db/test_fingerprint.py
Hasan Acar a24fd834d0 fix: migrate CI to jammy
fix: change tox.ini

fix: change queries for list_dimension_names and list_dimension_values because of influxdb time filter problem

fix: remove build_sphinx group from setup.cfg

fix: handle hashlib security problem

Change-Id: I0d31a8db5ed71c70e7b878ce5e7940e041d0fa43

Change-Id: I6f7066da10e834550cbf0c053c7bf425ac0ead93

Change-Id: If9575aee73d600bbc84fcdf58deb1c57b508d9c2

Change-Id: If515eaeee7539da3ca49997e88785dc65572b334
2024-02-22 14:35:03 +00:00

66 lines
2.7 KiB
Python

# Copyright 2018 StackHPC Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import hashlib
from unittest import mock
import monasca_api.db.fingerprint as fingerprint
from monasca_api.tests import base
class TestFingerprint(base.BaseTestCase):
@mock.patch('monasca_api.db.fingerprint.Fingerprint._get_metadata')
@mock.patch('monasca_api.db.fingerprint.Fingerprint._get_schema_raw')
def test_get_schema_raw_pre_alembic(self, mock_schema_raw, mock_metadata):
mock_schema_raw.return_value = 'dummy_schema_raw'
tables = mock.PropertyMock = {
'dummy_table': 'dummy_columns'
}
mock_metadata.return_value.tables = tables
# No Alembic revision ID exists in the DB so we look it up from the
# table of fingerprints. Since we use a dummy schema, we insert a dummy
# entry into the lookup table.
fingerprint._REVS[
hashlib.sha256(b'dummy_schema_raw').hexdigest()] = 'dummy_revision'
f = fingerprint.Fingerprint('mock_engine')
self.assertEqual(f.schema_raw, 'dummy_schema_raw')
self.assertEqual(f.sha256, hashlib.sha256(b'dummy_schema_raw').hexdigest())
self.assertEqual(f.revision, 'dummy_revision')
@mock.patch('monasca_api.db.fingerprint.Fingerprint._get_db_session')
@mock.patch('monasca_api.db.fingerprint.Fingerprint._get_metadata')
@mock.patch('monasca_api.db.fingerprint.Fingerprint._get_schema_raw')
def test_get_schema_raw_post_alembic(
self, mock_schema_raw, mock_metadata, mock_db_session):
mock_schema_raw.return_value = 'dummy_schema_raw'
tables = mock.PropertyMock = {
'alembic_version': 'dummy_version',
'dummy_table': 'dummy_columns'
}
mock_metadata.return_value.tables = tables
# Alembic sets the version in the DB, so we look it up from there
mock_db_session.return_value.query.return_value.one.return_value = (
'dummy_revision',)
f = fingerprint.Fingerprint('mock_engine')
self.assertEqual(f.schema_raw, 'dummy_schema_raw')
self.assertEqual(f.sha256, hashlib.sha256(b'dummy_schema_raw').hexdigest())
self.assertEqual(f.revision, 'dummy_revision')