Skip to content

Commit

Permalink
Merge pull request #28 from RedHatInsights/engine-unit-tests
Browse files Browse the repository at this point in the history
Init unit test
  • Loading branch information
tisnik authored Feb 23, 2022
2 parents ce41141 + 573faf8 commit d3b1333
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Binary file added test/correct_data.tar
Binary file not shown.
74 changes: 74 additions & 0 deletions test/engines/sha_extractor_engine_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2022 Red Hat, Inc
#
# 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.

"""Module for testing the engines module."""

from pythonjsonlogger import jsonlogger
import pytest

from ccx_messaging.engines.sha_extractor_engine import SHAExtractorEngine

def test_init():
"""Test the SHAExtractorEngine constructor."""

formatter = jsonlogger
e = SHAExtractorEngine(formatter)

# just basic check
assert e is not None


def test_process_no_extract():
"""Basic test for SHAExtractorEngine."""

formatter = jsonlogger
e = SHAExtractorEngine(formatter)
e.watchers = []
e.extract_tmp_dir = "not-exist"

broker = None
path = "not-exist"

with pytest.raises(Exception):
e.process(broker, path)


def test_process_extract_wrong_data():
"""Basic test for SHAExtractorEngine."""

formatter = jsonlogger
e = SHAExtractorEngine(formatter)
e.watchers = []
e.extract_tmp_dir = ""

broker = None
path = "test/wrong_data.tar"

result = e.process(broker, path)
assert result is None


def test_process_extract_correct_data():
"""Basic test for SHAExtractorEngine."""

formatter = jsonlogger
e = SHAExtractorEngine(formatter)
e.watchers = []
e.extract_tmp_dir = ""

broker = None
path = "test/correct_data.tar"

result = e.process(broker, path)
assert result is not None
Binary file added test/wrong_data.tar
Binary file not shown.

0 comments on commit d3b1333

Please sign in to comment.