Exemplo n.º 1
0
    def test_default_profile(self):
        """Test setting and getting default profile."""
        config = Config(self.config_filepath, self.config_dictionary)

        # If not set should return None
        self.assertEqual(config.default_profile_name, None)

        # Setting it to a profile that does not exist should raise
        with self.assertRaises(exceptions.ProfileConfigurationError):
            config.set_default_profile('non_existing_profile')

        # After setting a default profile, it should return the right name
        config.add_profile(create_mock_profile(self.profile_name))
        config.set_default_profile(self.profile_name)
        self.assertTrue(config.default_profile_name, self.profile_name)

        # Setting it when a default is already set, should not overwrite by default
        alternative_profile_name = 'alternative_profile_name'
        config.add_profile(create_mock_profile(alternative_profile_name))
        config.set_default_profile(self.profile_name)
        self.assertTrue(config.default_profile_name, self.profile_name)

        # But with overwrite=True it should
        config.set_default_profile(self.profile_name, overwrite=True)
        self.assertTrue(config.default_profile_name, alternative_profile_name)
Exemplo n.º 2
0
    def test_profiles(self):
        """Test the properties related to retrieving, creating, updating and removing profiles."""
        config = Config(self.config_filepath, self.config_dictionary)

        # Each item returned by config.profiles should be a Profile instance
        for profile in config.profiles:
            self.assertIsInstance(profile, Profile)
            self.assertTrue(
                profile.dictionary,
                self.config_dictionary[Config.KEY_PROFILES][profile.name])

        # The profile_names property should return the keys of the profiles dictionary
        self.assertEqual(config.profile_names,
                         list(self.config_dictionary[Config.KEY_PROFILES]))

        # Test get_profile
        self.assertEqual(
            config.get_profile(self.profile_name).dictionary,
            self.profile.dictionary)

        # Update a profile
        updated_profile = create_mock_profile(self.profile_name)
        config.update_profile(updated_profile)
        self.assertEqual(
            config.get_profile(self.profile_name).dictionary,
            updated_profile.dictionary)

        # Removing an unexisting profile should raise
        with self.assertRaises(exceptions.ProfileConfigurationError):
            config.remove_profile('non_existing_profile')

        # Removing an existing should work and in this test case none should remain
        config.remove_profile(self.profile_name)
        self.assertEqual(config.profiles, [])
        self.assertEqual(config.profile_names, [])
Exemplo n.º 3
0
    def test_is_test_profile(self):
        """Test that a profile whose name starts with `test_` is marked as a test profile."""
        profile_name = 'not_a_test_profile'
        profile = create_mock_profile(name=profile_name)

        # The one constructed in the setUpClass should be a test profile
        self.assertTrue(self.profile.is_test_profile)

        # The profile created here should *not* be a test profile
        self.assertFalse(profile.is_test_profile)
Exemplo n.º 4
0
 def setUp(self):
     """Setup a mock config."""
     super().setUp()
     self.profile_name = 'test_profile'
     self.profile = create_mock_profile(self.profile_name)
     self.config_filebase = tempfile.mkdtemp()
     self.config_filename = 'config.json'
     self.config_filepath = os.path.join(self.config_filebase, self.config_filename)
     self.config_dictionary = {
         Config.KEY_VERSION: {
             Config.KEY_VERSION_CURRENT: CURRENT_CONFIG_VERSION,
             Config.KEY_VERSION_OLDEST_COMPATIBLE: OLDEST_COMPATIBLE_CONFIG_VERSION,
         },
         Config.KEY_PROFILES: {
             self.profile_name: self.profile.dictionary
         },
     }
Exemplo n.º 5
0
    def mock_profiles(self, **kwargs):
        """Create mock profiles and a runner object to invoke the CLI commands.

        Note: this cannot be done in the `setUp` or `setUpClass` methods, because the temporary configuration instance
        is not generated until the test function is entered, which calls the `config_with_profile` test fixture.
        """
        self.config = configuration.get_config()
        self.profile_list = [
            'mock_profile1', 'mock_profile2', 'mock_profile3', 'mock_profile4'
        ]

        for profile_name in self.profile_list:
            profile = create_mock_profile(profile_name, **kwargs)
            self.config.add_profile(profile)

        self.config.set_default_profile(self.profile_list[0],
                                        overwrite=True).store()