Esempio n. 1
0
 def test_csproj_path_is_csproj_file(self):
     """Test CsProj.path_is_csproj_file - returns true path is a .csproj file"""
     file_name = "MyProject.csproj"
     with temp_dir() as tmp_root_dir:
         path = os.path.normpath(os.path.join(tmp_root_dir, file_name))
         create_empty_file(path)
         assert CsProj.path_is_csproj_file(path)
Esempio n. 2
0
    def test_cli_uget_pack_with_config_file(
        self, nuget_runner_mock, csproj_mock):
        """Test cli: uget pack with --config-path file"""
        nuget_runner_instance = MagicMock()
        nuget_runner_mock.return_value = nuget_runner_instance
        nuget_runner_mock.valid_nuget_executable.return_value = True
        nuget_runner_mock.locate_nuget.return_value = "custom_nuget.exe"

        csproj_instance = MagicMock()
        csproj_instance.get_assembly_name.return_value = "TestProject"
        csproj_instance.get_assembly_version.return_value = "1.2.3"
        csproj_instance.get_csproj_at_path.return_value = "TestProject.csproj"
        csproj_mock.return_value = csproj_instance
        csproj_mock.get_csproj_at_path.return_value = "TestProject.csproj"

        config_data = {
            "output_dir": "CustomOutput",
            "nuget_path": "custom_nuget.exe",
            "unitypackage_path": "MyUnityPackage.unitypackage",
            "configuration": "Debug",
        }

        runner = CliRunner(env={"NUGET_PATH": None})
        with runner.isolated_filesystem():
            with open('config_test.json', 'w') as f:
                json.dump(config_data, f)

            create_empty_file('MyUnityPackage.unitypackage')
            result = runner.invoke(cli.ugetcli, ['pack', '--config-path', 'config_test.json'], obj={})

        assert result.exit_code == 0, result
        nuget_runner_mock.assert_called_with('custom_nuget.exe', False)
        nuget_runner_instance.pack.assert_called_with(
            ".", "CustomOutput", "Debug", "MyUnityPackage.unitypackage", os.path.normpath("UnityProject/Assets/TestProject"))
Esempio n. 3
0
 def test_csproj_get_csproj_at_path_when_path_contains_csproj(self):
     """Test CsProj.get_csproj_at_path - returns path if path is a file"""
     file_name = "MyProject.csproj"
     with temp_dir() as tmp_root_dir:
         path = os.path.normpath(os.path.join(tmp_root_dir, file_name))
         create_empty_file(path)
         assert CsProj.get_csproj_at_path(tmp_root_dir) == path
Esempio n. 4
0
    def test_cli_uget_push_path_csproj_with_output_dir(self, nuget_runner_mock,
                                                       csproj_mock):
        """Test cli: uget pack with default values when path directly points to .csproj and --output-dir is set"""
        nuget_runner_instance = MagicMock()
        nuget_runner_mock.return_value = nuget_runner_instance
        nuget_runner_mock.locate_nuget.return_value = "nuget.exe"

        csproj_instance = MagicMock()
        csproj_instance.get_assembly_name.return_value = "TestProject"
        csproj_instance.get_assembly_version.return_value = "1.2.3"
        csproj_mock.return_value = csproj_instance
        csproj_mock.get_csproj_at_path.return_value = "TestProject.csproj"

        runner = CliRunner(env={"NUGET_PATH": None, "NUGET_API_KEY": None})
        with runner.isolated_filesystem():
            os.makedirs("MyOutput")
            create_empty_file("MyOutput/TestProject.1.2.3.nupkg")
            result = runner.invoke(cli.ugetcli, [
                'push', '--path', 'TestProject.csproj', '--output-dir',
                'MyOutput'
            ],
                                   obj={})

        assert result.exit_code == 0, result
        nuget_runner_mock.assert_called_with('nuget.exe', False)
        nuget_runner_instance.push.assert_called_with(
            os.path.normpath("MyOutput/TestProject.1.2.3.nupkg"), None, None)
        csproj_mock.get_csproj_at_path.assert_called_with('TestProject.csproj')
