Exemple #1
0
 def strip_whitespace(_json, index):
     # skips whitespace characters (<space>, <tab>, <charrage return> and <newline>)
     # as well as block comments and line comments
     while _json[index] in _whitespace:
         index += 1
     if _json[index] == "/":
         if _json[index + 1] == "/":
             index += 2
             while _json[index] != "\n":
                 index += 1
             index = strip_whitespace(_json, index)
         elif _json[index + 1] == "*":
             index += 2
             while _json[index : index + 2] != "*/":
                 index += 1
                 if index + 1 >= len(_json):
                     raise json.JSONDecodeError(
                         "expected */ but reached the end of file", _json, index
                     )
             index += 2
             index = strip_whitespace(_json, index)
         else:
             raise json.JSONDecodeError(
                 f"unexpected / at index {index}", _json, index
             )
     return index
def parse_json(str_):
    """Parse JSONC (JSON with ``//``-comments) string *str\_* into a Python object.
    Comments are discarded. Wraps standard library :py:func:`json.loads`.

    Syntax errors in the input (:py:class:`~json.JSONDecodeError`) are passed
    through from the Python standard library parser. We correct the line numbers
    mentioned in the errors to refer to the original file (i.e., with comments.)
    """
    def _pos_from_lc(lineno, colno, str_):
        # fix line number, since we stripped commented-out lines. JSONDecodeError
        # computes line/col no. in error message from character position in string.
        lines = str_.splitlines()
        return (colno - 1) + sum((len(line) + 1) for line in lines[:lineno])

    (strip_str, line_nos) = strip_comments(str_, delimiter='//')
    try:
        parsed_json = json.loads(strip_str,
                                 object_pairs_hook=collections.OrderedDict)
    except json.JSONDecodeError as exc:
        # fix reported line number, since we stripped commented-out lines.
        assert exc.lineno <= len(line_nos)
        raise json.JSONDecodeError(msg=exc.msg,
                                   doc=str_,
                                   pos=_pos_from_lc(line_nos[exc.lineno - 1],
                                                    exc.colno, str_))
    except UnicodeDecodeError as exc:
        raise json.JSONDecodeError(
            msg=f"parse_json received UnicodeDecodeError:\n{exc}",
            doc=strip_str,
            pos=0)
    return parsed_json
Exemple #3
0
def py_scanstring(s,
                  end,
                  strict=True,
                  _b=json.decoder.BACKSLASH,
                  _m=json.decoder.STRINGCHUNK.match):
    """Scan the string s for a JSON string. End is the index of the
    character in s after the quote that started the JSON string.
    Unescapes all valid JSON string escape sequences and raises ValueError
    on attempt to decode an invalid string. If strict is False then literal
    control characters are allowed in the string.
    Returns a tuple of the decoded string and the index of the character in s
    after the end quote."""
    chunks = []
    _append = chunks.append
    begin = end - 1
    while 1:
        chunk = _m(s, end)
        if chunk is None:
            raise json.JSONDecodeError("Unterminated string starting at", s,
                                       begin)
        end = chunk.end()
        content, terminator = chunk.groups()
        # Content is contains zero or more unescaped string characters
        if content:
            _append(content)
        # Terminator is the end of string, a literal control character,
        # or a backslash denoting that an escape sequence follows
        if terminator == '"':
            break
        elif terminator != '\\':
            if strict:
                msg = "Invalid control character {0!r} at".format(terminator)
                raise json.JSONDecodeError(msg, s, end)
            else:
                _append(terminator)
                continue
        try:
            esc = s[end]
        except IndexError:
            raise json.JSONDecodeError("Unterminated string starting at", s,
                                       begin)
        # If not a unicode escape sequence, must be in the lookup table
        if esc != 'u':
            try:
                char = _b[esc]
            except KeyError:
                msg = "Invalid \\escape: {0!r}".format(esc)
                raise json.JSONDecodeError(msg, s, end)
            end += 1
        else:
            st = end - 1
            end += 5
            char = s[st:end]
        _append(char)
    return ''.join(chunks), end
