from unittest.mock import patch import pytest from django.conf import settings from license_info.tools import check_features LICENSE_FEATURE_EVENT_PROCESSING = getattr(settings, 'LICENSE_FEATURE_EVENT_PROCESSING') FULL_LICENSE = {"uuid": "5fcda3dd-8b32-47cd-96d4-1b39f68cf2f3", "hardware": "f5fbe2bd-872c-31f6-9af2-2b8eccdd9dd1", "customer": "Developers", "product": "ARMA Console", "type": "ENTERPRISE", "features": ["event_processing"], "options": {"event_sources": "100"}, "evaluationStart": "2021-08-26T19:58:03.674613245Z", "evaluationEnd": "2021-09-25T19:58:03.674613245Z"} MIN_LICENSE = {"uuid": "5fcda3dd-8b32-47cd-96d4-1b39e88a2910", "hardware": "f5fbe2bd-872c-31f6-9af2-2b8eccdd9dd1", "customer": "Developers", "product": "ARMA Console", "type": "ENTERPRISE", "features": [], "options": {}, "evaluationStart": "2021-08-30T20:04:39.804548860Z", "evaluationEnd": "2021-09-29T20:04:39.804548860Z"} class TestTools: @pytest.mark.unit @patch("license_info.tools.get_license_info") def test_check_features_has_feature(self, mock_function): mock_function.return_value = FULL_LICENSE assert check_features(LICENSE_FEATURE_EVENT_PROCESSING) @pytest.mark.unit @patch("license_info.tools.get_license_info") def test_check_features_has_no_feature(self, mock_function): mock_function.return_value = MIN_LICENSE assert check_features(LICENSE_FEATURE_EVENT_PROCESSING) is False @pytest.mark.unit @patch("license_info.tools.get_license_info") def test_check_feature_no_license(self, mock_function): mock_function.return_value = None assert check_features(LICENSE_FEATURE_EVENT_PROCESSING) is False