tests/testthat/test-validate_api.R

# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate

context("Test ValidateApi")

test_that("validation via REST API of mztab json works", {
  skip_if_not(apps_lifstools_statusOK, "apps.lifs-tools.org not reachable")
  
  testfile <- system.file("testdata", c("lipidomics-example.mzTab.json"),package="rmzTabM")
  mzTabObject <- MzTab$new()
  mzTabObject$fromJSON(testfile)
  metadataJsonObject <- mzTabObject$`metadata`$toJSON()
  
  # perform some sanity checks, reading and writing are tested in test_read_mztab.R and test_write_mztab.R
  expect_false(is.null(metadataJsonObject))
  expect_false(is.null(metadataJsonObject$`mzTab-version`))
  expect_equal(as.character(metadataJsonObject$`mzTab-version`), "2.0.0-M")
  expect_false(is.null(metadataJsonObject$`mzTab-ID`))
  expect_equal(as.character(metadataJsonObject$`mzTab-ID`), "ISAS-2018-1234")
  expect_false(is.null(metadataJsonObject$`description`))
  expect_true(is.null(metadataJsonObject$`title`))
  expect_true(0 == length(metadataJsonObject$`title`))
  
  # set a custom api client to use a different URL
  apiClient <- ApiClient$new(basePath = "https://apps.lifs-tools.org/mztabvalidator/rest/v2")
  validateApi <- ValidateApi$new(apiClient = apiClient)
  
  response <- validateApi$ValidateMzTabFile(mzTabObject, 'info', 50, FALSE)
  
  # HTTP code means, that the file is valid at the current validation level 'info'.
  expect_equal(response$response$status_code, 200)
  if (!is.null(response$content)) {
    print(response$content)
  }
  expect_null(response$content)
  
  # retrieve the validation messages
  validationMessages <- apiClient$deserialize(resp = response$response, returnType = "array[ValidationMessage]", loadNamespace("rmzTabM"))
  expect_equal(length(validationMessages), 0)
})
lifs-tools/rmzTab-m documentation built on Jan. 26, 2023, 4:45 p.m.