Пример #1
0
 def test_take_thermal_still_skips_scale_image_when_requested(self,
                                                              cs_take_thermal_still,
                                                              ans_scale_image,
                                                              ads_clean_up_files,
                                                              ads_send_mail):
     snap_id = uuid.uuid4()
     group_id = get_group_document('current')['_id']
     ct.take_thermal_still(snap_id=snap_id, group_id=group_id, delay=0, repeat=0, scale_image=False)
     cs_take_thermal_still.assert_called_once_with(snap_id, group_id, ANY)
     ans_scale_image.assert_not_called()
     ads_send_mail.assert_called_once_with(snap_id, group_id)
     ads_clean_up_files.assert_called_once_with(snap_id, group_id)
Пример #2
0
 def test_take_thermal_still_calls_all_chained_tasks_multiple_times_when_repeat_specified(self,
                                                                                          cs_take_thermal_still,
                                                                                          ans_scale_image,
                                                                                          ads_clean_up_files,
                                                                                          ads_send_mail):
     snap_id = uuid.uuid4()
     group_id = get_group_document('current')['_id']
     ct.take_thermal_still(snap_id=snap_id, group_id=group_id, delay=0, repeat=1)
     cs_take_thermal_still.assert_has_calls([call(snap_id, group_id, ANY), call(ANY, group_id, ANY)])
     ans_scale_image.assert_has_calls([call(ANY, ANY, group_id), call(ANY, ANY, group_id)])
     ads_send_mail.assert_has_calls([call(snap_id, group_id), call(ANY, group_id)])
     ads_clean_up_files.assert_has_calls([call(snap_id, group_id), call(ANY, group_id)])
Пример #3
0
 def test_take_thermal_still_calls_all_chained_tasks(self,
                                                     cs_take_thermal_still,
                                                     ans_scale_image,
                                                     ads_clean_up_files,
                                                     ads_send_mail):
     snap_id = uuid.uuid4()
     group_id = get_group_document('current')['_id']
     ct.take_thermal_still(snap_id=snap_id, group_id=group_id, delay=0, repeat=0)
     cs_take_thermal_still.assert_called_once_with(snap_id, group_id, ANY)
     ans_scale_image.assert_called_once_with(ANY, ANY, group_id)
     ads_clean_up_files.assert_called_once_with(snap_id, group_id)
     ads_send_mail.assert_called_once_with(snap_id, group_id)
Пример #4
0
    def test_take_thermal_still_calls_expected_methods_with_defaults_for_delay_repeat_and_clean_up_files_on(
            self):
        camera.services.take_thermal_still = Mock()
        analysis.services.scale_image = Mock()
        admin.services.send_mail = Mock()
        admin.services.upload_files_to_s3 = Mock()
        admin.services.clean_up_files = Mock()

        return_value = ct.take_thermal_still('some_snap_id', 'some_group_id')

        camera.services.take_thermal_still.assert_called_once_with(
            'some_snap_id', 'some_group_id', ANY, True)
        analysis.services.scale_image.assert_called_once_with(ANY,
                                                              ANY,
                                                              'some_group_id',
                                                              scale_image=True)
        admin.services.send_mail.assert_called_once_with(
            'some_snap_id', 'some_group_id')
        admin.services.upload_files_to_s3.assert_called_once_with(
            'some_snap_id', 'some_group_id')
        admin.services.clean_up_files.assert_called_once_with(
            'some_snap_id', 'some_group_id')
        assert return_value == {
            'snap_ids': ['some_snap_id'],
            'group_id': 'some_group_id',
            'pic_ids': [ANY],
            'scaled_pic_ids': [ANY]
        }
