# Copyright ClusterHQ Inc.  See LICENSE file for details.

"""
Test validation of keys generated by flocker-ca.
"""

from twisted.trial.unittest import SynchronousTestCase

from .. import amp_server_context_factory, rest_api_context_factory
from ..testtools import get_credential_sets


class ClientValidationContextFactoryTests(SynchronousTestCase):
    """
    Tests for implementation details of the context factory used by the
    control service.
    """
    def test_amp_new_context_each_time(self):
        """
        Each call to the AMP server's context factory ``getContext`` returns a
        new instance, to prevent issues with global shared state.
        """
        ca_set, _ = get_credential_sets()
        context_factory = amp_server_context_factory(
            ca_set.root.credential.certificate, ca_set.control)
        self.assertNotIdentical(context_factory.getContext(),
                                context_factory.getContext())

    def test_rest_new_context_each_time(self):
        """
        Each call to the REST API server's context factory ``getContext``
        returns a new instance, to prevent issues with global shared
        state.
        """
        ca_set, _ = get_credential_sets()
        context_factory = rest_api_context_factory(
            ca_set.root.credential.certificate, ca_set.control)
        self.assertNotIdentical(context_factory.getContext(),
                                context_factory.getContext())

# Copyright ClusterHQ Inc.  See LICENSE file for details.

"""
Test validation of keys generated by flocker-ca.
"""

from twisted.trial.unittest import SynchronousTestCase

from .. import amp_server_context_factory, rest_api_context_factory
from ..testtools import get_credential_sets


class ClientValidationContextFactoryTests(SynchronousTestCase):
    """
    Tests for implementation details of the context factory used by the
    control service.
    """
    def test_amp_new_context_each_time(self):
        """
        Each call to the AMP server's context factory ``getContext`` returns a
        new instance, to prevent issues with global shared state.
        """
        ca_set, _ = get_credential_sets()
        context_factory = amp_server_context_factory(
            ca_set.root.credential.certificate, ca_set.control)
        self.assertIsNot(context_factory.getContext(),
                         context_factory.getContext())

    def test_rest_new_context_each_time(self):
        """
        Each call to the REST API server's context factory ``getContext``
        returns a new instance, to prevent issues with global shared
        state.
        """
        ca_set, _ = get_credential_sets()
        context_factory = rest_api_context_factory(
            ca_set.root.credential.certificate, ca_set.control)
        self.assertIsNot(context_factory.getContext(),
                         context_factory.getContext())

Address review comment: More standard assertions.
Address review comment: More standard assertions.
