# Copyright Hybrid Logic Ltd.  See LICENSE file for details.

"""
Tests for ``flocker.node._config``.
"""

from twisted.trial.unittest import SynchronousTestCase
from .._config import Configuration


class ModelFromConfigurationTests(SynchronousTestCase):
    """
    Other tests for ``model_from_configuration``.
    """
    def test_error_on_missing_application_key(self):
        """
        ``model_from_configuration`` raises an ``KeyError`` if the
        application_configuration does not contain an `application` key.
        """
        config = Configuration()
        self.assertRaises(KeyError, config._applications_from_configuration, {})

    def test_error_on_missing_application_attributes(self):
        """
        ``model_from_configuration`` raises an exception if the
        application_configuration does not contain all the attributes of an
        `Application` record.
        """
        # XXX: Test for individual missing attributes when other attributes (eg
        # volume) are added to the Application class.
        config = dict(applications={u'mysql-hybridcluster': {}})
        parser = Configuration()
        exception = self.assertRaises(KeyError, parser._applications_from_configuration, config)
        self.assertEqual(
            "Application 'mysql-hybridcluster' has a config error. "
            "Missing value for 'image'.",
            exception.message
        )

    def test_error_on_extra_application_attributes(self):
        """
        ``model_from_configuration`` raises an exception if the
        application_configuration contains unrecognised Application attribute
        names.
        """

    def test_error_invalid_dockerimage_name(self):
        """
        ``model_from_configuration`` raises an exception if the
        application_configuration uses invalid docker image names.
        """

    def test_error_on_invalid_volume_path(self):
        """
        ``model_from_configuration`` raises an exception if the
        application_configuration uses invalid unix paths for volumes.
        """

    def test_dict_of_applications(self):
        """
        ``model_from_configuration`` returns a dict of ``Application``
        instances, one for each application key in the supplied configuration.
        """

@@ -1638,32 +1638,580 @@
 mes.%0A        %22%22%22
+%0A        # XXX: Test for individual missing attributes when other attributes (eg%0A        # volume) are added to the Application class.%0A        config = dict(applications=%7Bu'mysql-hybridcluster': dict(image=b'foo/bar:baz', foo=b'bar')%7D)%0A        parser = Configuration()%0A        exception = self.assertRaises(KeyError, parser._applications_from_configuration, config)%0A        self.assertEqual(%0A            %22Application 'mysql-hybridcluster' has a config error. %22%0A            %22Unrecognised keys in: image, foo%22,%0A            exception.message%0A        )
 %0A%0A    def test_e

Test for unrecognized keys in the application config.