Beispiel #1
0
    def test_post_create(self):
        '''it enqueues a job after being created'''
        with patch.object(theia.tasks, 'locate_scenes',
                          autospec=True) as mockLocate:
            with patch.object(mockLocate.return_value, 'delay',
                              autospec=True) as mockDelay:
                ImageryRequest.post_save(None, self.test_request, False)
                mockDelay.assert_not_called()

                ImageryRequest.post_save(None, self.test_request, True)
                mockDelay.assert_called_once_with(self.test_request.id)
Beispiel #2
0
 def test_search_build_overview(self):
     imageryRequest = ImageryRequest(dataset_name='ds9',
                                     wgs_row=23,
                                     wgs_path=47,
                                     max_cloud_cover=65)
     search_obj = ImagerySearch.build_search(imageryRequest)
     print("SEARCH OBJ")
     print(search_obj)
     assert search_obj == {
         'datasetName': 'ds9',
         'sceneFilter': {
             'metadataFilter': {
                 'filterType':
                 'and',
                 'childFilters': [{
                     'filterType': 'value',
                     'filterId': '5e83d0b81d20cee8',
                     'value': '47'
                 }, {
                     'filterType': 'value',
                     'filterId': '5e83d0b849ed5ee7',
                     'value': '23'
                 }, {
                     'filterType': 'value',
                     'filterId': '5e83d0b83a03f8ee',
                     'value': 'DAY'
                 }]
             },
             'cloudCoverFilter': {
                 'max': 65,
                 'min': 0
             }
         }
     }
Beispiel #3
0
    def test_process_request(self, mock_wait, mock_rso, mock_order_all, mock_search, mock_build):
        request = ImageryRequest()
        Adapter().process_request(request)

        mock_build.assert_called_once_with(request)
        mock_search.assert_called_once_with({})
        mock_order_all.assert_called_once_with('some scene id', 'sr')
        mock_rso.assert_called_once()
        mock_wait.assert_called_once_with(3)
Beispiel #4
0
def test_process_bundle(mock_input_files, mock_resolve, mock_apply,
                        mock_retrieve):
    project = Project(id=4)
    project.save()

    pipeline = Pipeline(project=project)
    pipeline.save()

    stage_1 = PipelineStage(operation='noop',
                            pipeline=pipeline,
                            sort_order=1,
                            config={})
    stage_1.save()

    stage_2 = PipelineStage(operation='noop',
                            select_images=['blue'],
                            pipeline=pipeline,
                            sort_order=2,
                            config={})
    stage_2.save()

    request = ImageryRequest(adapter_name='dummy',
                             pipeline=pipeline,
                             project=project)
    request.save()

    bundle = JobBundle(id=3, total_stages=2)
    bundle.imagery_request = request
    bundle.pipeline = pipeline
    bundle.save()

    tasks.process_bundle(3)

    assert (mock_apply.call_count == 2)
    second_method_call = mock_apply.call_args_list[1]
    arguments = second_method_call[0]
    file_list = arguments[0]
    assert str.endswith(file_list[0], '/theia/1_noop/input_file')

    mock_retrieve.assert_called_once()
Beispiel #5
0
    def test_from_requested_scene(self, mockCreate):
        project = Project(id=7)
        pipeline = Pipeline(project=project)
        request = ImageryRequest(pipeline=pipeline, project=project)
        scene = RequestedScene(imagery_request=request,
                               scene_entity_id='entity id')
        bundle = JobBundle.objects.from_requested_scene(scene)

        mockCreate.assert_called_once()
        mockCreate.assert_called_once_with(imagery_request=request,
                                           pipeline=pipeline,
                                           requested_scene=scene,
                                           scene_entity_id='entity id',
                                           total_stages=0)
 def setUp(self):
     self.request = ImageryRequest(adapter_name='dummy')
     self.stage = PipelineStage(
         select_images=['composite'],
         sort_order=3,
         config={
             'tile_size': 100,
             'tile_overlap': 10,
             'output_filename': 'foo.csv',
         },
     )
     self.bundle = JobBundle(current_stage=self.stage,
                             imagery_request=self.request)
     self.operation = ComputeCorners(self.bundle)
