Esempio n. 1
0
 def test_create_parsed_resource(self):
     args_in = [ 'create',
             '--description', 'Description of resource',
             '--author', 'fred', 
             '--author-email', 'fred@here', 
             '--data-type', 'feature collection',
             '--version', '1.0',
             '--maintainer', 'Joe',
             '--maintainer-email', 'joe@here',
             'test-repository', 'my_resource',
             self.filepath
             ]
     expected_metadata = dict(
             description='Description of resource',
             author='fred',
             author_email='fred@here',
             data_type='feature collection',
             version='1.0',
             maintainer='Joe',
             maintainer_email='joe@here',
             )
     resource_args = self.parser.parse_args(args_in)
     resource = ds_util.create_new_resource(resource_args)
     self.assertEquals(resource.metadata, expected_metadata)
     self.assertEquals(resource.files[0].path, self.filepath)
Esempio n. 2
0
    def test_create_new_resource_just_files(self,
            mock_os_path_isdir,
            mock_os_path_exists):
        resource_args = argparse.Namespace()
        setattr(resource_args, 'bundle', False)
        setattr(resource_args, 'metadata_file', {})
        setattr(resource_args, 'publish', False)
        setattr(resource_args, 'filenames', ['file1','file2'])
        setattr(resource_args, 'resource_name', 'dummy-resource')

        mock_os_path_exists.return_value = True
        mock_os_path_isdir.return_value = False
        with patch('bdkd.datastore.Resource.new') as mock_Resource_new:
            resource = ds_util.create_new_resource(resource_args)
        mock_Resource_new.assert_called_once_with('dummy-resource', 
                files_data=['file1','file2'],
                do_bundle=False,
                metadata={},
                publish=False)
Esempio n. 3
0
    def test_create_new_resource_just_files(self, mock_os_path_isdir,
                                            mock_os_path_exists):
        resource_args = argparse.Namespace()
        setattr(resource_args, 'bundle', False)
        setattr(resource_args, 'metadata_file', {})
        setattr(resource_args, 'publish', False)
        setattr(resource_args, 'filenames', ['file1', 'file2'])
        setattr(resource_args, 'resource_name', 'dummy-resource')

        mock_os_path_exists.return_value = True
        mock_os_path_isdir.return_value = False
        with patch('bdkd.datastore.Resource.new') as mock_Resource_new:
            resource = ds_util.create_new_resource(resource_args)
        mock_Resource_new.assert_called_once_with(
            'dummy-resource',
            files_data=['file1', 'file2'],
            do_bundle=False,
            metadata={},
            publish=False)
Esempio n. 4
0
    def test_create_new_resource_files_and_remote(self, mock_os_path_isdir,
                                                  mock_os_path_exists):
        resource_args = argparse.Namespace()
        setattr(resource_args, 'bundle', False)
        setattr(resource_args, 'metadata_file', {})
        setattr(resource_args, 'publish', False)
        setattr(resource_args, 'filenames',
                ['file1', 'http://test.dummy/file2', 'file3'])
        setattr(resource_args, 'resource_name', 'dummy-resource')

        mock_os_path_exists.side_effect = lambda f: f[0:4] == 'file'
        mock_os_path_isdir.return_value = False
        with patch('bdkd.datastore.Resource.new') as mock_Resource_new:
            resource = ds_util.create_new_resource(resource_args)
        mock_Resource_new.assert_called_once_with(
            'dummy-resource',
            files_data=['file1', 'http://test.dummy/file2', 'file3'],
            metadata={},
            do_bundle=False,
            publish=False)
Esempio n. 5
0
    def test_create_new_resource_files_and_remote(self,
            mock_os_path_isdir,
            mock_os_path_exists):
        resource_args = argparse.Namespace()
        setattr(resource_args, 'bundle', False)
        setattr(resource_args, 'metadata_file', {})
        setattr(resource_args, 'publish', False)
        setattr(resource_args, 'filenames', ['file1','http://test.dummy/file2','file3'])
        setattr(resource_args, 'resource_name', 'dummy-resource')


        mock_os_path_exists.side_effect = lambda f: f[0:4] == 'file'
        mock_os_path_isdir.return_value = False
        with patch('bdkd.datastore.Resource.new') as mock_Resource_new:
            resource = ds_util.create_new_resource(resource_args)
        mock_Resource_new.assert_called_once_with(
            'dummy-resource',
            files_data=['file1','http://test.dummy/file2', 'file3'],
            metadata={},
            do_bundle=False,
            publish=False)