Пример #5
0
def thermal_still():
    '''
    Api endpoint for taking one or a series of Lepton stills.  
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()
    scale_image = get_scale_image_parameter()
    ret_dict = take_thermal_still(snap_id=snap_id, group_id=group_id, delay=delay, repeat=repeat, scale_image=scale_image)
    return Response(json.dumps(ret_dict), status=202, mimetype='application/json')
Пример #6
0
    def test_take_thermal_still_calls_expected_methods_with_expected_values_when_clean_up_files_of(self):
        camera.services.take_thermal_still = Mock()
        analysis.services.scale_image = Mock()
        admin.services.send_mail = Mock()
        admin.services.upload_files_to_s3 = Mock()
        admin.services.clean_up_files = Mock()

        return_value = ct.take_thermal_still('some_snap_id', 'some_group_id', clean_up_files=False)

        camera.services.take_thermal_still.assert_called_once_with('some_snap_id', 'some_group_id', ANY, False)
        assert return_value == {'snap_ids': ['some_snap_id'],
                                'group_id': 'some_group_id',
                                'pic_ids': [ANY],
                                'scaled_pic_ids': [ANY]}
Пример #7
0
    def test_take_thermal_still_calls_expected_methods_with_defaults_for_delay_repeat_and_clean_up_files_on(self):
        camera.services.take_thermal_still = Mock()
        analysis.services.scale_image = Mock()
        admin.services.send_mail = Mock()
        admin.services.upload_files_to_s3 = Mock()
        admin.services.clean_up_files = Mock()

        return_value = ct.take_thermal_still('some_snap_id', 'some_group_id')

        camera.services.take_thermal_still.assert_called_once_with('some_snap_id', 'some_group_id', ANY, True)
        analysis.services.scale_image.assert_called_once_with(ANY, ANY, 'some_group_id', scale_image=True)
        admin.services.send_mail.assert_called_once_with('some_snap_id', 'some_group_id')
        admin.services.upload_files_to_s3.assert_called_once_with('some_snap_id', 'some_group_id')
        admin.services.clean_up_files.assert_called_once_with('some_snap_id', 'some_group_id')
        assert return_value == {'snap_ids': ['some_snap_id'],
                                'group_id': 'some_group_id',
                                'pic_ids': [ANY],
                                'scaled_pic_ids': [ANY]}
Пример #8
0
def thermal_still():
    '''
    Api endpoint for taking one or a series of Lepton stills.  
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    snap_id = uuid.uuid4()
    group_id = get_settings_document()['current_group_id']
    delay = get_delay_parameter()
    repeat = get_repeat_parameter()
    scale_image = get_scale_image_parameter()
    ret_dict = take_thermal_still(snap_id=snap_id,
                                  group_id=group_id,
                                  delay=delay,
                                  repeat=repeat,
                                  scale_image=scale_image)
    return Response(json.dumps(ret_dict),
                    status=202,
                    mimetype='application/json')
