Esempio n. 1
0
    def get(self, uid=None):
        if not uid:
            paging, success = get_paging(request.args)
            if not success:
                return error_message(paging, self.URL, request_data=request.args)
            offset, limit = paging

            try:
                recursive = get_recursive(request.args)
                query = get_query(request.args)
            except ValueError as value_error:
                return error_message(str(value_error), self.URL, request_data=dict(query=request.args.get('query'), recursive=request.args.get('recursive')))
            if recursive and not query:
                return error_message('recursive search is only permissible with non-empty query', self.URL, request_data=dict(query=request.args.get('query'), recursive=request.args.get('recursive')))

            try:
                with ConnectTo(FrontEndDbInterface, self.config) as connection:
                    uids = connection.rest_get_firmware_uids(offset=offset, limit=limit, query=query, recursive=recursive)

                return success_message(dict(uids=uids), self.URL, dict(offset=offset, limit=limit, query=query, recursive=recursive))
            except Exception:
                return error_message('Unknown exception on request', self.URL, dict(offset=offset, limit=limit, query=query, recursive=recursive))
        else:
            summary = get_summary_flag(request.args)
            if summary:
                with ConnectTo(FrontEndDbInterface, self.config) as connection:
                    firmware = connection.get_complete_object_including_all_summaries(uid)
            else:
                with ConnectTo(FrontEndDbInterface, self.config) as connection:
                    firmware = connection.get_firmware(uid)
            if not firmware or not isinstance(firmware, Firmware):
                return error_message('No firmware with UID {} found'.format(uid), self.URL, dict(uid=uid))

            fitted_firmware = self._fit_firmware(firmware)
            return success_message(dict(firmware=fitted_firmware), self.URL, request_data=dict(uid=uid))
Esempio n. 2
0
def test_get_recursive():
    assert not get_recursive(None)

    with pytest.raises(ValueError):
        get_recursive(dict(recursive='bad_string'))

    with pytest.raises(ValueError):
        get_recursive(dict(recursive='2'))

    no_flag = get_recursive(dict())
    assert not no_flag

    false_result = get_recursive(dict(recursive='false'))
    assert not false_result

    good_result = get_recursive(dict(recursive='true'))
    assert good_result
Esempio n. 3
0
    def _get_without_uid(self):
        paging, success = get_paging(request.args)
        if not success:
            return error_message(paging, self.URL, request_data=request.args)
        offset, limit = paging

        try:
            recursive = get_recursive(request.args)
            query = get_query(request.args)
        except ValueError as value_error:
            return error_message(str(value_error),
                                 self.URL,
                                 request_data=dict(
                                     query=request.args.get('query'),
                                     recursive=request.args.get('recursive')))
        if recursive and not query:
            return error_message(
                'recursive search is only permissible with non-empty query',
                self.URL,
                request_data=dict(query=request.args.get('query'),
                                  recursive=request.args.get('recursive')))

        try:
            with ConnectTo(FrontEndDbInterface, self.config) as connection:
                uids = connection.rest_get_firmware_uids(offset=offset,
                                                         limit=limit,
                                                         query=query,
                                                         recursive=recursive)

            return success_message(
                dict(uids=uids), self.URL,
                dict(offset=offset,
                     limit=limit,
                     query=query,
                     recursive=recursive))
        except Exception:
            return error_message(
                'Unknown exception on request', self.URL,
                dict(offset=offset,
                     limit=limit,
                     query=query,
                     recursive=recursive))