tests/testthat/test-validate_plain_api.R

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

context("Test ValidatePlainApi")

api.instance <- ValidatePlainApi$new()

test_that("validation from mzTab TAB 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)
  tmpFile <- tempfile(fileext = "mztab")
  writeMzTab(mzTabObject, tmpFile)
  mzTabString <- readChar(tmpFile, file.info(tmpFile)$size)
  #set a custom api client to use a different URL
  apiClient <- ApiClient$new(basePath = "https://apps.lifs-tools.org/mztabvalidator/rest/v2")
  validateApi <- ValidatePlainApi$new(apiClient = apiClient)
  response <- validateApi$ValidatePlainMzTabFile(mzTabString, 'info', 50, FALSE)
  
  # HTTP Code 200 means request was successfully validated with no messages.
  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)
})

test_that("validation via REST API of mztab TSV works", {
  skip_if_not(apps_lifstools_statusOK, "apps.lifs-tools.org not reachable")
  
  testfile <- system.file("testdata", c("lipidomics-example.mzTab"),package="rmzTabM")
  mzTabString <- readChar(testfile, file.info(testfile)$size)
  
  #set a custom api client to use a different URL
  apiClient <- ApiClient$new(basePath = "https://apps.lifs-tools.org/mztabvalidator/rest/v2")
  validateApi <- ValidatePlainApi$new(apiClient = apiClient)
  response <- validateApi$ValidatePlainMzTabFile(mzTabString, 'info', 50, FALSE)
  
  # HTTP Code 200 means request was successfully validated with no messages.
  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)
})

test_that("validation via REST API of mzTab TSV with an error works", {
  skip_if_not(apps_lifstools_statusOK, "apps.lifs-tools.org not reachable")

  testfile <- system.file("testdata", c("lipidomics-example-broken.mzTab"),package="rmzTabM")
  mzTabString <- readChar(testfile, file.info(testfile)$size)
  
  #set a custom api client to use a different URL
  apiClient <- ApiClient$new(basePath = "https://apps.lifs-tools.org/mztabvalidator/rest/v2")
  validateApi <- ValidatePlainApi$new(apiClient = apiClient)
  response <- validateApi$ValidatePlainMzTabFile(mzTabString, 'info', 50, FALSE)
  
  # HTTP Code 422 is invalid input
  expect_equal(response$response$status_code, 422)
  expect_equal(response$content, "API client error")
  
  # retrieve the validation messages
  validationMessages <- apiClient$deserialize(resp = response$response, returnType = "array[ValidationMessage]", loadNamespace("rmzTabM"))
  expect_equal(length(validationMessages), 1)
  expect_equal(validationMessages[[1]]$category, "logical")
  expect_equal(validationMessages[[1]]$message_type, "error")
  expect_equal(validationMessages[[1]]$line_number, 84)
})
lifs-tools/rmzTab-m documentation built on Jan. 26, 2023, 4:45 p.m.