コード例 #1
0
    def test__do_import_modules_handles_cancel(self, _add_new_module):
        """
        Make sure _do_import_modules() handles the cancel signal correctly. We'll do this by setting
        up a side effect with the first module to call cancel so the second never happens.
        """
        swpf = SynchronizeWithPuppetForge(self.repo, self.conduit, self.config)

        def _side_effect(*args, **kwargs):
            swpf.cancel()

        _add_new_module.side_effect = _side_effect
        metadata = model.RepositoryMetadata()
        module_1 = model.Module('module_1', '1.0.0', 'simon')
        module_2 = model.Module('module_2', '2.0.3', 'garfunkel')
        metadata.modules = [module_1, module_2]

        swpf._do_import_modules(metadata)

        # If _add_new_module was called exactly once, then our cancel was successful because the
        # first call to _add_new_module set the cancel flag, and the loop exited the next time.
        # Because dictionaries are involved in the order in which the modules get downloaded, we
        # don't have a documented guarantee about which module will be the one. Therefore, we'll
        # just assert that only one was downloaded and that it was one of the two.
        self.assertEqual(_add_new_module.call_count, 1)
        downloaded_module = _add_new_module.mock_calls[0][1][1]
        self.assertTrue(downloaded_module in [module_1, module_2])
コード例 #2
0
    def _run_metadata_test(self):
        # Test
        docs = self.downloader.retrieve_metadata(self.mock_progress_report)

        # Verify
        parsed = model.RepositoryMetadata()
        for d in docs:
            parsed.update_from_json(d)

        print('Number of Modules: %s' % len(parsed.modules))

        return docs
コード例 #3
0
    def test_retrieve_metadata(self):
        # Test
        docs = self.downloader.retrieve_metadata(self.mock_progress_report)

        # Verify
        self.assertEqual(1, len(docs))
        metadata = model.RepositoryMetadata()
        metadata.update_from_json(docs[0])
        self.assertEqual(2, len(metadata.modules))

        self.assertEqual(1, self.mock_progress_report.metadata_query_total_count)
        self.assertEqual(1, self.mock_progress_report.metadata_query_finished_count)
        expected_query = os.path.join(VALID_REPO_DIR, constants.REPO_METADATA_FILENAME)
        self.assertEqual(expected_query, self.mock_progress_report.metadata_current_query)
        self.assertEqual(2, self.mock_progress_report.update_progress.call_count)