Exemplo n.º 1
0
 def test_download_data_to_existing_folder_using_button(self):
     updater = UpdateDownloader(local_egg_repo=HERE,
                                allow_dlg=False,
                                current_version=("0.6.1", 4))
     updater.release_data_file = join(HERE, "release_list.json")
     updater.download_button = True
     self.assert_files_downloaded_to(HERE)
Exemplo n.º 2
0
 def test_new_releases_previous_minor_version(self):
     # Fake to be in an old version state for the specified release to be
     # considered eligible.
     updater = UpdateDownloader(current_version=((0, 6, 1), 4))
     updater.release_data_file = join(HERE, "release_list.json")
     self.assertIn(NEWEST_CONTENT_FNAME, updater.new_release_list)
     self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)
Exemplo n.º 3
0
 def test_new_releases_previous_build_number(self):
     # Fake to be the same version but a previous build number for the
     # specified release to be considered eligible.
     updater = UpdateDownloader(current_version=("0.7.2", 2))
     updater.release_data_file = join(HERE, "release_list.json")
     self.assertIn(NEWEST_CONTENT_FNAME, updater.new_release_list)
     self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)
Exemplo n.º 4
0
    def open_software_updater(self):
        from kromatography.tools.update_downloader import UpdateDownloader

        tool = UpdateDownloader()
        # Trigger a check before opening the UI:
        tool.check_button = True
        tool.edit_traits(kind="modal")
Exemplo n.º 5
0
    def assert_can_download_update_to(self, local_egg_repo):
        updater = UpdateDownloader(local_egg_repo=local_egg_repo,
                                   current_version=("0.6.1", 4))
        updater.release_data_file = join(HERE, "release_list.json")
        self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)
        success = updater.download_newest_version()

        self.assertTrue(success)
        self.assert_files_downloaded_to(local_egg_repo)
Exemplo n.º 6
0
 def test_fail_download_data_bad_release_file(self):
     updater = UpdateDownloader(local_egg_repo=HERE,
                                allow_dlg=False,
                                current_version=("0.6.1", 4))
     updater.release_data_file = join(HERE, "BAD_release_list.json")
     updater.download_button = True
     # There is not content file downloaded or no egg
     for fname in os.listdir(HERE):
         self.assertNotIn("content", fname)
         ext = splitext(fname)[1]
         self.assertNotEqual(ext, ".egg")
Exemplo n.º 7
0
 def setUp(self):
     self.updater = UpdateDownloader()
