def test_import(self): local = fileVersionManagement.SubModVersionInfo( TestSubModVersion.localJSON) remote = fileVersionManagement.SubModVersionInfo( TestSubModVersion.remoteJSON) result = fileVersionManagement.SubModVersionInfo.getFilesNeedingInstall( local, remote) self.assertEqual( stripReason(result), { 'cg': False, 'cgalt': True, 'movie': True, 'voices': True, 'script': True })
def test_voice_partial_install_full_then_voice(self): local = fileVersionManagement.SubModVersionInfo( TestSubModVersion.voiceWithFullPartiallyInstalledJSON) remote = fileVersionManagement.SubModVersionInfo( TestSubModVersion.voiceOnlyJSON) result = fileVersionManagement.SubModVersionInfo.getFilesNeedingInstall( local, remote) self.assertEqual( stripReason(result), { 'cg': True, 'cgalt': True, 'movie': True, 'voices': True, 'script': True })
def test_highLevelFunctions(self): remoteSubModVersionJSONString = """ { "id" : "Onikakushi Ch.1/full", "files":[ {"id": "cg", "version": "1.0.0"}, {"id": "cgalt", "version": "1.0.0"}, {"id": "movie", "version": "1.0.0"}, {"id": "voices", "version": "1.0.0"}, {"id": "script", "version": "6.1.0"}, {"id": "movie-unix", "version": "1.0.0"}, {"id": "ui-windows", "version": "1.0.0"}, {"id": "ui-unix", "version": "1.0.0"} ] } """ remoteVersionObject = fileVersionManagement.SubModVersionInfo( json.loads(remoteSubModVersionJSONString)) test_dir = tempfile.mkdtemp() modList = self.getModListFromDummyJSON() mod = modList[0] submod = mod['submods'][0] subModConfig = installConfiguration.SubModConfig(mod, submod) fullConfig = installConfiguration.FullInstallConfiguration( subModConfig, test_dir, True) originalModFileList = fullConfig.buildFileListSorted('datadir') # If there is no file present, all files should require download fileVersionManager = fileVersionManagement.VersionManager( subMod=subModConfig, modFileList=originalModFileList, localVersionFolder=test_dir, _testRemoteSubModVersion=remoteVersionObject) self.assertEqual(fileVersionManager.getFilesRequiringUpdate(), originalModFileList) self.assertEqual(fileVersionManager.fullUpdateRequired(), True) fileVersionManager.saveVersionInstallFinished() # If there is a file present which is identical, no files should require download fileVersionManagerIdentical = fileVersionManagement.VersionManager( subMod=subModConfig, modFileList=originalModFileList, localVersionFolder=test_dir, _testRemoteSubModVersion=remoteVersionObject) self.assertEqual(fileVersionManagerIdentical.getFilesRequiringUpdate(), []) self.assertEqual(fileVersionManagerIdentical.fullUpdateRequired(), False) shutil.rmtree(test_dir)
def test_filterFileListInner(self): modList = self.getModListFromDummyJSON() mod = modList[0] submod = mod['submods'][0] subModConfig = installConfiguration.SubModConfig(mod, submod) fullConfig = installConfiguration.FullInstallConfiguration(subModConfig, '.', True) fileList = fullConfig.buildFileListSorted('datadir') # Test if versions have not changed unchangedTestSet = (json.loads(""" { "id" : "Onikakushi Ch.1/full", "lastAttemptedInstallID" : "Onikakushi Ch.1/full", "files":[ {"id": "cg", "version": "1.0.0"}, {"id": "cgalt", "version": "1.0.0"}, {"id": "movie", "version": "1.0.0"}, {"id": "voices", "version": "1.0.0"}, {"id": "script", "version": "6.1.0"}, {"id": "ui-windows", "version": "2.1.0"} ] } """), json.loads(""" { "id" : "Onikakushi Ch.1/full", "lastAttemptedInstallID" : "Onikakushi Ch.1/full", "files":[ {"id": "cg", "version": "1.0.0"}, {"id": "cgalt", "version": "1.0.0"}, {"id": "movie", "version": "1.0.0"}, {"id": "voices", "version": "1.0.0"}, {"id": "script", "version": "6.1.0"}, {"id": "ui-windows", "version": "2.1.0"} ] } """)) updateInformation = fileVersionManagement.getFilesNeedingUpdate(fileList, fileVersionManagement.SubModVersionInfo(unchangedTestSet[0]), fileVersionManagement.SubModVersionInfo(unchangedTestSet[1])) result = convertUpdateInformationToModFileList(fileList, updateInformation) self.assertEqual(result, []) print("Unchanged", [x.id for x in result]) # Test if 'cg' version changes, that both 'cg' and 'script' need update dependencyTestSet = (json.loads(""" { "id" : "Onikakushi Ch.1/full", "lastAttemptedInstallID" : "Onikakushi Ch.1/full", "files":[ {"id": "cg", "version": "1.0.0"}, {"id": "cgalt", "version": "1.0.0"}, {"id": "movie", "version": "1.0.0"}, {"id": "voices", "version": "1.0.0"}, {"id": "script", "version": "6.1.0"}, {"id": "ui-windows", "version": "2.1.0"} ] } """), json.loads(""" { "id" : "Onikakushi Ch.1/full", "lastAttemptedInstallID" : "Onikakushi Ch.1/full", "files":[ {"id": "cg", "version": "1.0.1"}, {"id": "cgalt", "version": "1.0.0"}, {"id": "movie", "version": "1.0.0"}, {"id": "voices", "version": "1.0.0"}, {"id": "script", "version": "6.1.0"}, {"id": "ui-windows", "version": "2.1.0"} ] } """)) updateInformation = fileVersionManagement.getFilesNeedingUpdate(fileList, fileVersionManagement.SubModVersionInfo(dependencyTestSet[0]), fileVersionManagement.SubModVersionInfo(dependencyTestSet[1])) result = convertUpdateInformationToModFileList(fileList, updateInformation) idSet = set(x.id for x in result) self.assertIn('cg', idSet) #cg changed version self.assertIn('script', idSet) #script is a dependency of cg (must overwrite cg) idSet.remove('cg') idSet.remove('script') self.assertEqual(idSet, set()) #no other items should remain in the list