Esempio n. 6
0
 def test_create_parsed_resource(self):
     args_in = [
         'create', '--description', 'Description of resource', '--author',
         'fred', '--author-email', 'fred@here', '--data-type',
         'feature collection', '--version', '1.0', '--maintainer', 'Joe',
         '--maintainer-email', 'joe@here', 'test-repository', 'my_resource',
         self.filepath
     ]
     expected_metadata = dict(
         description='Description of resource',
         author='fred',
         author_email='fred@here',
         data_type='feature collection',
         version='1.0',
         maintainer='Joe',
         maintainer_email='joe@here',
     )
     resource_args = self.parser.parse_args(args_in)
     resource = ds_util.create_new_resource(resource_args)
     self.assertEquals(resource.metadata, expected_metadata)
     self.assertEquals(resource.files[0].path, self.filepath)
Esempio n. 7
0
    def test_create_new_resource_files_and_dirs(self,
            mock_walk,
            mock_os_path_isdir,
            mock_os_path_exists,
            mock_Resource_new):
        resource_args = argparse.Namespace()
        setattr(resource_args, 'bundle', False)
        setattr(resource_args, 'metadata_file', {})
        setattr(resource_args, 'publish', False)
        setattr(resource_args, 'filenames', ['file1','dir1'])
        setattr(resource_args, 'resource_name', 'dummy-resource')

        mock_os_path_exists.return_value = True
        mock_os_path_isdir.side_effect = lambda f: 'file' not in f
        mock_walk.return_value = [
            ('dir1', ['emptydir','subdir1','subdir2' ], []),
            ('dir1/emptydir', [], []),
            ('dir1/subdir1', [], ['file1']),
            ('dir1/subdir2', [], ['file2'])
            ]
        # Simulates the following file structure:
        # ./file1
        # ./dir1/
        # ./dir1/emptydir/
        # ./dir1/subdir1/
        # ./dir1/subdir1/file1
        # ./dir1/subdir2/
        # ./dir1/subdir2/file2
        # When adding with the parameter 'file1 dir1', it will create a resource
        # containing the file 'file1' and all files inside directory 'dir1'

        resource = ds_util.create_new_resource(resource_args)
        mock_Resource_new.assert_called_once_with(
            'dummy-resource', 
            do_bundle=False,
            files_data=['file1','dir1/subdir1/file1','dir1/subdir2/file2'],
            metadata={},
            publish=False)
Esempio n. 8
0
    def test_create_new_resource_files_and_dirs(self, mock_walk,
                                                mock_os_path_isdir,
                                                mock_os_path_exists,
                                                mock_Resource_new):
        resource_args = argparse.Namespace()
        setattr(resource_args, 'bundle', False)
        setattr(resource_args, 'metadata_file', {})
        setattr(resource_args, 'publish', False)
        setattr(resource_args, 'filenames', ['file1', 'dir1'])
        setattr(resource_args, 'resource_name', 'dummy-resource')

        mock_os_path_exists.return_value = True
        mock_os_path_isdir.side_effect = lambda f: 'file' not in f
        mock_walk.return_value = [('dir1', ['emptydir', 'subdir1',
                                            'subdir2'], []),
                                  ('dir1/emptydir', [], []),
                                  ('dir1/subdir1', [], ['file1']),
                                  ('dir1/subdir2', [], ['file2'])]
        # Simulates the following file structure:
        # ./file1
        # ./dir1/
        # ./dir1/emptydir/
        # ./dir1/subdir1/
        # ./dir1/subdir1/file1
        # ./dir1/subdir2/
        # ./dir1/subdir2/file2
        # When adding with the parameter 'file1 dir1', it will create a resource
        # containing the file 'file1' and all files inside directory 'dir1'

        resource = ds_util.create_new_resource(resource_args)
        mock_Resource_new.assert_called_once_with(
            'dummy-resource',
            do_bundle=False,
            files_data=['file1', 'dir1/subdir1/file1', 'dir1/subdir2/file2'],
            metadata={},
            publish=False)