Esempio n. 1
0
    def setUp(self):
        self.network_name = "test_net_name"
        self.driver = DefaultPolicyDriver(self.network_name)
        assert_equal(self.driver.profile_name, self.network_name)

        # Mock the DatastoreClient
        self.client = MagicMock(spec=DatastoreClient)
        self.driver._client = self.client
    def setUp(self):
        self.network_name = "test_net_name"
        self.driver = DefaultPolicyDriver(self.network_name)
        assert_equal(self.driver.profile_name, self.network_name)

        # Mock the DatastoreClient
        self.client = MagicMock(spec=DatastoreClient)
        self.driver._client = self.client
Esempio n. 3
0
class DefaultPolicyDriverTest(unittest.TestCase):
    """
    Test class for DefaultPolicyDriver class.
    """
    def setUp(self):
        self.network_name = "test_net_name"
        self.driver = DefaultPolicyDriver(self.network_name)
        assert_equal(self.driver.profile_name, self.network_name)

        # Mock the DatastoreClient
        self.client = MagicMock(spec=DatastoreClient)
        self.driver._client = self.client

    def test_apply_new_profile(self):
        # Mock.
        endpoint = MagicMock(spec=Endpoint)
        endpoint.profile_ids = []
        endpoint.endpoint_id = "12345"
        self.client.profile_exists.return_value = False

        # Mock out generate_tags.
        self.driver.generate_tags = MagicMock(spec=self.driver.generate_tags)
        self.driver.generate_tags.return_value = ["tag1", "tag2"]

        # Call
        self.driver.apply_profile(endpoint)

        # Assert
        self.client.append_profiles_to_endpoint.assert_called_once_with(
            profile_names=[self.network_name], endpoint_id="12345")

    def test_apply_same_profile(self):
        # Mock.
        endpoint = MagicMock(spec=Endpoint)
        endpoint.profile_ids = [self.network_name]
        endpoint.endpoint_id = "12345"
        self.client.profile_exists.return_value = False

        # Call
        self.driver.apply_profile(endpoint)

        # Assert
        assert_false(self.client.append_profiles_to_endpoint.called)

    def test_apply_profile_error(self):
        # Mock.
        endpoint = MagicMock(spec=Endpoint)
        endpoint.profile_ids = []
        endpoint.endpoint_id = "12345"
        endpoint.name = "cali12345"
        self.client.profile_exists.return_value = False
        self.client.append_profiles_to_endpoint.side_effect = KeyError

        # Call
        assert_raises(ApplyProfileError, self.driver.apply_profile, endpoint)

    def test_remove_profile(self):
        # Should do nothing.
        self.driver.remove_profile()

    @parameterized.expand([
        ("invalid=name"),
        ("^regex$"),
    ])
    def test_invalid_network_name(self, net_name):
        assert_raises(ValueError, DefaultPolicyDriver, net_name)
class DefaultPolicyDriverTest(unittest.TestCase):
    """
    Test class for DefaultPolicyDriver class.
    """
    def setUp(self):
        self.network_name = "test_net_name"
        self.driver = DefaultPolicyDriver(self.network_name)
        assert_equal(self.driver.profile_name, self.network_name)

        # Mock the DatastoreClient
        self.client = MagicMock(spec=DatastoreClient)
        self.driver._client = self.client

    def test_apply_new_profile(self):
        # Mock.
        endpoint = MagicMock(spec=Endpoint)
        endpoint.profile_ids = []
        endpoint.endpoint_id = "12345"
        self.client.profile_exists.return_value = False

        # Mock out generate_tags.
        self.driver.generate_tags = MagicMock(spec=self.driver.generate_tags)
        self.driver.generate_tags.return_value = ["tag1", "tag2"]

        # Call
        self.driver.apply_profile(endpoint)

        # Assert
        self.client.append_profiles_to_endpoint.assert_called_once_with(
                profile_names=[self.network_name], endpoint_id="12345"
        )

    def test_apply_same_profile(self):
        # Mock.
        endpoint = MagicMock(spec=Endpoint)
        endpoint.profile_ids = [self.network_name]
        endpoint.endpoint_id = "12345"
        self.client.profile_exists.return_value = False

        # Call
        self.driver.apply_profile(endpoint)

        # Assert
        assert_false(self.client.append_profiles_to_endpoint.called)

    def test_apply_profile_error(self):
        # Mock.
        endpoint = MagicMock(spec=Endpoint)
        endpoint.profile_ids = []
        endpoint.endpoint_id = "12345"
        endpoint.name = "cali12345"
        self.client.profile_exists.return_value = False
        self.client.append_profiles_to_endpoint.side_effect = KeyError

        # Call
        assert_raises(ApplyProfileError, self.driver.apply_profile, endpoint)

    def test_remove_profile(self):
        # Should do nothing.
        self.driver.remove_profile()

    @parameterized.expand([
        ("invalid=name"), ("^regex$"),
    ])
    def test_invalid_network_name(self, net_name):
        assert_raises(ValueError, DefaultPolicyDriver, net_name)