Exemple #4
0
def date_decoder(dic):
    """Add python types decoding. See JsonEncoder"""
    if '__date__' in dic:
        try:
            d = datetime.date(**{c: v for c, v in dic.items() if not c == "__date__"})
        except (TypeError, ValueError):
            raise json.JSONDecodeError("Corrupted date format !", str(dic), 1)
    elif '__datetime__' in dic:
        try:
            d = datetime.datetime(**{c: v for c, v in dic.items() if not c == "__datetime__"})
        except (TypeError, ValueError):
            raise json.JSONDecodeError("Corrupted datetime format !", str(dic), 1)
    else:
        return dic
    return d
Exemple #5
0
def test_mplug_init_invalid_state(mock_files):
    """Test initialisation when the state-file is corrupt."""
    mock_files.json_load.side_effect = [None, json.JSONDecodeError("", "", 0)]
    with pytest.raises(SystemExit) as pytest_wrapped_e:
        mplug.MPlug()
    assert pytest_wrapped_e.type == SystemExit
    assert pytest_wrapped_e.value.code != 0
Exemple #6
0
def get_webpack_stats():
    """Get webpack-bundle-tracker output file data.

    Returns:
        dict: The data from webpack-bundle-tracker JSON output file.

    """
    try:
        with open(WEBPACK_STATS_PATH, encoding='utf-8') as ws_file:
            webpack_stats = json.load(ws_file)
    except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
        if isinstance(e, FileNotFoundError):
            err_msg = (
                'The File "{file}" does not exist in the directory:\n'
                '"{path}"\n'
                'Possibly because you haven\'t run Webpack yet,\n'
                'or you don\'t have webpack-bundle-tracker set up in Node.'
            ).format(file=WS_FILENAME, path=WS_PATH)
            raise FileNotFoundError(2, err_msg)
        if isinstance(e, json.decoder.JSONDecodeError):
            err_msg = (
                'The file "{file}" is not a valid JSON file.\n'
                'Try checking that Webpack and webpack-bundle-tracker '
                'are set up in Node\n    and that they run without error.\n'
                '{emsg} at'
            ).format(file=WS_FILENAME, emsg=e.msg)
            raise json.JSONDecodeError(
                err_msg,
                WS_FILENAME,
                e.pos,
            )
    else:
        return webpack_stats
Exemple #7
0
    def test_clean_result_decode_error(self):
        resp_mock = mock.MagicMock()
        resp_mock.status_code = 200
        resp_mock.json.side_effect = json.JSONDecodeError("error", "\n\n", 1)

        with self.assertRaises(ResponseError):
            self.http.clean_result(resp_mock)
Exemple #8
0
def corpora_get_props_from_anndata(adata):
    """
    Get Corpora dataset properties from an AnnData
    """
    versions = corpora_get_versions_from_anndata(adata)
    if versions is None:
        return None
    [corpora_schema_version, corpora_encoding_version] = versions
    version_is_supported = corpora_is_version_supported(
        corpora_schema_version, corpora_encoding_version)
    if not version_is_supported:
        raise ValueError("Unsupported Corpora schema version")

    corpora_props = {}
    for key in CorporaConstants.REQUIRED_SIMPLE_METADATA_FIELDS:
        if key not in adata.uns:
            raise KeyError(f"missing Corpora schema field {key}")
        corpora_props[key] = adata.uns[key]

    for key in CorporaConstants.REQUIRED_JSON_ENCODED_METADATA_FIELD:
        if key not in adata.uns:
            raise KeyError(f"missing Corpora schema field {key}")
        try:
            corpora_props[key] = json.loads(adata.uns[key])
        except json.JSONDecodeError:
            raise json.JSONDecodeError(
                f"Corpora schema field {key} is expected to be a valid JSON string"
            )

    for key in CorporaConstants.OPTIONAL_SIMPLE_METADATA_FIELDS:
        if key in adata.uns:
            corpora_props[key] = adata.uns[key]

    return corpora_props