Exemplo n.º 8
0
class TestUpdateDownloader(TestCase):
    def setUp(self):
        self.updater = UpdateDownloader()

    def tearDown(self):
        hist_file = join(HERE, DEFAULT_HIST_FILENAME)
        if isfile(hist_file):
            os.remove(hist_file)

    def test_bringup(self):
        with temp_bringup_ui_for(self.updater):
            pass

    def test_default_release_data(self):
        updater = self.updater
        self.assertEqual(updater.release_data, [])
        self.assertEqual(updater.new_release_list, [])
        self.assertEqual(updater.newest_release, "")

        updater.release_data_file = join(HERE, "release_list.json")
        self.assertIn(FIRST_RELEASE_ENTRY, updater.release_data)

    def test_current_version(self):
        version, build = self.updater.current_version
        self.assertIsInstance(version, tuple)
        self.assertEqual(version,
                         version_str_to_version(kromatography.__version__))
        if len(kromatography.__build__) > 2:
            self.assertEqual(build, kromatography.__build__)
        else:
            self.assertEqual(build, int(kromatography.__build__))

        self.assertIsInstance(self.updater.current_version_msg, str)

    def test_download_release_data(self):
        local_egg_repo = get_updater_folder()
        release_list_file = join(local_egg_repo, RELEASE_LIST_FNAME)
        if isfile(release_list_file):
            os.remove(release_list_file)

        self.updater.update_release_data_file()
        try:
            self.assertTrue(isfile(release_list_file))
        finally:
            os.remove(release_list_file)

        # Information propagates to the release_data attribute
        self.assertIn(FIRST_RELEASE_ENTRY, self.updater.release_data)

    def test_download_release_data_using_button(self):
        local_egg_repo = get_updater_folder()
        release_list_file = join(local_egg_repo, RELEASE_LIST_FNAME)
        if isfile(release_list_file):
            os.remove(release_list_file)

        self.updater.check_button = True
        try:
            self.assertTrue(isfile(release_list_file))
        finally:
            os.remove(release_list_file)

        # Information propagates to the release_data attribute
        self.assertIn(FIRST_RELEASE_ENTRY, self.updater.release_data)

    def test_new_releases_previous_minor_version(self):
        # Fake to be in an old version state for the specified release to be
        # considered eligible.
        updater = UpdateDownloader(current_version=((0, 6, 1), 4))
        updater.release_data_file = join(HERE, "release_list.json")
        self.assertIn(NEWEST_CONTENT_FNAME, updater.new_release_list)
        self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)

    def test_new_releases_previous_minor_version_str(self):
        # Fake to be in an old version state for the specified release to be
        # considered eligible.
        updater = UpdateDownloader(current_version=("0.6.1", 4))
        updater.release_data_file = join(HERE, "release_list.json")
        self.assertIn(NEWEST_CONTENT_FNAME, updater.new_release_list)
        self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)

    def test_new_releases_previous_bug_fix_release(self):
        # Slightly older version (and build)
        updater = UpdateDownloader(current_version=("0.7.1", 2))
        updater.release_data_file = join(HERE, "release_list.json")
        self.assertIn(NEWEST_CONTENT_FNAME, updater.new_release_list)
        self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)

    def test_new_releases_previous_bug_fix_release_but_larger_build(self):
        # slightly order version but larger build number
        updater = UpdateDownloader(current_version=("0.7.1", 4))
        updater.release_data_file = join(HERE, "release_list.json")
        self.assertIn(NEWEST_CONTENT_FNAME, updater.new_release_list)
        self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)

    def test_new_releases_previous_minor_version_09_010(self):
        """ Test that 0.10 is treated as newer than 0.9."""
        updater = UpdateDownloader(current_version=("0.9.2", 1))
        updater.release_data_file = join(HERE, "release_list2.json")
        self.assertIn('content_0.10.0_0.json', updater.new_release_list)
        self.assertEqual(updater.newest_release, 'content_0.10.0_0.json')

    def test_new_releases_previous_build_number(self):
        # Fake to be the same version but a previous build number for the
        # specified release to be considered eligible.
        updater = UpdateDownloader(current_version=("0.7.2", 2))
        updater.release_data_file = join(HERE, "release_list.json")
        self.assertIn(NEWEST_CONTENT_FNAME, updater.new_release_list)
        self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)

    def test_no_new_releases_future_version(self):
        # Larger major version number:
        updater = UpdateDownloader(current_version=("1.4", 1))
        updater.release_data_file = join(HERE, "release_list.json")
        self.assert_no_release_found(updater)

    def test_no_new_releases_same_version(self):
        # Fake to be in a futuristic version
        updater = UpdateDownloader(current_version=("0.7.2", 3))
        updater.release_data_file = join(HERE, "release_list.json")
        self.assert_no_release_found(updater)

    def test_download_data_to_existing_folder(self):
        self.assert_can_download_update_to(HERE)

    def test_download_data_to_existing_folder_using_button(self):
        updater = UpdateDownloader(local_egg_repo=HERE,
                                   allow_dlg=False,
                                   current_version=("0.6.1", 4))
        updater.release_data_file = join(HERE, "release_list.json")
        updater.download_button = True
        self.assert_files_downloaded_to(HERE)

    def test_fail_download_data_bad_release_file(self):
        updater = UpdateDownloader(local_egg_repo=HERE,
                                   allow_dlg=False,
                                   current_version=("0.6.1", 4))
        updater.release_data_file = join(HERE, "BAD_release_list.json")
        updater.download_button = True
        # There is not content file downloaded or no egg
        for fname in os.listdir(HERE):
            self.assertNotIn("content", fname)
            ext = splitext(fname)[1]
            self.assertNotEqual(ext, ".egg")

    def test_download_data_to_new_folder(self):
        local_egg_repo = join(HERE, "new folder")
        self.assertFalse(isdir(local_egg_repo))
        try:
            self.assert_can_download_update_to(local_egg_repo)
        finally:
            shutil.rmtree(local_egg_repo)

    def test_download_utility(self):
        download_version(NEWEST_CONTENT_FNAME,
                         egg_repo_url=EGG_REPO_URL,
                         local_egg_repo=HERE)
        self.assert_files_downloaded_to(HERE)

    def test_download_utility_with_bitly_link(self):
        self.skipTest("bitly not yet in use")
        download_version("content_v0.10.4_1.json",
                         egg_repo_url=EGG_REPO_URL,
                         local_egg_repo=HERE)
        filenames = ["content_v0.10.4_1.json", 'kromatography-0.10.4-1.egg']
        self.assert_files_downloaded_to(HERE, filenames=filenames)

    # Helper methods ----------------------------------------------------------

    def assert_no_release_found(self, updater):
        self.assertEqual(updater.new_release_list, [])
        self.assertEqual(updater.newest_release, NO_RELEASE)
        self.assertIsInstance(updater.newest_release_msg, str)

    def assert_can_download_update_to(self, local_egg_repo):
        updater = UpdateDownloader(local_egg_repo=local_egg_repo,
                                   current_version=("0.6.1", 4))
        updater.release_data_file = join(HERE, "release_list.json")
        self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)
        success = updater.download_newest_version()

        self.assertTrue(success)
        self.assert_files_downloaded_to(local_egg_repo)

    def assert_files_downloaded_to(self, local_egg_repo, filenames=None):
        if filenames is None:
            filenames = [NEWEST_CONTENT_FNAME, 'kromatography-0.7.2-3.egg']

        for fname in filenames:
            try:
                self.assertIn(fname, os.listdir(local_egg_repo))
            finally:
                filepath = join(local_egg_repo, fname)
                if isfile(filepath):
                    os.remove(filepath)
