Example #1
0
    def test_order_association2(self):
        order = self._make_order()

        tmp = self._make_tmp_file()
        doc_id = documents_service.save(None, tmp[0], 'zulu', 'description')
        self._clear_tmp_file(*tmp)

        tmp = self._make_tmp_file()
        doc_id2 = documents_service.save(None, tmp[0], 'zulu', 'description')
        self._clear_tmp_file(*tmp)

        documents_service.associate_to_order(order.order_id, [doc_id, doc_id2])
        assert len(documents_service.find_by_order_id(order.order_id)) == 2

        assert len(order.documents) == 2

        session().delete(order)
        session().commit()

        # Make sure all the docs of the part were removed
        try:
            documents_service.find_by_id(doc_id)
            self.fail()
        except NoResultFound as ex:
            pass

        assert len(documents_service.find_by_order_id(order.order_id)) == 0
Example #2
0
    def test_copy_template(self):

        tmp = self._make_tmp_file()
        tpl_id = documents_service.save_template(tmp[0], 'zulu')
        self._clear_tmp_file(*tmp)

        doc_id = documents_service.copy_template_to_document(tpl_id)

        assert documents_service.find_by_id(doc_id)
        assert documents_service.find_by_id(tpl_id)
Example #3
0
    def test_add_delete(self):
        tmp = self._make_tmp_file()
        doc_id = documents_service.save(None, tmp[0], 'zulu', 'description')
        documents_service.delete(doc_id)
        self._clear_tmp_file(*tmp)

        tmp = self._make_tmp_file()
        doc_id = documents_service.save(None, tmp[0], 'zulu.txt', 'description')

        d = documents_service.find_by_id(doc_id)
        assert d.filename == "zulu.txt"
        assert "koimes_{}_{}".format(doc_id,"zulu.txt") in d.server_location
        assert d.file_size == 8
        assert d.upload_date.year == datetime.today().year
        assert d.upload_date.month == datetime.today().month
        assert d.upload_date.day == datetime.today().day


        tmp2 = self._make_tmp_file()
        doc_id2 = documents_service.save(None, tmp2[0], 'zulu.txt', 'description')
        documents_service.delete(doc_id)
        documents_service.delete(doc_id2)

        self._clear_tmp_file(*tmp)
        self._clear_tmp_file(*tmp2)
Example #4
0
    def download_file(self, file_id):
        doc = documents_service.find_by_id(file_id)
        path = documents_service.path_to_file(file_id)

        # FIXME I have the feeling that CherryPy transcode the
        # filenamne from utf-8 to iso-8859-1 (or CP-1252 which is alike)
        # Or is it somehitng akin to :(IETF, RFC 2183, section 2.3 :
        # Current [RFC 2045] grammar restricts parameter values (and
        # hence Content-Disposition filenames) to US-ASCII.
        # ???

        mainlog.debug(u"download_file : {}".format(doc.filename))
        return cherrypy.lib.static.serve_file(path, "application/x-download",
                                              "attachment", doc.filename)
Example #5
0
    def test_add_delete_template(self):
        t = documents_service.all_templates()
        assert len(t) == 0

        tmp = self._make_tmp_file()
        tpl_id = documents_service.save_template(tmp[0], 'zulu.tpl')
        self._clear_tmp_file(*tmp)

        t = documents_service.all_templates()
        assert len(t) == 1

        d = documents_service.find_by_id(tpl_id)
        assert d.filename == "zulu.tpl"
        assert "koimes_{}_{}".format(tpl_id,"zulu.tpl") in d.server_location
        assert d.file_size == 8
        assert d.upload_date.year == datetime.today().year
        assert d.upload_date.month == datetime.today().month
        assert d.upload_date.day == datetime.today().day


        documents_service.delete(tpl_id)

        t = documents_service.all_templates()
        assert len(t) == 0