Exemple #1
0
 def test_use_fixture(self, mock_vr):
     exp_vr = dict(keypair='keypair',
                   floating_ip='floating_ip',
                   security_group='security_group')
     mock_vr.return_value = exp_vr
     exp_clients = 'clients'
     exp_parameters = dict(keypair=True,
                           floating_ip=True,
                           security_group=True,
                           security_group_rules=True,
                           ethertype='v6',
                           use_neutron=True,
                           floating_network_id='fnid',
                           floating_network_name='fnname')
     # First mock cleanup
     self.useFixture(
         fixtures.MockPatchObject(vr,
                                  'clear_validation_resources',
                                  autospec=True))
     # And then use vr fixture, so when the fixture is cleaned-up, the mock
     # is still there
     vr_fixture = self.useFixture(
         vr.ValidationResourcesFixture(exp_clients, **exp_parameters))
     # Assert vr have been provisioned
     mock_vr.assert_called_once_with(exp_clients, **exp_parameters)
     # Assert vr have been setup in the fixture
     self.assertEqual(exp_vr, vr_fixture.resources)
Exemple #2
0
    def get_test_validation_resources(self, os_clients):
        """Returns a dict of validation resources according to configuration

        Initialise a validation resources fixture based on configuration.
        Start the fixture and returns the validation resources.

        If `CONF.validation.run_validation` is False no resource will be
        provisioned at all.

        @param os_clients: Clients to be used to provision the resources.
        """

        params = {}
        # Test will try to use the fixture, so for this to be useful
        # we must return a fixture. If validation is disabled though
        # we don't need to provision anything, which is the default
        # behavior for the fixture.
        if CONF.validation.run_validation:
            params = self._validation_resources_params_from_conf()

        validation = self.useFixture(
            vr.ValidationResourcesFixture(os_clients, **params))
        return validation.resources
Exemple #3
0
 def test_use_fixture_context(self, mock_vr, mock_clear):
     exp_vr = dict(keypair='keypair',
                   floating_ip='floating_ip',
                   security_group='security_group')
     mock_vr.return_value = exp_vr
     exp_clients = 'clients'
     exp_parameters = dict(keypair=True,
                           floating_ip=True,
                           security_group=True,
                           security_group_rules=True,
                           ethertype='v6',
                           use_neutron=True,
                           floating_network_id='fnid',
                           floating_network_name='fnname')
     with vr.ValidationResourcesFixture(exp_clients,
                                        **exp_parameters) as vr_fixture:
         # Assert vr have been provisioned
         mock_vr.assert_called_once_with(exp_clients, **exp_parameters)
         # Assert vr have been setup in the fixture
         self.assertEqual(exp_vr, vr_fixture.resources)
     # After context manager is closed, clear is invoked
     exp_vr['use_neutron'] = exp_parameters['use_neutron']
     mock_clear.assert_called_once_with(exp_clients, **exp_vr)