Exemplo n.º 9
0
 def test_no_new_releases_same_version(self):
     # Fake to be in a futuristic version
     updater = UpdateDownloader(current_version=("0.7.2", 3))
     updater.release_data_file = join(HERE, "release_list.json")
     self.assert_no_release_found(updater)
Exemplo n.º 10
0
 def test_no_new_releases_future_version(self):
     # Larger major version number:
     updater = UpdateDownloader(current_version=("1.4", 1))
     updater.release_data_file = join(HERE, "release_list.json")
     self.assert_no_release_found(updater)
Exemplo n.º 11
0
 def test_new_releases_previous_minor_version_09_010(self):
     """ Test that 0.10 is treated as newer than 0.9."""
     updater = UpdateDownloader(current_version=("0.9.2", 1))
     updater.release_data_file = join(HERE, "release_list2.json")
     self.assertIn('content_0.10.0_0.json', updater.new_release_list)
     self.assertEqual(updater.newest_release, 'content_0.10.0_0.json')
Exemplo n.º 12
0
 def test_new_releases_previous_bug_fix_release_but_larger_build(self):
     # slightly order version but larger build number
     updater = UpdateDownloader(current_version=("0.7.1", 4))
     updater.release_data_file = join(HERE, "release_list.json")
     self.assertIn(NEWEST_CONTENT_FNAME, updater.new_release_list)
     self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)
Exemplo n.º 13
0
 def test_new_releases_previous_bug_fix_release(self):
     # Slightly older version (and build)
     updater = UpdateDownloader(current_version=("0.7.1", 2))
     updater.release_data_file = join(HERE, "release_list.json")
     self.assertIn(NEWEST_CONTENT_FNAME, updater.new_release_list)
     self.assertEqual(updater.newest_release, NEWEST_CONTENT_FNAME)