Пример #9
0
def thermal_still():
    '''
    Api endpoint for taking one or a series of Lepton stills.
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Cleaning up files comes in via a GET parameter, note that empty string is the ONLY thing that will force it to false
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    try:
        snap_id = uuid.uuid4()
        group_id = get_settings_document()['current_group_id']
        args_dict = gather_and_enforce_request_args([{
            'name': 'delay',
            'default': 0,
            'cast_function': int
        }, {
            'name': 'repeat',
            'default': 0,
            'cast_function': int
        }, {
            'name': 'clean_up_files',
            'default': True,
            'cast_function': bool
        }, {
            'name': 'scale_image',
            'default': True,
            'cast_function': bool
        }])
        # TODO specify that is (snap_id, group_id, **args_dict soon)
        ret_dict = take_thermal_still(
            snap_id=snap_id,
            group_id=group_id,
            delay=args_dict['delay'],
            repeat=args_dict['repeat'],
            scale_image=args_dict['scale_image'],
            clean_up_files=args_dict['clean_up_files'])
        return Response(json.dumps(ret_dict),
                        status=202,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
Пример #10
0
    def test_take_thermal_still_calls_expected_methods_with_expected_values_when_clean_up_files_of(
            self):
        camera.services.take_thermal_still = Mock()
        analysis.services.scale_image = Mock()
        admin.services.send_mail = Mock()
        admin.services.upload_files_to_s3 = Mock()
        admin.services.clean_up_files = Mock()

        return_value = ct.take_thermal_still('some_snap_id',
                                             'some_group_id',
                                             clean_up_files=False)

        camera.services.take_thermal_still.assert_called_once_with(
            'some_snap_id', 'some_group_id', ANY, False)
        assert return_value == {
            'snap_ids': ['some_snap_id'],
            'group_id': 'some_group_id',
            'pic_ids': [ANY],
            'scaled_pic_ids': [ANY]
        }
Пример #11
0
    def test_take_thermal_still_calls_expected_methods_with_nonzero_for_repeat(
            self):
        camera.services.take_thermal_still = Mock()
        analysis.services.scale_image = Mock()
        admin.services.send_mail = Mock()
        admin.services.upload_files_to_s3 = Mock()
        admin.services.clean_up_files = Mock()

        return_value = ct.take_thermal_still('some_snap_id',
                                             'some_group_id',
                                             delay=0,
                                             repeat=1)

        camera.services.take_thermal_still.assert_has_calls([
            call('some_snap_id', 'some_group_id', ANY, True),
            call(ANY, 'some_group_id', ANY, True)
        ])
        analysis.services.scale_image.assert_has_calls([
            call(ANY, ANY, 'some_group_id', scale_image=True),
            call(ANY, ANY, 'some_group_id', scale_image=True)
        ])
        admin.services.send_mail.assert_has_calls([
            call('some_snap_id', 'some_group_id'),
            call(ANY, 'some_group_id')
        ])
        admin.services.upload_files_to_s3.assert_has_calls([
            call('some_snap_id', 'some_group_id'),
            call(ANY, 'some_group_id')
        ])
        admin.services.clean_up_files.assert_has_calls([
            call('some_snap_id', 'some_group_id'),
            call(ANY, 'some_group_id')
        ])
        assert return_value == {
            'snap_ids': ['some_snap_id', ANY],
            'group_id': 'some_group_id',
            'pic_ids': [ANY, ANY],
            'scaled_pic_ids': [ANY, ANY]
        }
Пример #12
0
    def test_take_thermal_still_calls_expected_methods_with_nonzero_for_repeat(self):
        camera.services.take_thermal_still = Mock()
        analysis.services.scale_image = Mock()
        admin.services.send_mail = Mock()
        admin.services.upload_files_to_s3 = Mock()
        admin.services.clean_up_files = Mock()

        return_value = ct.take_thermal_still('some_snap_id', 'some_group_id', delay=0, repeat=1)

        camera.services.take_thermal_still.assert_has_calls([call('some_snap_id', 'some_group_id', ANY, True),
                                                             call(ANY, 'some_group_id', ANY, True)])
        analysis.services.scale_image.assert_has_calls([call(ANY, ANY, 'some_group_id', scale_image=True),
                                                        call(ANY, ANY, 'some_group_id', scale_image=True)])
        admin.services.send_mail.assert_has_calls([call('some_snap_id', 'some_group_id'),
                                                   call(ANY, 'some_group_id')])
        admin.services.upload_files_to_s3.assert_has_calls([call('some_snap_id', 'some_group_id'),
                                                            call(ANY, 'some_group_id')])
        admin.services.clean_up_files.assert_has_calls([call('some_snap_id', 'some_group_id'),
                                                        call(ANY, 'some_group_id')])
        assert return_value == {'snap_ids': ['some_snap_id', ANY],
                                'group_id': 'some_group_id',
                                'pic_ids': [ANY, ANY],
                                'scaled_pic_ids': [ANY, ANY]}
Пример #13
0
def thermal_still():
    '''
    Api endpoint for taking one or a series of Lepton stills.
    The still/stills will run asynchronously as Celery tasks, the scheduling work is delegated to the camera.tasks module
    Cleaning up files comes in via a GET parameter, note that empty string is the ONLY thing that will force it to false
    Delaying and Repeating info comes in via GET parameters, the rest comes from the current group record.
    '''
    try:
        snap_id = uuid.uuid4()
        group_id = get_settings_document()['current_group_id']
        args_dict = gather_and_enforce_request_args([{'name': 'delay', 'default': 0, 'cast_function': int},
                                                     {'name': 'repeat', 'default': 0, 'cast_function': int},
                                                     {'name': 'clean_up_files', 'default': True, 'cast_function': bool},
                                                     {'name': 'scale_image', 'default': True, 'cast_function': bool}])
        # TODO specify that is (snap_id, group_id, **args_dict soon)
        ret_dict = take_thermal_still(snap_id=snap_id,
                                      group_id=group_id,
                                      delay=args_dict['delay'],
                                      repeat=args_dict['repeat'],
                                      scale_image=args_dict['scale_image'],
                                      clean_up_files=args_dict['clean_up_files'])
        return Response(json.dumps(ret_dict), status=202, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')