Esempio n. 5
0
    def test_cli_uget_push_with_config_file(self, nuget_runner_mock,
                                            csproj_mock):
        """Test cli: uget pack with config file"""
        nuget_runner_instance = MagicMock()
        nuget_runner_mock.return_value = nuget_runner_instance
        nuget_runner_mock.locate_nuget.return_value = "nuget.exe"

        csproj_instance = MagicMock()
        csproj_instance.get_assembly_name.return_value = "TestProject"
        csproj_instance.get_assembly_version.return_value = "1.2.3"
        csproj_mock.return_value = csproj_instance
        csproj_mock.get_csproj_at_path.return_value = "TestProject.csproj"

        config_data = {
            "output_dir": "CustomOutput",
            "feed": "http://test.com/nuget",
            "nuget_path": "custom_nuget.exe",
            "api_key": "myapikey123"
        }

        runner = CliRunner(env={"NUGET_PATH": None, "NUGET_API_KEY": None})
        with runner.isolated_filesystem():
            with open('config_test.json', 'w') as f:
                json.dump(config_data, f)
            os.makedirs("CustomOutput")
            create_empty_file("CustomOutput/TestProject.1.2.3.nupkg")
            result = runner.invoke(
                cli.ugetcli, ['push', '--config-path', 'config_test.json'],
                obj={})

        assert result.exit_code == 0, result
        nuget_runner_mock.assert_called_with('custom_nuget.exe', False)
        nuget_runner_instance.push.assert_called_with(
            os.path.normpath("CustomOutput/TestProject.1.2.3.nupkg"),
            "http://test.com/nuget", "myapikey123")
Esempio n. 6
0
    def test_cli_uget_push_with_api_key_env(self, nuget_runner_mock,
                                            csproj_mock):
        """Test cli: uget pack with API_KEY env variable"""
        nuget_runner_instance = MagicMock()
        nuget_runner_mock.return_value = nuget_runner_instance
        nuget_runner_mock.locate_nuget.return_value = "nuget.exe"

        csproj_instance = MagicMock()
        csproj_instance.get_assembly_name.return_value = "TestProject"
        csproj_instance.get_assembly_version.return_value = "1.2.3"
        csproj_mock.return_value = csproj_instance
        csproj_mock.get_csproj_at_path.return_value = "TestProject.csproj"

        runner = CliRunner(env={
            "NUGET_PATH": None,
            "NUGET_API_KEY": "myapikey"
        })
        with runner.isolated_filesystem():
            os.mkdir("Output")
            create_empty_file("Output/TestProject.1.2.3.nupkg")
            result = runner.invoke(cli.ugetcli, ['push'], obj={})

        assert result.exit_code == 0, result
        nuget_runner_mock.assert_called_with('nuget.exe', False)
        nuget_runner_instance.push.assert_called_with(
            os.path.normpath("Output/TestProject.1.2.3.nupkg"), None,
            "myapikey")
Esempio n. 7
0
 def export_unitypackage_mock(*args, **kwargs):
     assert 'UnityProject' in args[0]  # In temp folder
     assert args[0] == os.path.normpath(
         'UnityProject/Assets/TestProject')
     assert args[1] == os.path.normpath(
         'Output/TestProject_1.0.0_Release.unitypackage')
     create_empty_file(args[1])
     invocation_results[0] = True
     return 0
Esempio n. 8
0
 def export_unitypackage_mock(*args, **kwargs):
     assert 'CustomUnityProject' in args[0]  # In temp folder
     assert os.path.normpath(
         'CustomUnityProject/Assets/MyUnityPackage') in args[0]
     assert os.path.normpath(
         'CustomOutput/TestProject_1.0.0_Debug.unitypackage') in args[1]
     create_empty_file(args[1])
     invocation_results[0] = True
     return 0
