Пример #1
0
    def setUp(self):
        # make an in-memory sqlite database to use during testing
        self.connection = Connection_wrapper(
            sqlite.connect(":memory:",
                           detect_types=sqlite.PARSE_DECLTYPES,
                           check_same_thread=False))
        self.cache = Stub_cache()
        cursor = self.connection.cursor()
        cursor.execute(Stub_object.sql_create_table())

        self.database = Database(self.connection, self.cache)
    def setUp(self):
        # make an in-memory sqlite database to use during testing
        self.connection = Connection_wrapper(
            sqlite.connect(":memory:",
                           detect_types=sqlite.PARSE_DECLTYPES,
                           check_same_thread=False))
        self.cache = Stub_cache()
        cursor = self.connection.cursor()
        cursor.execute(Stub_object.sql_create_table())

        self.fake_files = {
        }  # map of fake filename (full path) to fake file contents
        self.database = Database(self.connection, self.cache)
        self.upgrader = Schema_upgrader(self.database,
                                        glob=self.glob,
                                        read_file=self.read_file)
Пример #3
0
    def setUp(self):
        self.database = Database(
            Connection_wrapper(
                sqlite.connect(":memory:",
                               detect_types=sqlite.PARSE_DECLTYPES,
                               check_same_thread=False)),
            cache=Stub_cache(),
        )
        self.database.execute_script(file("model/schema.sqlite").read(),
                                     commit=True)

        self.username = u"mulder"
        self.password = u"trustno1"
        self.email_address = u"*****@*****.**"
        self.user = User.create(self.database.next_id(User), self.username,
                                self.password, self.email_address)
        self.database.save(self.user, commit=False)

        self.trash = Notebook.create(self.database.next_id(Notebook), u"trash")
        self.database.save(self.trash, commit=False)
        self.notebook = Notebook.create(self.database.next_id(Notebook),
                                        u"notebook",
                                        self.trash.object_id,
                                        user_id=self.user.object_id)
        self.database.save(self.notebook, commit=False)

        note_id = self.database.next_id(Note)
        self.note1 = Note.create(note_id,
                                 u"<h3>my title</h3>blah",
                                 notebook_id=self.notebook.object_id,
                                 startup=True,
                                 user_id=self.user.object_id)
        self.database.save(self.note1, commit=False)

        note_id = self.database.next_id(Note)
        self.note2 = Note.create(note_id,
                                 u"<h3>other title</h3>whee",
                                 notebook_id=self.notebook.object_id,
                                 user_id=self.user.object_id)
        self.database.save(self.note2, commit=False)
Пример #4
0
    def setUp(self):
        # trick tested methods into using a fake SMTP server
        Stub_smtp.reset()
        smtplib.SMTP = Stub_smtp

        from controller.Root import Root
        cherrypy.lowercase_api = True
        self.database = Database(
            Connection_wrapper(
                sqlite.connect(":memory:",
                               detect_types=sqlite.PARSE_DECLTYPES,
                               check_same_thread=False)),
            cache=Stub_cache(),
        )
        self.database.execute_script(file("model/schema.sqlite").read(),
                                     commit=True)

        self.settings = {
            u"global": {
                u"server.environment":
                "production",
                u"session_filter.on":
                True,
                u"session_filter.storage_type":
                u"ram",
                u"encoding_filter.on":
                True,
                u"encoding_filter.encoding":
                "utf-8",
                u"decoding_filter.on":
                True,
                u"decoding_filter.encoding":
                "utf-8",
                u"server.log_to_screen":
                False,
                u"luminotes.http_url":
                u"http://luminotes.com",
                u"luminotes.https_url":
                u"https://luminotes.com",
                u"luminotes.http_proxy_ip":
                u"127.0.0.1",
                u"luminotes.https_proxy_ip":
                u"127.0.0.2",
                u"luminotes.support_email":
                "*****@*****.**",
                u"luminotes.payment_email":
                "*****@*****.**",
                u"luminotes.rate_plans": [
                    {
                        u"name":
                        u"super",
                        u"storage_quota_bytes":
                        1337 * 10,
                        u"notebook_collaboration":
                        False,
                        u"user_admin":
                        False,
                        u"included_users":
                        1,
                        u"fee":
                        1.99,
                        u"yearly_fee":
                        19.90,
                        u"button":
                        u"[subscribe here user %s!] button (modify=%s)",
                        u"yearly_button":
                        u"[yearly subscribe here user %s!] button (modify=%s)",
                    },
                    {
                        u"name":
                        "extra super",
                        u"storage_quota_bytes":
                        31337 * 1000,
                        u"notebook_collaboration":
                        True,
                        u"user_admin":
                        True,
                        u"included_users":
                        3,
                        u"fee":
                        9.00,
                        u"yearly_fee":
                        90.00,
                        u"button":
                        u"[or here user %s!] button (modify=%s)",
                        u"yearly_button":
                        u"[yearly or here user %s!] button (modify=%s)",
                    },
                ],
                "luminotes.download_products": [
                    {
                        "name": "local desktop extravaganza",
                        "designed_for": "individuals",
                        "storage_quota_bytes": None,
                        "included_users": 1,
                        "notebook_sharing": False,
                        "notebook_collaboration": False,
                        "user_admin": False,
                        "fee": "30.00",
                        "item_number": "5000",
                        "filename": "test.exe",
                        "button": u"",
                    },
                ],
            },
            u"/files/download": {
                u"stream_response": True,
                u"encoding_filter.on": False,
            },
            u"/files/download_product": {
                u"stream_response": True,
                u"encoding_filter.on": False,
            },
            u"/notebooks/export_csv": {
                u"stream_response": True,
                u"encoding_filter.on": False,
            },
            u"/files/progress": {
                u"stream_response": True,
            },
        }

        cherrypy.root = Root(self.database,
                             self.settings,
                             suppress_exceptions=True)
        cherrypy.config.update(self.settings)
        cherrypy.server.start(init_only=True, server_class=None)

        # since we only want to test the controller, use the stub view for all exposed methods
        import controller.Expose
        Stub_view.result = None
        controller.Expose.view_override = Stub_view