superset/tests/unit_tests/advanced_data_type/types_tests.py

563 lines
19 KiB
Python
Raw Normal View History

feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
# isort:skip_file
"""Unit tests for Superset"""
import sqlalchemy
from sqlalchemy import Column, Integer
from superset.advanced_data_type.types import (
AdvancedDataTypeRequest,
AdvancedDataTypeResponse,
)
from superset.utils.core import FilterOperator, FilterStringOperators
from superset.advanced_data_type.plugins.internet_address import internet_address
from superset.advanced_data_type.plugins.internet_port import internet_port as port
# To run the unit tests below, use the following command in the root Superset folder:
# tox -e py38 -- tests/unit_tests/advanced_data_type/types_tests.py
def test_ip_func_valid_ip():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_func behaves as expected when a valid IP is passed in"""
cidr_request: AdvancedDataTypeRequest = {
"advanced_data_type": "cidr",
"values": ["1.1.1.1"],
}
cidr_response: AdvancedDataTypeResponse = {
"values": [16843009],
"error_message": "",
"display_value": "16843009",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}
assert internet_address.translate_type(cidr_request) == cidr_response
def test_cidr_func_invalid_ip():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_func behaves as expected when an invalid IP is passed in"""
cidr_request: AdvancedDataTypeRequest = {
"advanced_data_type": "cidr",
"values": ["abc"],
}
cidr_response: AdvancedDataTypeResponse = {
"values": [],
"error_message": "'abc' does not appear to be an IPv4 or IPv6 network",
"display_value": "",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}
assert internet_address.translate_type(cidr_request) == cidr_response
def test_cidr_func_empty_ip():
"""Test to see if the cidr_func behaves as expected when no IP is passed in"""
cidr_request: AdvancedDataTypeRequest = {
"advanced_data_type": "cidr",
"values": [""],
}
cidr_response: AdvancedDataTypeResponse = {
"values": [""],
"error_message": "",
"display_value": "",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}
assert internet_address.translate_type(cidr_request) == cidr_response
def test_port_translation_func_valid_port_number():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translation_func behaves as expected when a valid port number
is passed in"""
port_request: AdvancedDataTypeRequest = {
"advanced_data_type": "port",
"values": ["80"],
}
port_response: AdvancedDataTypeResponse = {
"values": [[80]],
"error_message": "",
"display_value": "[80]",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}
assert port.translate_type(port_request) == port_response
def test_port_translation_func_valid_port_name():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translation_func behaves as expected when a valid port name
is passed in"""
port_request: AdvancedDataTypeRequest = {
"advanced_data_type": "port",
"values": ["https"],
}
port_response: AdvancedDataTypeResponse = {
"values": [[443]],
"error_message": "",
"display_value": "[443]",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}
assert port.translate_type(port_request) == port_response
def test_port_translation_func_invalid_port_name():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translation_func behaves as expected when an invalid port name
is passed in"""
port_request: AdvancedDataTypeRequest = {
"advanced_data_type": "port",
"values": ["abc"],
}
port_response: AdvancedDataTypeResponse = {
"values": [],
"error_message": "'abc' does not appear to be a port name or number",
"display_value": "",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}
assert port.translate_type(port_request) == port_response
def test_port_translation_func_invalid_port_number():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translation_func behaves as expected when an invalid port
number is passed in"""
port_request: AdvancedDataTypeRequest = {
"advanced_data_type": "port",
"values": ["123456789"],
}
port_response: AdvancedDataTypeResponse = {
"values": [],
"error_message": "'123456789' does not appear to be a port name or number",
"display_value": "",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}
assert port.translate_type(port_request) == port_response
def test_port_translation_func_empty_port_number():
"""Test to see if the port_translation_func behaves as expected when no port
number is passed in"""
port_request: AdvancedDataTypeRequest = {
"advanced_data_type": "port",
"values": [""],
}
port_response: AdvancedDataTypeResponse = {
"values": [[""]],
"error_message": "",
"display_value": "",
"valid_filter_operators": [
FilterStringOperators.EQUALS,
FilterStringOperators.GREATER_THAN_OR_EQUAL,
FilterStringOperators.GREATER_THAN,
FilterStringOperators.IN,
FilterStringOperators.LESS_THAN,
FilterStringOperators.LESS_THAN_OR_EQUAL,
],
}
assert port.translate_type(port_request) == port_response
def test_cidr_translate_filter_func_equals():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the EQUALS
operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.EQUALS
input_values = [16843009]
cidr_translate_filter_response = input_column == input_values[0]
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_cidr_translate_filter_func_not_equals():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the NOT_EQUALS
operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.NOT_EQUALS
input_values = [16843009]
cidr_translate_filter_response = input_column != input_values[0]
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_cidr_translate_filter_func_greater_than_or_equals():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the
GREATER_THAN_OR_EQUALS operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.GREATER_THAN_OR_EQUALS
input_values = [16843009]
cidr_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column >= input_values[0]
)
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_cidr_translate_filter_func_greater_than():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the
GREATER_THAN operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.GREATER_THAN
input_values = [16843009]
cidr_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column > input_values[0]
)
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_cidr_translate_filter_func_less_than():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the LESS_THAN
operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.LESS_THAN
input_values = [16843009]
cidr_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column < input_values[0]
)
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_cidr_translate_filter_func_less_than_or_equals():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the
LESS_THAN_OR_EQUALS operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.LESS_THAN_OR_EQUALS
input_values = [16843009]
cidr_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column <= input_values[0]
)
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_cidr_translate_filter_func_in_single():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the IN operator
is used with a single IP"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.IN
input_values = [16843009]
cidr_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column.in_(input_values)
)
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_cidr_translate_filter_func_in_double():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the IN operator
is used with two IP's"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.IN
input_values = [{"start": 16843009, "end": 33686018}]
input_condition = input_column.in_([])
cidr_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_condition | ((input_column <= 33686018) & (input_column >= 16843009))
)
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_cidr_translate_filter_func_not_in_single():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the NOT_IN
operator is used with a single IP"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.NOT_IN
input_values = [16843009]
cidr_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = ~(
input_column.in_(input_values)
)
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_cidr_translate_filter_func_not_in_double():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the cidr_translate_filter_func behaves as expected when the NOT_IN
operator is used with two IP's"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.NOT_IN
input_values = [{"start": 16843009, "end": 33686018}]
input_condition = ~(input_column.in_([]))
cidr_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_condition & (input_column > 33686018) & (input_column < 16843009)
)
assert internet_address.translate_filter(
input_column, input_operation, input_values
).compare(cidr_translate_filter_response)
def test_port_translate_filter_func_equals():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the EQUALS
operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.EQUALS
input_values = [[443]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column.in_(input_values[0])
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)
def test_port_translate_filter_func_not_equals():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the NOT_EQUALS
operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.NOT_EQUALS
input_values = [[443]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = ~(
input_column.in_(input_values[0])
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)
def test_port_translate_filter_func_greater_than_or_equals():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the
GREATER_THAN_OR_EQUALS operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.GREATER_THAN_OR_EQUALS
input_values = [[443]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column >= input_values[0][0]
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)
def test_port_translate_filter_func_greater_than():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the
GREATER_THAN operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.GREATER_THAN
input_values = [[443]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column > input_values[0][0]
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)
def test_port_translate_filter_func_less_than_or_equals():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the
LESS_THAN_OR_EQUALS operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.LESS_THAN_OR_EQUALS
input_values = [[443]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column <= input_values[0][0]
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)
def test_port_translate_filter_func_less_than():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the LESS_THAN
operator is used"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.LESS_THAN
input_values = [[443]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column < input_values[0][0]
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)
def test_port_translate_filter_func_in_single():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the IN operator
is used with a single port"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.IN
input_values = [[443]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column.in_(input_values[0])
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)
def test_port_translate_filter_func_in_double():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the IN operator
is used with two ports"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.IN
input_values = [[443, 80]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = (
input_column.in_(input_values[0])
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)
def test_port_translate_filter_func_not_in_single():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the NOT_IN
operator is used with a single port"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.NOT_IN
input_values = [[443]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = ~(
input_column.in_(input_values[0])
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)
def test_port_translate_filter_func_not_in_double():
feat(business-types): initial implementation of SIP-78 (#18794) * add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
2022-05-16 10:58:21 -04:00
"""Test to see if the port_translate_filter_func behaves as expected when the NOT_IN
operator is used with two ports"""
input_column = Column("user_ip", Integer)
input_operation = FilterOperator.NOT_IN
input_values = [[443, 80]]
port_translate_filter_response: sqlalchemy.sql.expression.BinaryExpression = ~(
input_column.in_(input_values[0])
)
assert port.translate_filter(input_column, input_operation, input_values).compare(
port_translate_filter_response
)