Example #1
0
    def test_get_forge_for_mc_bad_ver(self, forge_versions):
        """
        Tests that we handle when an unsupported MC version is given
        """

        forge_versions.return_value = []

        get_forge_for_mc_version('1.8.9')
Example #2
0
    def test_get_forge_for_mc_network1(self, requests_get):
        """
        Tests that we handle when there's a networking problem getting the list
        """

        mock_response = unittest.mock.Mock(spec = requests.Response)
        mock_response.ok = False

        requests_get.return_value = mock_response

        get_forge_for_mc_version('1.8.9')
Example #3
0
    def test_get_forge_for_mc_network2(self, versions, requests_get):
        """
        Tests that we handle when there's a networking problem getting the jar
        """

        versions.return_value = ['1.8.9']

        mock_list_response = unittest.mock.Mock(spec = requests.Response)
        mock_list_response.ok      = True
        mock_list_response.content = SAMPLE_DOWNLOADS_PAGE.format('LATEST')

        mock_jar_response = unittest.mock.Mock(spec = requests.Response)
        mock_jar_response.ok = False

        requests_get.side_effect = [
            mock_list_response,
            mock_jar_response,
        ]

        get_forge_for_mc_version('1.8.9')
Example #4
0
    def _do_forge_for_mc(self, release, path = None):
        root       = path if path is not None else os.getcwd()
        version_id = '1.8.9'

        with unittest.mock.patch('mymcadmin.forge.get_forge_mc_versions') as forge_versions, \
             unittest.mock.patch('requests.get') as requests_get, \
             unittest.mock.patch('mymcadmin.utils.download_file') as download_file:
            forge_versions.return_value = ['1.8.9']

            mock_version_response = unittest.mock.Mock(spec = requests.Response)
            mock_version_response.ok      = True
            mock_version_response.content = SAMPLE_DOWNLOADS_PAGE.format(release)

            mock_inst_jar_response = unittest.mock.Mock(spec = requests.Response)
            mock_inst_jar_response.ok = True

            mock_uni_jar_response = unittest.mock.Mock(spec = requests.Response)
            mock_uni_jar_response.ok = True

            requests_get.side_effect = [
                mock_version_response,
                mock_inst_jar_response,
                mock_uni_jar_response,
            ]

            inst_jar_path, uni_jar_path = get_forge_for_mc_version(
                version_id,
                path = path,
            )

            self.assertEqual(
                os.path.join(root, 'forge-1.8.9-10.10.10.10-installer.jar'),
                inst_jar_path,
                'Installer path did not match expected',
            )

            self.assertEqual(
                os.path.join(root, 'forge-1.8.9-10.10.10.10-universal.jar'),
                uni_jar_path,
                'Jar path did not match expected',
            )

            # pylint: disable=line-too-long
            requests_get.assert_has_calls(
                [
                    unittest.mock.call(
                        'http://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.8.9.html',
                    ),
                    unittest.mock.call(
                        'http://example.com/10.10.10.10/forge-1.8.9-10.10.10.10-installer.jar',
                        stream = True,
                    ),
                    unittest.mock.call(
                        'http://example.com/10.10.10.10/forge-1.8.9-10.10.10.10-universal.jar',
                        stream = True,
                    ),
                ]
            )
            # pylint: enable=line-too-long

        download_file.assert_has_calls(
            [
                unittest.mock.call(
                    mock_inst_jar_response,
                    inst_jar_path,
                    '943a702d06f34599aee1f8da8ef9f7296031d699',
                ),
                unittest.mock.call(
                    mock_uni_jar_response,
                    uni_jar_path,
                    '943a702d06f34599aee1f8da8ef9f7296031d699',
                )
            ]
        )