-
Notifications
You must be signed in to change notification settings - Fork 2k
/
test_patch.py
129 lines (98 loc) · 4.07 KB
/
test_patch.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# encoding: utf-8
'''Unit tests for ckan/logic/action/patch.py.'''
import datetime
from nose.tools import assert_equals, assert_raises
import mock
from ckan.common import config
from ckan.tests import helpers, factories
class TestPatch(helpers.FunctionalTestBase):
def test_package_patch_updating_single_field(self):
user = factories.User()
dataset = factories.Dataset(
name='annakarenina',
notes='some test now',
user=user)
dataset = helpers.call_action(
'package_patch',
id=dataset['id'],
name='somethingnew')
assert_equals(dataset['name'], 'somethingnew')
assert_equals(dataset['notes'], 'some test now')
dataset2 = helpers.call_action('package_show', id=dataset['id'])
assert_equals(dataset2['name'], 'somethingnew')
assert_equals(dataset2['notes'], 'some test now')
def test_resource_patch_updating_single_field(self):
user = factories.User()
dataset = factories.Dataset(
name='annakarenina',
notes='some test now',
user=user,
resources=[{'url': 'http://example.com/resource'}])
resource = helpers.call_action(
'resource_patch',
id=dataset['resources'][0]['id'],
name='somethingnew')
assert_equals(resource['name'], 'somethingnew')
assert_equals(resource['url'], 'http://example.com/resource')
dataset2 = helpers.call_action('package_show', id=dataset['id'])
resource2 = dataset2['resources'][0]
assert_equals(resource2['name'], 'somethingnew')
assert_equals(resource2['url'], 'http://example.com/resource')
def test_group_patch_updating_single_field(self):
user = factories.User()
group = factories.Group(
name='economy',
description='some test now',
user=user)
group = helpers.call_action(
'group_patch',
id=group['id'],
description='somethingnew',
context={'user': user['name']})
assert_equals(group['name'], 'economy')
assert_equals(group['description'], 'somethingnew')
group2 = helpers.call_action('group_show', id=group['id'])
assert_equals(group2['name'], 'economy')
assert_equals(group2['description'], 'somethingnew')
def test_group_patch_preserve_datasets(self):
user = factories.User()
group = factories.Group(
name='economy',
description='some test now',
user=user)
factories.Dataset(groups=[{'name': group['name']}])
group2 = helpers.call_action('group_show', id=group['id'])
assert_equals(1, group2['package_count'])
group = helpers.call_action(
'group_patch',
id=group['id'],
context={'user': user['name']})
group3 = helpers.call_action('group_show', id=group['id'])
assert_equals(1, group3['package_count'])
group = helpers.call_action(
'group_patch',
id=group['id'],
packages=[],
context={'user': user['name']})
group4 = helpers.call_action(
'group_show', id=group['id'], include_datasets=True
)
assert_equals(0, group4['package_count'])
def test_organization_patch_updating_single_field(self):
user = factories.User()
organization = factories.Organization(
name='economy',
description='some test now',
user=user)
organization = helpers.call_action(
'organization_patch',
id=organization['id'],
description='somethingnew',
context={'user': user['name']})
assert_equals(organization['name'], 'economy')
assert_equals(organization['description'], 'somethingnew')
organization2 = helpers.call_action(
'organization_show',
id=organization['id'])
assert_equals(organization2['name'], 'economy')
assert_equals(organization2['description'], 'somethingnew')