Ejemplo n.º 1
0
class TestRouter(unittest.TestCase):
    def setUp(self):
        self._resource_manager = MockResourceManager()
        self._template_builder = TemplateBuilder(self._resource_manager)
        self._template_builder.start()
        self._router = Router(resource_manager=self._resource_manager,
                              template_builder=self._template_builder,
                              login_manager=Mock(),
                              database=Mock(),
                              platform=Mock())
        self._router.start()
        self._app = self._router.get_wsgi_app()
        install_opener()
        add_wsgi_intercept("localhost", 8080, lambda: self._app)

    def tearDown(self):
        remove_wsgi_intercept("localhost", 8080)
        self._router = None
        self._template_builder = None
        self._resource_manager = None
        self._app = None

    #===========================================================================
    # Helpers
    #===========================================================================
    def _route_index(self):
        return urllib2.urlopen("http://localhost:8080/").read()

    def _route_login(self, post_data):
        return urllib2.urlopen("http://localhost:8080/login", post_data).read()

    def _route_logout(self):
        return urllib2.urlopen("http://localhost:8080/logout").read()

    def _route_static(self, asset):
        return urllib2.urlopen("http://localhost:8080/static").read()

    def _assert_json_response(self, expected_json, resp):
        """ `expected_json` in object form, unencoded """
        self.assertEqual(json.loads(expected_json), resp.body.read())

    #===========================================================================
    # Tests
    #===========================================================================
    def test_index(self):
        resp = self._route_index()
        self.assertNotEqual(resp, None)

    def test_login_without_state(self):
        try:
            self._route_login(JSON({"auth_code": "1234"}))
        except Exception, e:
            self.assertEqual(e.code, 401)
Ejemplo n.º 2
0
 def setUp(self):
     self._resource_manager = MockResourceManager()
     self._template_builder = TemplateBuilder(self._resource_manager)
     self._template_builder.start()
     self._router = Router(resource_manager=self._resource_manager,
                           template_builder=self._template_builder,
                           login_manager=Mock(),
                           database=Mock(),
                           platform=Mock())
     self._router.start()
     self._app = self._router.get_wsgi_app()
     install_opener()
     add_wsgi_intercept("localhost", 8080, lambda: self._app)
Ejemplo n.º 3
0
    def start(self):
        """Start the app"""
        # Start the logger so we can begin logging -----------------------------
        logging_configurator = \
                LoggingConfigurator(file_path=os.path.join(ROOT, "logs",
                                                           "log.txt"),
                                    level="INFO")
        logging_configurator.start()

        # Init all Components --------------------------------------------------
        self.platform = LinuxPlatform()
        self.resource_manager = ResourceManager()
        self.template_builder = TemplateBuilder(self.resource_manager)
        self.database = Database(self.resource_manager)
        self.login_manager = LoginManager(self.database,
                                          self.resource_manager,
                                          self.platform)
        self.router = Router(self.resource_manager,
                             self.template_builder,
                             self.login_manager,
                             self.database,
                             self.platform)

        # Start all Components -------------------------------------------------
        self._start_component("Linux Platform", self.platform)

        self._start_component("Template Builder", self.template_builder)

        self._start_component("Login Manager", self.login_manager)

        self._start_component("Database", self.database)

        self._start_component("Router", self.router)

        WSGIServer(self.router.get_wsgi_app()).run()
Ejemplo n.º 4
0
    def start(self):
        """Start the app"""
        # Start the logger so we can begin logging -----------------------------
        logging_configurator = \
                LoggingConfigurator(file_path=os.path.join(ROOT, "logs",
                                                           "log.txt"),
                                    level="INFO")
        logging_configurator.start()

        # Init all Components --------------------------------------------------
        self.platform = LinuxPlatform()
        self.resource_manager = ResourceManager()
        self.template_builder = TemplateBuilder(self.resource_manager)
        self.database = Database(self.resource_manager)
        self.login_manager = LoginManager(self.database, self.resource_manager,
                                          self.platform)
        self.router = Router(self.resource_manager, self.template_builder,
                             self.login_manager, self.database, self.platform)
        self.debug_server = Server(self.router)

        # Start all Components -------------------------------------------------
        self._start_component("Linux Platform", self.platform)

        self._start_component("Template Builder", self.template_builder)

        self._start_component("Login Manager", self.login_manager)

        self._start_component("Database", self.database)

        self._start_component("Router", self.router)

        self._start_component("Debug Server", self.debug_server)

        # Main loop ------------------------------------------------------------
        try:
            print "Ctrl+C to quit..."
            while True:
                time.sleep(10)
        except KeyboardInterrupt:
            print "Interrupt received... shutting down"
            os._exit(0)