|
4 | 4 | from pyexcel.ext import xls |
5 | 5 | from db import Session, Base, Signature, Signature2, engine |
6 | 6 | import sys |
7 | | - |
8 | 7 | if sys.version_info[0] == 2 and sys.version_info[1] < 7: |
9 | 8 | from ordereddict import OrderedDict |
10 | 9 | else: |
11 | 10 | from collections import OrderedDict |
| 11 | +from nose.tools import raises |
| 12 | + |
12 | 13 |
|
13 | 14 | OUTPUT = "response_test.xls" |
14 | 15 |
|
15 | 16 |
|
16 | 17 | class TestInput(webio.ExcelInput): |
| 18 | + """This is sample implementation that read excel source from file""" |
17 | 19 | def load_single_sheet(self, filename=None, sheet_name=None, **keywords): |
| 20 | + """Load a single sheet""" |
18 | 21 | return pe.get_sheet(file_name=filename, **keywords) |
19 | 22 |
|
20 | 23 | def load_book(self, filename=None, **keywords): |
| 24 | + """Load a book""" |
21 | 25 | return pe.get_book(file_name=filename, **keywords) |
22 | 26 |
|
| 27 | + |
23 | 28 | def dumpy_response(content, content_type=None, status=200): |
| 29 | + """A dummy response""" |
24 | 30 | f = open(OUTPUT, 'wb') |
25 | 31 | f.write(content) |
26 | 32 | f.close() |
27 | 33 |
|
28 | 34 |
|
29 | 35 | webio.ExcelResponse = dumpy_response |
30 | | - |
31 | | - |
| 36 | + |
| 37 | + |
| 38 | +class TestExceptions: |
| 39 | + @raises(NotImplementedError) |
| 40 | + def test_load_single_sheet(self): |
| 41 | + testinput = webio.ExcelInput() |
| 42 | + testinput.get_sheet(filename="test") # booom |
| 43 | + |
| 44 | + @raises(NotImplementedError) |
| 45 | + def test_load_book(self): |
| 46 | + testinput = webio.ExcelInput() |
| 47 | + testinput.get_book(filename="test") # booom |
| 48 | + |
| 49 | + def test_get_sheet(self): |
| 50 | + myinput = TestInput() |
| 51 | + sheet = myinput.get_sheet(unrelated="foo bar") |
| 52 | + assert sheet == None |
| 53 | + |
| 54 | + def test_get_array(self): |
| 55 | + myinput = TestInput() |
| 56 | + array = myinput.get_array(unrelated="foo bar") |
| 57 | + assert array == None |
| 58 | + |
| 59 | + def test_get_dict(self): |
| 60 | + myinput = TestInput() |
| 61 | + result = myinput.get_dict(unrelated="foo bar") |
| 62 | + assert result == None |
| 63 | + |
| 64 | + def test_get_records(self): |
| 65 | + myinput = TestInput() |
| 66 | + result = myinput.get_records(unrelated="foo bar") |
| 67 | + assert result == None |
| 68 | + |
| 69 | + def test_get_book(self): |
| 70 | + myinput = TestInput() |
| 71 | + result = myinput.get_book(unrelated="foo bar") |
| 72 | + assert result == None |
| 73 | + |
| 74 | + def test_get_book_dict(self): |
| 75 | + myinput = TestInput() |
| 76 | + result = myinput.get_book_dict(unrelated="foo bar") |
| 77 | + assert result == None |
| 78 | + |
| 79 | +# excel inputs |
| 80 | + |
32 | 81 | class TestExcelInput: |
33 | 82 | def setUp(self): |
34 | 83 | self.data = [ |
@@ -103,10 +152,21 @@ def test_get_book_dict(self): |
103 | 152 | assert result["sheet1"] == self.data |
104 | 153 | assert result["sheet2"] == self.data1 |
105 | 154 |
|
| 155 | + def test_save_to_database(self): |
| 156 | + Base.metadata.drop_all(engine) |
| 157 | + Base.metadata.create_all(engine) |
| 158 | + self.session = Session() |
| 159 | + myinput = TestInput() |
| 160 | + myinput.save_book_to_database(filename=self.testfile, session=self.session, tables=[Signature, Signature2]) |
| 161 | + array = pe.get_array(session=self.session, table=Signature) |
| 162 | + assert array == self.data |
| 163 | + array = pe.get_array(session=self.session, table=Signature2) |
| 164 | + assert array == self.data1 |
106 | 165 |
|
107 | 166 | def tearDown(self): |
108 | 167 | os.unlink(self.testfile) |
109 | 168 |
|
| 169 | +## responses |
110 | 170 |
|
111 | 171 | class TestResponse: |
112 | 172 | def setUp(self): |
|
0 commit comments