def test_non_strict_failure(self, system_dict): system_dict["name"] = 1234 value = SchemaParser.parse_system(system_dict, from_string=False, strict=False) assert value.get("name") is None assert value["version"] == system_dict["version"]
def test_patch_commands( self, http_client, base_url, mongo_system, system_id, bg_command, field, value, dev, succeed, ): if dev: mongo_system.version += ".dev" mongo_system.deep_save() # Make changes to the new command if field: if field == "parameters": value = [value] setattr(bg_command, field, value) # Also delete the id, otherwise mongo gets really confused delattr(bg_command, "id") body = PatchOperation( operation="replace", path="/commands", value=SchemaParser.serialize_command( [bg_command], to_string=False, many=True ), ) request = HTTPRequest( base_url + "/api/v1/systems/" + system_id, method="PATCH", headers={"content-type": "application/json"}, body=SchemaParser.serialize_patch(body), ) response = yield http_client.fetch(request, raise_error=False) if succeed: assert response.code == 200 updated = SchemaParser.parse_system( response.body.decode("utf-8"), from_string=True ) assert_command_equal(bg_command, updated.commands[0]) else: assert response.code == 400
async def get(self, system_id): """ --- summary: Retrieve a specific System parameters: - name: system_id in: path required: true description: The ID of the System type: string - name: include_commands in: query required: false description: Include the System's commands in the response type: boolean default: true responses: 200: description: System with the given ID schema: $ref: '#/definitions/System' 404: $ref: '#/definitions/404Error' 50x: $ref: '#/definitions/50xError' tags: - Systems """ response = await self.client( Operation(operation_type="SYSTEM_READ", args=[system_id]) ) # This is only here because of backwards compatibility include_commands = ( self.get_query_argument("include_commands", default="").lower() != "false" ) if not include_commands: system = SchemaParser.parse_system(response, from_string=True) system.commands = [] response = SchemaParser.serialize(system) self.set_header("Content-Type", "application/json; charset=UTF-8") self.write(response)
async def post(self): """ --- summary: Create a new System or update an existing System description: | If the System does not exist it will be created. If the System already exists it will be updated (assuming it passes validation). parameters: - name: system in: body description: The System definition to create / update schema: $ref: '#/definitions/System' responses: 200: description: An existing System has been updated schema: $ref: '#/definitions/System' 201: description: A new System has been created schema: $ref: '#/definitions/System' 400: $ref: '#/definitions/400Error' 50x: $ref: '#/definitions/50xError' tags: - Systems """ response = await self.client( Operation( operation_type="SYSTEM_CREATE", args=[ SchemaParser.parse_system( self.request.decoded_body, from_string=True ) ], ) ) self.set_status(201) self.set_header("Content-Type", "application/json; charset=UTF-8") self.write(response)
def test_error(self, data, kwargs, error): with pytest.raises(error): SchemaParser.parse_system(data, **kwargs)
def test_single_specific_from_string(self): assert_system_equal(SchemaParser.parse_system("{}", from_string=True), System())
def test_non_strict_failure(system_dict): parser = SchemaParser() system_dict['name'] = None value = parser.parse_system(system_dict, from_string=False, strict=False) assert value.get('name') is None assert value['version'] == system_dict['version']
def test_parse_error(data, kwargs, error): parser = SchemaParser() with pytest.raises(error): parser.parse_system(data, **kwargs)