def test_PackageUpload(self): # Check if we can properly upload a package file from the tar directory. with pynacl.working_directory.TemporaryWorkingDirectory() as work_dir: tar_dir = os.path.join(work_dir, 'tar_dir') package_target = 'test_package_archives' package_name = 'package_archives' package_revision = 10 package_version.ArchivePackageArchives(tar_dir, package_target, package_name, []) package_version.UploadPackage(self._fake_storage, package_revision, tar_dir, package_target, package_name, False) self.assertEqual(self._fake_storage.WriteCount(), 1, "Package did not get properly uploaded") remote_package_key = package_locations.GetRemotePackageKey( False, package_revision, package_target, package_name) downloaded_package = os.path.join(work_dir, 'download_package.json') package_info.DownloadPackageInfoFiles( downloaded_package, remote_package_key, downloader=self._fake_storage.GetFile) downloaded_package_desc = package_info.PackageInfo( downloaded_package) original_package_file = package_locations.GetLocalPackageFile( tar_dir, package_target, package_name) original_package_desc = package_info.PackageInfo( original_package_file) self.assertEqual(downloaded_package_desc, original_package_desc)
def test_CustomPackageUpload(self): # Check if we can upload a package file from a custom location. with pynacl.working_directory.TemporaryWorkingDirectory() as work_dir: custom_package_file = os.path.join(work_dir, 'custom_package.json') package_desc = self.GeneratePackageInfo([]) package_desc.SavePackageFile(custom_package_file) tar_dir = os.path.join(work_dir, 'tar_dir') package_target = 'custom_package_target' package_name = 'custom_package' package_revision = 10 package_version.UploadPackage( self._fake_storage, package_revision, tar_dir, package_target, package_name, False, custom_package_file=custom_package_file) self.assertEqual(self._fake_storage.WriteCount(), 1, "Package did not get properly uploaded") remote_package_key = package_locations.GetRemotePackageKey( False, package_revision, package_target, package_name) downloaded_package = os.path.join(work_dir, 'download_package.json') self._fake_storage.GetFile(remote_package_key, downloaded_package) downloaded_package_desc = package_info.PackageInfo( downloaded_package) original_package_desc = package_info.PackageInfo( custom_package_file) self.assertEqual(downloaded_package_desc, original_package_desc)
def test_NoArchiveURLDoesUpload(self): # Checks when uploading package with no archive URL, archive is uploaded. with pynacl.working_directory.TemporaryWorkingDirectory() as work_dir: tar_dir = os.path.join(work_dir, 'tar_dir') package_target = 'custom_package_target' package_name = 'custom_package' package_revision = 10 mock_file = self.GenerateMockFile(work_dir) mock_tar = package_locations.GetLocalPackageArchiveFile( tar_dir, package_target, package_name, 'archive_name.tar') os.makedirs(os.path.dirname(mock_tar)) with tarfile.TarFile(mock_tar, 'w') as f: f.add(mock_file) package_desc = self.GeneratePackageInfo([mock_tar]) package_file = os.path.join(work_dir, 'package_file.json') package_desc.SavePackageFile(package_file) package_version.UploadPackage(self._fake_storage, package_revision, tar_dir, package_target, package_name, False, custom_package_file=package_file) self.assertEqual( self._fake_storage.WriteCount(), 3, "3 files (package, archive_info, archive) should have been uploaded." ) remote_package_key = package_locations.GetRemotePackageKey( False, package_revision, package_target, package_name) downloaded_package = os.path.join(work_dir, 'download_package.json') package_info.DownloadPackageInfoFiles( downloaded_package, remote_package_key, downloader=self._fake_storage.GetFile) downloaded_package_desc = package_info.PackageInfo( downloaded_package) archive_list = downloaded_package_desc.GetArchiveList() self.assertEqual( len(archive_list), 1, "The downloaded package does not have 1 archive.") self.assertTrue( archive_list[0].GetArchiveData().url, "The downloaded archive still does not have a proper URL")
def test_UploadKeepsArchiveURL(self): # Checks if the archive URL is kept after a package upload. with pynacl.working_directory.TemporaryWorkingDirectory() as work_dir: mock_tar = self.GenerateMockFile(work_dir) mock_url = 'http://www.mock.com/mock.tar' package_desc = self.GeneratePackageInfo( [mock_tar], url_dict={mock_tar: mock_url}) package_file = os.path.join(work_dir, 'package_file.json') package_desc.SavePackageFile(package_file) tar_dir = os.path.join(work_dir, 'tar_dir') package_target = 'custom_package_target' package_name = 'custom_package' package_revision = 10 package_version.UploadPackage(self._fake_storage, package_revision, tar_dir, package_target, package_name, False, custom_package_file=package_file) self.assertEqual(self._fake_storage.WriteCount(), 2, "Package did not get properly uploaded") remote_package_key = package_locations.GetRemotePackageKey( False, package_revision, package_target, package_name) downloaded_package = os.path.join(work_dir, 'download_package.json') package_info.DownloadPackageInfoFiles( downloaded_package, remote_package_key, downloader=self._fake_storage.GetFile) downloaded_package_desc = package_info.PackageInfo( downloaded_package) # Verify everything (including URL) still matches. self.assertEqual(downloaded_package_desc, package_desc)