forked from Flying-Free/pyopenproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_service_test.py
105 lines (94 loc) · 3.57 KB
/
grid_service_test.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import json
import os
from pyopenproject.model.grid import Grid
from tests.test_cases.openproject_test_case import OpenProjectTestCase
class GridServiceTestCase(OpenProjectTestCase):
def setUp(self):
super().setUp()
DATA = os.path.join(self.TEST_CASES, '../data/grid.json')
self.gridSer = self.op.get_grid_service()
with open(DATA) as f:
self.grid = Grid(json.load(f))
def test_find(self):
self.assertIsNotNone(self.gridSer.find(self.grid))
# TODO: FIXME: urn:openproject-org:api:v3:errors:InvalidQuery","message":["Filters Page does not exist."]
def test_find_all_with_filters(self):
# grids = self.gridSer.find_all(25, 25, [Filter("page", "=", ["/my/page"])], sort_by=None)
# self.assertEqual(0, len(grids))
pass
def test_find_all(self):
grids = self.gridSer.find_all()
self.assertEqual(7, len(grids))
# FIXME {
# "_type":"Error",
# "errorIdentifier":"urn:openproject-org:api:v3:errors:InvalidRequestBody",
# "message":"The request could not be parsed as JSON.",
# "_embedded":{"details":{"parseError":"unexpected character (after ) at line 1, column 1"}}
# }
def test_create(self):
g = Grid(self.gridSer.create_form()["_embedded"]["payload"])
demo_widget = {
"identifier": "time_entries_current_user",
"startRow": 1,
"endRow": 8,
"startColumn": 1,
"endColumn": 3
}
g.widgets.append(demo_widget)
# g = self.gridSer.create(g)
# self.assertEqual(g.widgets[0], self.gridSer.find(g).widgets[0])
# FIXME
# {
# "_type":"Error",
# "errorIdentifier":"urn:openproject-org:api:v3:errors:InternalServerError",
# "message":"An internal error has occured. 405 Not Allowed"
# }
def test_update(self):
demo_widget = {
"identifier": "time_entries_current_user",
"startRow": 1,
"endRow": 8,
"startColumn": 1,
"endColumn": 3
}
grids = self.gridSer.find_all()
grid = grids[0]
grid.widgets.append(demo_widget)
# grid = self.gridSer.update(grid)
# self.assertEqual(demo_widget, grid.widgets[0])
def test_create_form(self):
expected = Grid({'rowCount': 4, 'columnCount': 5, 'options': {}, 'widgets': [], '_links': {'attachments': []}})
grid = Grid(self.gridSer.create_form()["_embedded"]["payload"])
self.assertEqual(expected.__dict__, grid.__dict__)
def test_update_form(self):
form = {
"rowCount": 8,
"columnCount": 5,
"widgets": [
{
"identifier": "time_entries_current_user",
"startRow": 1,
"endRow": 8,
"startColumn": 1,
"endColumn": 3
},
{
"identifier": "news",
"startRow": 3,
"endRow": 8,
"startColumn": 4,
"endColumn": 5
},
{
"identifier": "documents",
"startRow": 1,
"endRow": 3,
"startColumn": 3,
"endColumn": 6
}
]
}
grid = list(filter(lambda x: x.id == 1, self.gridSer.find_all()))[0]
self.gridSer.update_form(grid, form)
new_grid = list(filter(lambda x: x.id == 1, self.gridSer.find_all()))[0]
self.assertNotEqual(grid, new_grid)