Exemple #9
0
    def post(self, request, app, model):
        model = apps.get_model(app, model)
        org = json.loads(request.body.decode('utf8'))
        try:
            d = request.data
            print("###################3 bahar", d)
            if not d:
                print("#########################3333", d)
                REQ_LOGS.error("In valid Json provided for POST")
                raise json.JSONDecodeError("InValid JSON provided",
                                           doc=request.data,
                                           pos=0)
        except json.JSONDecodeError:
            REQ_LOGS.error("In valid Json provided for POST")
            return Response("Invalid JSON for the POST")

        validators_d = {}
        # validators_d['validators'] = [CharOnly(), UpperCaseOnly()]
        serialize = getGenericSerializer(model)
        serial_data = serialize(data=d)
        if serial_data.is_valid():
            # with transaction.atomic(), reversion.create_revision():
            #     reversion.set_user(request.user)
            #     reversion.set_comment(request.method)
            #     reversion.set_date_created(date_created=datetime.datetime.now())
            serial_data.save()
            # audit_log_list(org, request, app, model)

            return Response(serial_data.data, status=status.HTTP_201_CREATED)
        return Response(serial_data.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #10
0
def read_json(path):
    """Read JSON data from file with corresponding custom exceptions.

    Parameters
    ----------
    path: str
        Path to json file.

    Returns
    -------
    json_data: dict
        Dictionary of data loaded from json file.
    """
    try:
        with open(path, "r") as json_file:
            json_data = json.loads(json_file.read())

    except json.JSONDecodeError:
        raise json.JSONDecodeError(
            f"File {os.path.basename(path)} Could Not be Loaded.")
    except FileNotFoundError:
        raise FileNotFoundError(
            f"File {os.path.basename(path)} Could Not Be Found.")
    except PermissionError:
        raise PermissionError(
            f"File {os.path.basename(path)} Could not be accessed, lack of permission."
        )

    return json_data
Exemple #11
0
    def _load_config(self, config_path: str):
        """Load config from the config path
        
        Parameters
        ----------
        config_path : str
            The given filepath to config file
        
        Returns
        -------
        dict
            Return config (as dict) if it was read successfully
        
        Raises
        ------
        FileNotFoundError
            Raised when the config file was not found in the specified directory
        json.JSONDecodeError
            Raised when the JSON decoding was not successful
        PermissionError
            Raised when there is no permission to read the config file
        """
        config = {}
        if not os.path.isfile(config_path):
            raise FileNotFoundError(
                "The config file at '{}' was not found".format(config_path))
        elif not os.access(config_path, os.R_OK):
            raise PermissionError("Permission denied to read config file")

        try:
            with open(config_path) as fp:
                config = json.loads(fp.read())
        except json.JSONDecodeError:
            raise json.JSONDecodeError("Could not read JSON from file")
        return config
async def test_stream_processor_ignore_503(run_engine, _, redis_stream,
                                           redis_cache, logger_checker):
    response = mock.Mock()
    response.text = "Server Error: Sorry, this diff is taking too long to generate."
    response.status_code = 503
    response.json.side_effect = json.JSONDecodeError("whatever", "", 0)
    response.reason_phrase = "Service Unavailable"
    response.url = "https://api.github.com/repositories/1234/pulls/5/files"

    run_engine.side_effect = lambda *_: http.raise_for_status(response)

    await worker.push(
        redis_stream,
        123,
        "owner1",
        "repo",
        123,
        "pull_request",
        {"payload": "whatever"},
    )

    await run_worker()

    # Check redis is empty
    assert 0 == (await redis_stream.zcard("streams"))
    assert 0 == len(await redis_stream.keys("stream~*"))
    assert 0 == len(await redis_stream.hgetall("attempts"))
    def test_json_error(self, mocker):
        mock_reply = mocker.MagicMock()
        mock_reply.json.side_effect = json.JSONDecodeError('test', 'test', 42)
        mocker.patch('requests.Session.get', return_value=mock_reply)

        with pytest.raises(TemporaryCheckError):
            Kodi('foo', url='url', timeout=10).check()
def merge_config(config_file_path, result_config):
    """
    A func merges default configuration and config from
    the specified file(by the --config option in the CLI).
    The config in specified file should be in JSON format.
    :return result config
    """
    config_params = ["LOG_DIR", "LOG_FILE", "REPORTS_SIZE", "REPORT_DIR"]

    if os.path.isfile(config_file_path):
        try:
            # SUB-SECTION 1: decode/read configuration file.
            with open(config_file_path, "r") as con_file:
                file_config = json.loads(con_file.read())

            # SUB-SECTION 2: merge configurations.
            if isinstance(file_config, dict):
                for config_param in file_config:
                    config_param_type = config_params[config_param]
                    print(config_param_type)
                    if config_param in config_params:
                        result_config[config_param] = file_config[config_param]
                return result_config
            raise TypeError(f"{merge_config.__name__}: the config file contains "
                            f"data with an invalid data type.")

        except json.JSONDecodeError:
            raise json.JSONDecodeError(
                msg=f"{merge_config.__name__}: the config file -"
                    f" {config_file_path} could not decoded.",
                doc="",
                pos=0)
    else:
        raise FileExistsError(f"{merge_config.__name__}: the config file -"
                              f" {config_file_path} is not exist.")
    def test_json_error(self, mocker) -> None:
        mock_reply = mocker.MagicMock()
        mock_reply.json.side_effect = json.JSONDecodeError("test", "test", 42)
        mocker.patch("requests.Session.get", return_value=mock_reply)

        with pytest.raises(TemporaryCheckError):
            Kodi("foo", url="url", timeout=10).check()
Exemple #16
0
def validate_raw_manifest_format(raw_manifest: str) -> None:
    """
    Raise a EthPMValidationError if a manifest ...
    - is not tightly packed (i.e. no linebreaks or extra whitespace)
    - does not have alphabetically sorted keys
    - has duplicate keys
    - is not UTF-8 encoded
    - has a trailing newline
    """
    try:
        manifest_dict = json.loads(raw_manifest, encoding="UTF-8")
    except json.JSONDecodeError as err:
        raise json.JSONDecodeError(
            "Failed to load package data. File is not a valid JSON document.",
            err.doc,
            err.pos,
        )
    compact_manifest = json.dumps(manifest_dict,
                                  sort_keys=True,
                                  separators=(",", ":"))
    if raw_manifest != compact_manifest:
        raise EthPMValidationError(
            "The manifest appears to be malformed. Please ensure that it conforms to the "
            "EthPM-Spec for document format. "
            "http://ethpm.github.io/ethpm-spec/package-spec.html#document-format "
        )
Exemple #17
0
def upload_report(result_path, entry, args, \
	git_user, git_repo, git_commit, \
	cotk_record_information):
	'''Upload report to dashboard. Return id of the new record.'''
	# check result file existence
	# get git link
	if not os.path.isfile(result_path):
		raise ValueError("Result file ({}) is not found.".format(result_path))
	try:
		result = json.load(open(result_path, "r"))
	except json.JSONDecodeError as err:
		raise json.JSONDecodeError("{} is not a valid json. {}".format(result_path, err.msg),\
				err.doc, err.pos)

	working_dir = get_repo_workingdir()

	upload_information = { \
		"entry": entry, \
		"args": args, \
		"working_dir": working_dir, \
		"git_user": git_user, \
		"git_repo": git_repo, \
		"git_commit": git_commit, \
		"record_information": cotk_record_information, \
		"result": json.dumps(result) \
	}
	LOGGER.info("Save your report locally at .cotk_upload_backup")
	json.dump(upload_information, open(".cotk_upload_backup", 'w'))
	LOGGER.info("Uploading your report...")
	res = requests.post(REPORT_URL, upload_information)
	res = json.loads(res.text)
	if res['code'] != "ok":
		raise RuntimeError("upload error. %s" % json.loads(res['err']))
	return res['id']
def create_dynamic_link(deep_link):
    """Create a Firebase dynamic link for the passed deep link"""
    logger.info("Creating dynamic link via Firebase...")
    logger.debug("Deep Link: %s", deep_link)

    payload = {
        "dynamicLinkInfo": {
            "domainUriPrefix": os.environ['FRIDGIFY_DL_URL'],
            "link": deep_link,
            "androidInfo": {
                "androidPackageName": os.environ['ANDROID_PN']
            },
            "iosInfo": {
                "iosBundleId": os.environ['IOS_BID']
            }
        }
    }
    logger.debug("Payload: %s", repr(payload))

    req_url = f"{os.environ['FB_DL_URL']}/shortLinks?key={os.environ['FB_API_KEY']}"
    response = requests.post(req_url, data=json.dumps(payload))
    logger.debug("Firebase Response: %s", response.content)
    if response.status_code != 200:
        raise json.JSONDecodeError(msg="Invalid Payload", doc="", pos=0)
    content = json.loads(response.content)
    return content["shortLink"]
Exemple #19
0
def check_molecule_data_structure(fname, verbose=True):
    ''' Check that ``fname`` has a valid JSON structure for molecular data
    
    Parameters
    ----------
    
    fname: str
        molecular data JSON file 
        
        
    Notes
    -----
    
    Order in the json doesnt matter, however, the order of the 
    electronic_level_names matters: the index of all levels should
    match the `index` key of these states. 
    
    '''

    with open(fname) as f:
        try:
            db = json.load(f)  #, object_pairs_hook=OrderedDict)
        except json.JSONDecodeError as err:
            raise json.JSONDecodeError(
                "Error reading '{0}' (line {2} col {3}): \n{1}".format(
                    fname, err.msg, err.lineno, err.colno), err.doc,
                err.pos) from err

    for molecule, db_molec in db.items():
        # ... Check number of isotopes is correct
        isotope_names = db_molec['isotopes_names']
        isotopes = db_molec['isotopes']
        if len(isotopes) != len(isotope_names):
            raise ValueError(
                    'In molecule {0}: isotope names '.format(molecule)+\
                    '({0}) dont match the number of isotopes ({1})'.format(
                    isotope_names, list(isotopes.keys())))

        # ... Check number of electronic states is correct
        for isotope, db_iso in db_molec['isotopes'].items():
            elec_states_names = db_iso['electronic_levels_names']
            elec_states = db_iso['electronic_level']
            if len(elec_states_names) != len(elec_states):
                raise ValueError(
                    'In molecule {0}, isotope {1}: electronic '.format(molecule, isotope)+\
                    'levels names ({0}) dont match the number of levels ({1})'.format(
                    elec_states_names, list(elec_states.keys())))

        # ... Check they are properly ordered
            for state, db_state in elec_states.items():
                if elec_states_names.index(
                        db_state['name']) + 1 != db_state['index']:
                    # ... + 1 because Python index start at 0 and FORTRAN at 1 unless allocated with 0:N
                    raise ValueError(
                        'In molecule {0}, isotope {1}: index of electronic '.format(
                                molecule, isotope, db_state['index'])+\
                        'state {0} ({1}): {2} does not match the list of states: {3}. '.format(
                        state, db_state['name'], db_state['index'], elec_states_names))

    if verbose: print('Structure of {0} looks correct'.format(fname))
Exemple #20
0
def input_to_grid(in_str):

    output = []

    if '[' in in_str and '{' in in_str:
        # assume input is a list of neighborhoods
        neighborhoods = json.loads(in_str)
        if type(neighborhoods) != list:
            raise json.JSONDecodeError("expected a list of neighborhoods",
                                       in_str, 0)

        # for each unique y value
        for y in sorted(set([n['y'] for n in neighborhoods])):

            # sort cells by x value
            row = sorted(filter(lambda n: n['y'] == y, neighborhoods),
                         key=lambda n: n['x'])

            # add row to list as single string
            output.append(''.join([str(int(n['alive'])) for n in row]))

    else:
        # assume input is a string, filter anything but 0, or 1
        cells = list(filter(lambda c: c in ['0', '1'], in_str))

        # make a grid out of it
        sidelen = int(math.sqrt(len(cells)))
        for row_idx in range(0, len(cells), sidelen):
            output.append(''.join(cells[row_idx:row_idx + sidelen]))

    return output
Exemple #21
0
async def getcords(address, key):
    try:
        r = await http.get(
            f"https://maps.googleapis.com/maps/api/geocode/json?address={urllib.parse.quote(address)}&key={key}",
            res_method="json"
        )
    except json.JSONDecodeError:
        raise json.JSONDecodeError("The API didn't give any response")

    results = r["results"][0]

    geometry = results["geometry"]["viewport"]["northeast"]
    address = results["formatted_address"]

    # Just TRY till you get it
    shortfind = results["address_components"]
    for g in shortfind:
        if len(g["short_name"]) == 2:
            country_code = g["short_name"]

    return dict.JsonDict({
        "country_code": country_code,
        "address": address,
        "geometry": geometry,
        "latitude": geometry["lat"],
        "longitude": geometry["lng"]
    })
Exemple #22
0
 def decode(self, s, mClass):
     try:
         data = json.loads(s, object_hook=self.object_hook, parse_float=self.parse_float,
         parse_int=self.parse_int, parse_constant=self.parse_constant, strict=self.strict,
         object_pairs_hook=self.object_pairs_hook)
     except Exception as err:
         raise json.JSONDecodeError("Json Loads Error", s, err.__str__())
     return self.__transform__(data, mClass)
def _read_json_file(json_file):
    with open(json_file, 'r') as f:
        try:
            content = json.load(f)
        except json.JSONDecodeError as e:
            raise json.JSONDecodeError('ERROR: Could not decode JSON struct '
                                       'in {}: {}'.format(json_file, e))
    return content
 def safe_load_log(self):
         try:
             #object_hook=integer_keys insures integer keys are converted into python ints
             master_log = load_json(path=self.logfile, object_hook=integer_keys) 
         except json.JSONDecodeError as e:
             msg = 'JSON file misformatted, failed to read.'
             raise json.JSONDecodeError(msg, e.doc, e.pos)
         return master_log
Exemple #25
0
def loads(obj, **kw):
    try:
        output = mainjson.loads(obj)
    except ValueError as e:
        raise stblib_json.JSONDecodeError(str(e), "", 0)
    if json_module == "orjson" and hasattr(output, "decode"):
        output = output.decode("utf-8")
    return output
Exemple #26
0
 def _parse_json_line(line: str, default_value=None):
     try:
         return json.loads(line)
     except json.JSONDecodeError as err:
         if default_value is not None:
             return default_value
         else:
             raise json.JSONDecodeError(err.msg, err.doc, err.pos)
Exemple #27
0
 def func(line: str):
     try:
         return json.loads(line)
     except json.JSONDecodeError as err:
         if default is not None:
             return default
         elif not skip_errors:
             raise json.JSONDecodeError(err.msg, err.doc, err.pos)
Exemple #28
0
    def do_POST(self):
        if self.path == "/api":
            content_length = int(
                self.headers['Content-Length'])  # <--- Gets the size of data
            post_data = self.rfile.read(
                content_length)  # <--- Gets the data itself
            post_data = post_data.decode('utf-8')

            try:
                post_data = json.loads(post_data)
            except json.JSONDecodeError(msg, doc, pos):
                print('Error decodificando JSON: ' + post_data)
                return

            self.send_response(200)

            metodo = post_data['metodo']

            if metodo == 'AvanzaPapel':
                lineas = post_data['parametros']['lineas']
                avanzar_papel(lineas)
            elif metodo == 'CortaPapel':
                cortar_papel()
            elif metodo == 'CierreCajero':
                cierre_cajero(1)
            elif metodo == 'CierreZ':
                cierre_z(1)
            elif metodo == 'InformacionFiscalCurso':
                rtn = informacion_fiscal_curso()
                rtn = json.dumps(rtn)
                self.wfile.write(rtn.encode())
            elif metodo == 'HeaderSet':
                linea = post_data['parametros']['linea']
                texto = post_data['parametros']['texto']
                header_set(linea, texto)
            elif metodo == 'FooterSet':
                linea = post_data['parametros']['linea']
                texto = post_data['parametros']['texto']
                header_set(linea, texto)
            elif metodo == 'BoletaAbrir':
                boleta_abrir()
            elif metodo == 'BoletaItem':
                descripcion = post_data['parametros']['descripcion']
                cantidad = post_data['parametros']['cantidad']
                precio = post_data['parametros']['precio']
                impuesto = post_data['parametros']['impuesto']
                calificador = post_data['parametros']['calificador']
                excentoiva = post_data['parametros']['excentoiva']
                boleta_item(descripcion, cantidad, precio, impuesto,
                            calificador, excentoiva)
            elif metodo == 'BoletaSubtotal':
                boleta_subtotal(False)
            elif metodo == 'BoletaPago':
                tipopago = post_data['parametros']['tipopago']
                cantidad = post_data['parametros']['cantidad']
                boleta_pago(tipopago, cantidad)
            elif metodo == 'BoletaCerrar':
                boleta_cerrar()
Exemple #29
0
def test_load_repo_descriptor_unparseable(mocker):
    mocker.patch(
        'connect.cli.plugins.report.helpers.json.load',
        side_effect=json.JSONDecodeError('test', 'json_doc', 1),
    )
    with pytest.raises(ClickException) as cv:
        load_repo('./tests/fixtures/reports/basic_report')

    assert str(cv.value) == 'The reports project descriptor `reports.json` is not a valid json file.'
Exemple #30
0
def test_parse_category_tree_request_body_raise_exc_when_unable_to_parse_body(
        mocker):
    json_loads_mock = mocker.patch(
        'tree.categories.utils.json.loads',  # noqa
        side_effect=json.JSONDecodeError('msg', 'doc', 1))
    body = {}

    with pytest.raises(InvalidBodyException):
        parse_category_tree_request_body(body)