Esempio n. 9
0
    def test_cli_uget_create_with_clean(self, unitypackage_runner_mock,
                                        csproj_mock):
        """Test cli: uget create with --clean"""

        invocation_results = [False]

        # Mock running Unity to export unity package
        def export_unitypackage_mock(*args, **kwargs):
            assert 'UnityProject' in args[0]  # In temp folder
            assert args[0] == os.path.normpath(
                'UnityProject/Assets/TestProject')
            assert args[1] == os.path.normpath(
                'Output/TestProject_1.0.0_Release.unitypackage')
            create_empty_file(args[1])
            invocation_results[0] = True
            return 0

        unitypackage_runner_instance = MagicMock()
        unitypackage_runner_instance.export_unitypackage = export_unitypackage_mock
        unitypackage_runner_mock.return_value = unitypackage_runner_instance

        csproj_instance = MagicMock()
        csproj_instance.get_assembly_name.return_value = "TestProject"
        csproj_instance.get_assembly_version.return_value = "1.0.0"
        csproj_instance.get_output_path.return_value = "bin/Output/Debug"
        csproj_instance.path = "TestProject.csproj"
        csproj_mock.return_value = csproj_instance

        runner = CliRunner(env={})
        with runner.isolated_filesystem():
            os.makedirs("bin/Output/Debug")
            create_empty_file("bin/Output/Debug/TestProject.dll")
            create_empty_file("bin/Output/Debug/TestProject.pdb")
            os.makedirs("Output/")
            create_empty_file("Output/TestProject_0.1.0_Release.unitypackage"
                              )  # Should be removed
            create_empty_file("Output/TestProject_0.1.1_Release.unitypackage"
                              )  # Should be removed
            create_empty_file("Output/TestProject_0.1.0_Debug.unitypackage"
                              )  # Should NOT be removed
            result = runner.invoke(cli.ugetcli, ['create', '--clean'], obj={})

            assert not os.path.isfile(
                "Output/TestProject_0.1.0_Release.unitypackage")
            assert not os.path.isfile(
                "Output/TestProject_0.1.1_Release.unitypackage")
            assert os.path.isfile(
                "Output/TestProject_0.1.0_Debug.unitypackage")

        assert result.exit_code == 0, result
        unitypackage_runner_mock.assert_called_with(False)
        assert invocation_results[0], "did not invoke export_unitypackage_mock"
Esempio n. 10
0
 def test_msbuild_runner_locate_msbuild_when_dotnet_framework_installed_win32(self, mock_call, mock_sys):
     """Test MsBuildRunner.locate_msbuild - returns msbuild path in the local system using .NET Framework path """
     if sys.platform != 'win32': # TODO: Fix unit test compatibility on non-windows platform
         return
     mock_call.return_value = 0
     mock_sys.configure_mock(platform='win32')
     vs_msbuild_dir = os.path.normpath("Microsoft.NET\\Framework\\1.0\\")
     msbuild_name = "MSBuild.exe"
     with temp_dir() as tmp_root_dir:
         from ugetcli import msbuild
         with patch.dict(msbuild.os.environ, {'ProgramFiles': tmp_root_dir, 'WINDIR': tmp_root_dir}, clear=True):
             msbuild_dir_path = os.path.join(tmp_root_dir, vs_msbuild_dir)
             os.makedirs(msbuild_dir_path)
             msbuild_path = os.path.join(msbuild_dir_path, msbuild_name)
             create_empty_file(msbuild_path)
             assert MsBuildRunner.locate_msbuild() == msbuild_path
Esempio n. 11
0
    def test_cli_uget_push_path_nupkg(self, nuget_runner_mock):
        """Test cli: uget pack with default values when path points to a .nupkg file"""
        nuget_runner_instance = MagicMock()
        nuget_runner_mock.return_value = nuget_runner_instance
        nuget_runner_mock.locate_nuget.return_value = "nuget.exe"

        runner = CliRunner(env={"NUGET_PATH": None, "NUGET_API_KEY": None})
        with runner.isolated_filesystem():
            create_empty_file("myproject.nupkg")
            result = runner.invoke(cli.ugetcli,
                                   ['push', '--path', 'myproject.nupkg'],
                                   obj={})

        assert result.exit_code == 0, result
        nuget_runner_mock.assert_called_with('nuget.exe', False)
        nuget_runner_instance.push.assert_called_with(
            os.path.normpath("myproject.nupkg"), None, None)
