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

from twisted.web.server import Site
from twisted.trial.unittest import SynchronousTestCase

from ..script import ControlOptions, ControlScript
from ...testtools import MemoryCoreReactor


class ControlOptionsTests():
    """
    Tests for ``ControlOptions``.
    """
    def test_default_port(self):
        """
        The default port configured by ``ControlOptions`` is 4523.
        """
        options = ControlOptions()
        options.parseOptions([])
        self.assertEqual(options["port"], 4523)

    def test_custom_port(self):
        """
        The ``--port`` command-line option allows configuring the port.
        """
        options = ControlOptions()
        options.parseOptions(["--port", 1234])
        self.assertEqual(options["port"], 1234)


class ControlScriptTests(SynchronousTestCase):
    """
    Tests for ``ControlScript``.
    """
    def test_starts_http_api_server(self):
        """
        ``ControlScript.main`` starts a HTTP server on the given port.
        """
        reactor = MemoryCoreReactor()
        ControlScript().main(reactor, {"port": 8001})
        server = reactor.tcpServers[0]
        port = server[0]
        factory = server[1].__class__
        self.assertEqual((port, factory), (8001, Site))

@@ -240,16 +240,43 @@
 eReactor
+, StandardOptionsTestsMixin
 %0A%0A%0Aclass
@@ -296,16 +296,88 @@
 nsTests(
+StandardOptionsTestsMixin,%0A                          SynchronousTestCase
 ):%0A    %22
@@ -413,32 +413,62 @@
 ions%60%60.%0A    %22%22%22%0A
+    options = ControlOptions%0A%0A
     def test_def
@@ -971,16 +971,23 @@
 olScript
+Effects
 Tests(Sy
@@ -1020,32 +1020,40 @@
 %22%0A    Tests for 
+effects 
 %60%60ControlScript%60

Make sure options tests run.