Beispiel #7
0
    def test_apply(self, mock_merge, mock_open, mock_get_new, mock_get_version):
        request = ImageryRequest(adapter_name='dummy')
        stage = PipelineStage(
            select_images=['green_channel', 'red_channel', 'blue_channel'],
            config={"red": "red_channel", "green": "green_channel", "blue": "blue_channel", "filename": "newish name"},
            sort_order=3
        )
        bundle = JobBundle(current_stage=stage, imagery_request=request)

        operation = ComposeImages(bundle)
        operation.apply(['green_tif', 'red_tif', 'blue_tif'])

        mock_open.assert_has_calls([call('green_tif'), call('red_tif'), call('blue_tif')])
        mock_merge.assert_called_once_with('RGB', (ANY, ANY, ANY))
        mock_merge.return_value.save.assert_called_once()
        first_method_call = mock_merge.return_value.save.call_args_list[0]
        args = first_method_call[0]
        assert str.endswith(args[0], '/theia/3_/totally new name')
Beispiel #8
0
    def test_do_apply(self, mockFromArray, mockOpen, mockRename, mockRemap):
        mockRemap.return_value = self.dummy_array
        mockOpen.return_value.read_image.return_value = self.dummy_array

        request = ImageryRequest(adapter_name='dummy')
        stage = PipelineStage(config={}, sort_order=3)
        bundle = JobBundle(current_stage=stage, imagery_request=request)

        operation = RemapImage(bundle)
        operation.apply(['literal filename'])

        mockRename.assert_called_once_with('literal filename')
        mockOpen.assert_called_once_with('literal filename')
        mockOpen.return_value.read_image.assert_called_once_with()
        mockRemap.assert_called_once_with(self.dummy_array)
        mockFromArray.assert_called_once_with(self.dummy_array)
        mockFromArray.return_value.save.assert_called_once_with(
            'versioned filename')
    def test_apply(self, mock_merge, mock_open, mock_get_new,
                   mock_get_version):
        request = ImageryRequest(adapter_name='dummy')
        stage = PipelineStage(select_images=['ggggg', 'rrr', 'bbbb'],
                              config={
                                  'red': 'rrr',
                                  'green': 'ggggg',
                                  'blue': 'bbbb',
                                  'filename': 'newish name'
                              },
                              sort_order=3)
        bundle = JobBundle(current_stage=stage, imagery_request=request)

        operation = ComposeImages(bundle)
        operation.apply(['neerg', 'erd', 'eulb'])

        mock_get_new.assert_called_once_with('newish name')
        mock_get_version.assert_called_once_with('new name')
        mock_open.assert_has_calls([call('erd'), call('neerg'), call('eulb')])
        mock_merge.assert_called_once_with('RGB', (ANY, ANY, ANY))
        mock_merge.return_value.save.assert_called_once_with(
            'totally new name')
Beispiel #10
0
def test_process_bundle(mock_resolve, mock_apply, mock_save, mock_get,
                        mock_retrieve):
    project = Project()
    pipeline = Pipeline(project=project)
    stage_1 = PipelineStage(operation='noop')
    stage_2 = PipelineStage(operation='noop', select_images=['blue'])
    request = ImageryRequest(adapter_name='dummy', pipeline=pipeline)

    with patch('theia.api.models.Pipeline.get_stages',
               return_value=[stage_1, stage_2]) as mockStages:
        bundle = mock_get.return_value
        bundle.imagery_request = request
        bundle.pipeline = pipeline

        tasks.process_bundle(3)

        assert (mock_save.call_count == 2)

        assert (mock_apply.call_count == 2)
        mock_apply.assert_called_with(['blue_resolved'])

        mock_resolve.assert_called_with(ANY, stage_2, bundle, 'blue')
        mock_retrieve.assert_called_once()
