예제 #1
0
 def test_create_bad_option(self):
     load_things_worker(self.ckan, 'datasets', {
             '--create-only': False,
             '--update-only': True,
             },
         stdin=BytesIO(b'{"name": "45","title":"Forty-five"}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'show')
     self.assertEqual(error, 'NotFound')
     self.assertEqual(data, [None, '45'])
예제 #2
0
 def test_update_unauthorized(self):
     load_things_worker(self.ckan, 'datasets', {
             '--create-only': False,
             '--update-only': False,
             },
         stdin=BytesIO(b'{"name": "seekrit", "title": "Things"}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'show')
     self.assertEqual(error, 'NotAuthorized')
     self.assertEqual(data, 'naughty user')
예제 #3
0
 def test_update_organization_with_users_cleared(self):
     load_things_worker(self.ckan, 'organizations', {
             '--create-only': False,
             '--update-only': False,
             },
         stdin=BytesIO(b'{"id": "unused", "users": []}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'update')
     self.assertEqual(error, None)
     self.assertEqual(data, 'users-cleared')
예제 #4
0
 def test_update_group(self):
     load_things_worker(self.ckan, 'groups', {
             '--create-only': False,
             '--update-only': False,
             },
         stdin=BytesIO(b'{"id": "ab","title":"a balloon"}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'update')
     self.assertEqual(error, None)
     self.assertEqual(data, 'group-updated')
예제 #5
0
 def test_update_only(self):
     load_things_worker(self.ckan, 'datasets', {
             '--create-only': False,
             '--update-only': True,
             },
         stdin=BytesIO(b'{"name": "34","title":"3.4 times ten"}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'update')
     self.assertEqual(error, None)
     self.assertEqual(data, 'something-updated')
예제 #6
0
 def test_update_bad_option(self):
     load_things_worker(self.ckan, 'datasets', {
             '--create-only': True,
             '--update-only': False,
             },
         stdin=BytesIO(b'{"name": "34","title":"3.4 times ten"}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'create')
     self.assertEqual(error, 'ValidationError')
     self.assertEqual(data, {'name': 'That URL is already in use.'})
예제 #7
0
 def test_update_with_corrupted_resources(self):
     load_things_worker(self.ckan, 'datasets', {
             '--create-only': False,
             '--update-only': False,
             },
         stdin=BytesIO(b'{"name": "30ish","title":"3.4 times ten","resources":[{"id":"123"}]}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'update')
     self.assertEqual(error, "Important attributes missing in resources")
     self.assertEqual(data, 'something-updated')
예제 #8
0
 def test_create_with_corrupted_resources(self):
     load_things_worker(self.ckan, 'datasets', {
             '--create-only': False,
             '--update-only': False,
             '--upload-resources':False,
             },
         stdin=BytesIO(b'{"name": "45","title":"Forty-five","resources":[{"id":"123"}]}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'create')
     self.assertEqual(error, None)
     self.assertEqual(data, 'something-new')
예제 #9
0
 def test_create_empty_dict(self):
     load_things_worker(self.ckan, 'datasets', {
             '--create-only': False,
             '--update-only': False,
             '--upload-resources':False,
             },
         stdin=BytesIO(b'{}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'create')
     self.assertEqual(error, None)
     self.assertEqual(data, 'something-new')
예제 #10
0
 def test_update_with_complete_resources(self):
     load_things_worker(self.ckan, 'datasets', {
             '--create-only': False,
             '--update-only': False,
             },
         stdin=BytesIO(
              b'{"name": "30ish","title":"3.4 times ten",'
              b'"resources":[{"id":"123","url_type":"","url":"http://example.com"}]}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'update')
     self.assertEqual(error, None)
     self.assertEqual(data, 'something-updated')
예제 #11
0
 def test_create_empty_dict(self):
     load_things_worker(self.ckan,
                        'datasets', {
                            '--create-only': False,
                            '--update-only': False,
                            '--upload-resources': False,
                        },
                        stdin=BytesIO(b'{}\n'),
                        stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'create')
     self.assertEqual(error, None)
     self.assertEqual(data, 'something-new')
예제 #12
0
 def test_update_organization_with_users_unchanged(self):
     load_things_worker(self.ckan,
                        'organizations', {
                            '--create-only': False,
                            '--update-only': False,
                            '--upload-resources': False,
                            '--insecure': False
                        },
                        stdin=BytesIO(b'{"id": "used", "title": "here"}\n'),
                        stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'update')
     self.assertEqual(error, None)
     self.assertEqual(data, 'users-unchanged')
예제 #13
0
 def test_update_with_corrupted_resources(self):
     load_things_worker(
         self.ckan,
         'datasets', {
             '--create-only': False,
             '--update-only': False,
         },
         stdin=BytesIO(
             b'{"name": "30ish","title":"3.4 times ten","resources":[{"id":"123"}]}\n'
         ),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'update')
     self.assertEqual(error, "Important attributes missing in resources")
     self.assertEqual(data, 'something-updated')
예제 #14
0
 def test_create_with_no_resources(self):
     load_things_worker(
         self.ckan,
         'datasets', {
             '--create-only': False,
             '--update-only': False,
             '--upload-resources': False,
             '--insecure': False
         },
         stdin=BytesIO(b'{"name": "45","title":"Forty-five"}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'create')
     self.assertEqual(error, None)
     self.assertEqual(data, 'something-new')
예제 #15
0
 def test_update_with_complete_resources(self):
     load_things_worker(
         self.ckan,
         'datasets', {
             '--create-only': False,
             '--update-only': False,
         },
         stdin=BytesIO(
             b'{"name": "30ish","title":"3.4 times ten",'
             b'"resources":[{"id":"123","url_type":"","url":"http://example.com"}]}\n'
         ),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response[-1:], b'\n')
     timstamp, action, error, data = json.loads(response.decode('UTF-8'))
     self.assertEqual(action, 'update')
     self.assertEqual(error, None)
     self.assertEqual(data, 'something-updated')
예제 #16
0
 def test_update_organization_two(self):
     load_things_worker(self.ckan, 'organizations', {
             '--create-only': False,
             '--update-only': False,
             },
         stdin=BytesIO(
             b'{"name": "cd", "title": "Go"}\n'
             b'{"name": "ef", "title": "Play"}\n'),
         stdout=self.stdout)
     response = self.stdout.getvalue()
     self.assertEqual(response.count(b'\n'), 2, response)
     self.assertEqual(response[-1:], b'\n')
     r1, r2 = response.split(b'\n', 1)
     timstamp, action, error, data = json.loads(r1.decode('UTF-8'))
     self.assertEqual(action, 'update')
     self.assertEqual(error, None)
     self.assertEqual(data, 'org-updated')
     timstamp, action, error, data = json.loads(r2.decode('UTF-8'))
     self.assertEqual(action, 'create')
     self.assertEqual(error, None)
     self.assertEqual(data, 'org-created')