File: testform.py

package info (click to toggle)
python-odf 1.3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,356 kB
  • ctags: 1,902
  • sloc: python: 21,654; makefile: 352; sh: 10; xml: 2
file content (90 lines) | stat: -rw-r--r-- 3,177 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2008-2010 Søren Roug, European Environment Agency
#
# This is free software.  You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
# 2 or at your option any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
# Contributor(s):
#

import unittest, os, os.path
from odf.opendocument import OpenDocumentSpreadsheet
import odf.table
import odf.office
import odf.form
import odf.draw

class TestForm(unittest.TestCase):
    def test_ooo_ns(self):
        """ Check that ooo exists in namespace declarations """
        calcdoc = OpenDocumentSpreadsheet()
        table = odf.table.Table(name="Costs")
        forms = odf.office.Forms()
        form = odf.form.Form(
           controlimplementation="ooo:com.sun.star.form.component.Form")
        lb = odf.form.Listbox(
           controlimplementation="ooo:com.sun.star.form.component.ListBox", dropdown="true", id="control1")
        form.addElement(lb)
        forms.addElement(form)
        table.addElement(forms)

        # One empty line
        tr = odf.table.TableRow()
        table.addElement(tr)

        tr = odf.table.TableRow()
        # One empty cell
        cell = odf.table.TableCell()
        tr.addElement(cell)

        cell = odf.table.TableCell()

        draw = odf.draw.Control(
        control="control1", height="0.1126in", width="0.798in",
        x="0.0303in", y="0.0205in", endcelladdress="Costs.B2",
        endx="0.8283in", endy="0.1331in")

        cell.addElement(draw)
        tr.addElement(cell)
        table.addElement(tr)

        calcdoc.spreadsheet.addElement(table)
        result = calcdoc.contentxml() # contentxml() is supposed to yeld a bytes
        self.assertNotEqual(-1, result.find(b'''xmlns:ooo="http://openoffice.org/2004/office"'''))

    def test_form_controls(self):
        odf.form.Button(id="Button")
        odf.form.Checkbox(id="Checkbox")
        odf.form.Combobox(id="Combobox")
        odf.form.Date(id="Date")
        odf.form.File(id="File")
        odf.form.FixedText(id="FixedText")
        odf.form.FormattedText(id="FormattedText")
        odf.form.Frame(id="Frame")
        odf.form.GenericControl(id="GenericControl")
        odf.form.Grid(id="Grid")
        odf.form.Hidden(id="Hidden")
        odf.form.Image(id="Image")
        odf.form.ImageFrame(id="ImageFrame")
        odf.form.Listbox(id="Listbox")
        odf.form.Number(id="Number")
        odf.form.Password(id="Password")
        odf.form.Radio(id="Radio")
        odf.form.Text(id="Text")
        odf.form.Textarea(id="Textarea")
        odf.form.Time(id="Time")
        odf.form.ValueRange(id="ValueRange")

if __name__ == '__main__':
    unittest.main()