Beispiel #11
0
class TestImageryRequest(TestCase):
    def setUp(self):
        self.test_request = ImageryRequest(
            id=3,
            dataset_name='LANDSAT_8_C1',
            project_id=123,
            created_at=datetime.fromisoformat('2019-05-17'))

    def test___str__(self):
        assert '[ImageryRequest project 123 at 2019-05-17]' == self.test_request.__str__(
        )

    def test_post_create(self):
        '''it enqueues a job after being created'''
        with patch.object(theia.tasks, 'locate_scenes',
                          autospec=True) as mockLocate:
            with patch.object(mockLocate.return_value, 'delay',
                              autospec=True) as mockDelay:
                ImageryRequest.post_save(None, self.test_request, False)
                mockDelay.assert_not_called()

                ImageryRequest.post_save(None, self.test_request, True)
                mockDelay.assert_called_once_with(self.test_request.id)
 def test_builds_path_row_search(self, mockAddPath, mockAddName, *args):
     ir = ImageryRequest(wgs_row=1, wgs_path=2, dataset_name='ds9')
     search_obj = ImagerySearch.build_search(ir)
     mockAddName.assert_called_once_with({}, 'ds9')
     mockAddPath.assert_called_once_with({}, 1, 2)
     assert search_obj == {}
Beispiel #13
0
import pytest
from unittest.mock import patch, Mock, PropertyMock, call, ANY

import theia.tasks as tasks
from theia.api.models import ImageryRequest, JobBundle, Pipeline, PipelineStage, Project
from theia.adapters.dummy import Adapter


@patch('theia.api.models.ImageryRequest.objects.get',
       return_value=ImageryRequest(adapter_name='dummy'))
@patch('theia.adapters.dummy.Adapter.process_request')
def test_locate_scenes(mock_process, mock_get):
    tasks.locate_scenes(7)
    mock_get.assert_called_once_with(pk=7)
    mock_process.assert_called_once_with(mock_get.return_value)


@patch('theia.adapters.dummy.Adapter.retrieve')
@patch('theia.api.models.JobBundle.objects.get', return_value=JobBundle(id=3))
@patch('theia.api.models.JobBundle.save')
@patch('theia.operations.noop.NoOp.apply')
@patch('theia.tasks._resolve_name', return_value=['blue_resolved'])
def test_process_bundle(mock_resolve, mock_apply, mock_save, mock_get,
                        mock_retrieve):
    project = Project()
    pipeline = Pipeline(project=project)
    stage_1 = PipelineStage(operation='noop')
    stage_2 = PipelineStage(operation='noop', select_images=['blue'])
    request = ImageryRequest(adapter_name='dummy', pipeline=pipeline)

    with patch('theia.api.models.Pipeline.get_stages',
Beispiel #14
0
 def test_adds_dataset_name(self):
     imageryRequest = ImageryRequest(dataset_name='ds9')
     search_obj = ImagerySearch.build_search(imageryRequest)
     assert search_obj['datasetName'] == 'ds9'
Beispiel #15
0
 def test_resolve_relative_image(self):
     request = ImageryRequest(adapter_name='usgs', dataset_name='LANDSAT_8_C1')
     bundle = JobBundle(scene_entity_id='LC08', imagery_request=request, local_path='tmp/')
     assert(Adapter().resolve_relative_image(bundle, 'red') == 'LC08_sr_band4.tif')
Beispiel #16
0
 def setUp(self):
     self.test_request = ImageryRequest(
         id=3,
         dataset_name='LANDSAT_8_C1',
         project_id=123,
         created_at=datetime.fromisoformat('2019-05-17'))
Beispiel #17
0
    def test_limit_scenes(self, mock_wait, mock_rso, mock_order_all, mock_search, mock_build):
        request = ImageryRequest(max_results=3)
        Adapter().process_request(request)

        assert(mock_order_all.call_count==3)