Esempio n. 12
0
 def test_msbuild_build_with_rebuild(self, mock_popen, mock_escape_exe_path):
     """Test MsBuildRunner.build - rebuilds .csproj """
     mock_process_instance = MagicMock()
     mock_popen.return_value = mock_process_instance
     mock_process_instance.wait.return_value = 0
     mock_escape_exe_path.return_value = "msbuild.exe"
     with temp_dir() as tmp_root_dir:
         msbuild_path = os.path.join(tmp_root_dir, "msbuild.exe")
         project_path = os.path.join(tmp_root_dir, "Project.csproj")
         create_empty_file(msbuild_path)
         create_empty_file(project_path)
         configuration = "Debug"
         msbuild = MsBuildRunner(msbuild_path)
         msbuild.build(project_path, configuration, True)
         expected_command = 'msbuild.exe {project_path} /t:Clean,Build /p:"Configuration={configuration}" /p:"DebugType=full"' \
                            ' /verbosity:{verbosity}'.format(project_path=project_path, configuration=configuration,
                                                             verbosity="minimal")
         mock_popen.assert_called_with(expected_command, shell=True)
         mock_process_instance.wait.assert_called()
Esempio n. 13
0
    def test_cli_uget_pack_with_unitypackage_path(
        self, nuget_runner_mock, csproj_mock):
        """Test cli: uget pack with --unitypackage-path"""
        nuget_runner_instance = MagicMock()
        nuget_runner_mock.return_value = nuget_runner_instance
        nuget_runner_mock.valid_nuget_executable.return_value = True
        nuget_runner_mock.locate_nuget.return_value = "nuget.exe"

        csproj_instance = MagicMock()
        csproj_instance.get_assembly_name.return_value = "TestProject"
        csproj_instance.get_assembly_version.return_value = "1.2.3"
        csproj_mock.return_value = csproj_instance
        csproj_mock.get_csproj_at_path.return_value = "TestProject.csproj"

        runner = CliRunner(env={"NUGET_PATH": None})
        with runner.isolated_filesystem():
            create_empty_file('MyUnityPackage.unitypackage')
            result = runner.invoke(cli.ugetcli, ['pack', '--unitypackage-path', 'MyUnityPackage.unitypackage'], obj={})

        assert result.exit_code == 0, result
        nuget_runner_mock.assert_called_with('nuget.exe', False)
        nuget_runner_instance.pack.assert_called_with(
            ".", "Output", "Release", "MyUnityPackage.unitypackage", os.path.normpath("UnityProject/Assets/TestProject"))
Esempio n. 14
0
    def test_cli_uget_create_with_config_json(self, unitypackage_runner_mock,
                                              csproj_mock):
        """Test cli: uget create with options loaded via config json"""

        invocation_results = [False]

        # Mock running Unity to export unity package
        def export_unitypackage_mock(*args, **kwargs):
            assert 'CustomUnityProject' in args[0]  # In temp folder
            assert os.path.normpath(
                'CustomUnityProject/Assets/MyUnityPackage') in args[0]
            assert os.path.normpath(
                'CustomOutput/TestProject_1.0.0_Debug.unitypackage') in args[1]
            create_empty_file(args[1])
            invocation_results[0] = True
            return 0

        unitypackage_runner_instance = MagicMock()
        unitypackage_runner_instance.export_unitypackage = export_unitypackage_mock
        unitypackage_runner_mock.return_value = unitypackage_runner_instance

        csproj_instance = MagicMock()
        csproj_instance.get_assembly_name.return_value = "TestProject"
        csproj_instance.get_assembly_version.return_value = "1.0.0"
        csproj_instance.get_output_path.return_value = "bin/Output/Debug"
        csproj_instance.path = "TestProject.csproj"
        csproj_mock.return_value = csproj_instance

        config_data = {
            "output_dir": "CustomOutput",
            "configuration": "Debug",
            "unity_project_path": "CustomUnityProject",
            "root_dir": "MyUnityPackage",
            "clean": True,
        }

        runner = CliRunner(env={})
        with runner.isolated_filesystem():
            os.makedirs("bin/Output/Debug")
            create_empty_file("bin/Output/Debug/TestProject.dll")
            create_empty_file("bin/Output/Debug/TestProject.pdb")
            os.makedirs("CustomOutput/")
            create_empty_file(
                "CustomOutput/TestProject_0.1.0_Release.unitypackage"
            )  # Should be removed

            result = runner.invoke(
                cli.ugetcli, ['create', '--config',
                              json.dumps(config_data)],
                obj={})

            assert not os.path.isfile(
                "Output/TestProject_0.1.0_Release.unitypackage")

        assert result.exit_code == 0, result
        unitypackage_runner_mock.assert_called_with(False)
        assert invocation_results[0], "did not invoke export_unitypackage_mock"