Example #1
0
def test_get_code_file():
    # Test integration case
    unifier = Unifier(f"{git_path()}/demisto_sdk/tests/test_files/VulnDB/")
    assert unifier.get_code_file(".py") == f"{git_path()}/demisto_sdk/tests/test_files/VulnDB/VulnDB.py"
    unifier = Unifier(f"{git_path()}/demisto_sdk/tests/test_files/Unifier/SampleNoPyFile")
    with pytest.raises(Exception):
        unifier.get_code_file(".py")
    # Test script case
    unifier = Unifier(f"{git_path()}/demisto_sdk/tests/test_files/CalculateGeoDistance/")
    assert unifier.get_code_file(".py") == f"{git_path()}/demisto_sdk/tests/test_files/CalculateGeoDistance/" \
                                           f"CalculateGeoDistance.py"
Example #2
0
    def check_api_module_imports(self, py_num):
        """
        Checks if the integration imports an API module and if so pastes the module in the package.
        :param py_num: The python version - api modules are in python 3
        """
        if py_num > 3:
            unifier = Unifier(self.project_dir)
            code_file_path = unifier.get_code_file('.py')

            try:
                # Look for an import to an API module in the code. If there is such import, we need to copy the correct
                # module file to the package directory.
                with io.open(code_file_path, mode='r',
                             encoding='utf-8') as script_file:
                    _, module_name = unifier.check_api_module_imports(
                        script_file.read())
                if module_name:
                    module_path = os.path.join(self.configuration.env_dir,
                                               'Packs', 'ApiModules',
                                               'Scripts', module_name,
                                               module_name + '.py')
                    print_v('Copying ' + os.path.join(
                        self.configuration.env_dir, 'Scripts', module_path))
                    if not os.path.exists(module_path):
                        raise ValueError(
                            'API Module {} not found, you might be outside of the content repository'
                            ' or this API module does not exist'.format(
                                module_name))
                    shutil.copy(os.path.join(module_path), self.project_dir)
            except Exception as e:
                print_v('Unable to retrieve the module file {}: {}'.format(
                    module_name, str(e)))
Example #3
0
def test_get_code_file_case_insensative(tmp_path):
    # Create an integration dir with some files
    integration_dir = tmp_path / "TestDummyInt"
    os.makedirs(integration_dir)
    open(integration_dir / "Dummy.ps1", 'a')
    open(integration_dir / "ADummy.tests.ps1", 'a')  # a test file which is named such a way that it comes up first
    unifier = Unifier(str(integration_dir))
    assert unifier.get_code_file(".ps1") == str(integration_dir / "Dummy.ps1")
Example #4
0
 def _get_lint_files(self):
     unifier = Unifier(self.project_dir)
     code_file = unifier.get_code_file('.py')
     return os.path.abspath(code_file)
Example #5
0
 def _get_lint_files(self):
     unifier = Unifier(self.project_dir)
     code_file = unifier.get_code_file(TYPE_TO_EXTENSION[self.script_type])
     return os.path.abspath(code_file)