tests/testthat/test-run_look.R

context("run_look")

test_that("run_look can get a look", {
  with_mock(
    `looker3:::setup_using_env_vars` = function() {
      list(LOOKER_URL = "https://fake.looker.com:111/api/3.0/",
           LOOKER_ID = "whatever",
           LOOKER_SECRET = "shhhhh")
    },
    `looker3:::login_api_call` = function(...) NULL,
    `looker3:::logout_api_call` = function(...) NULL,
    `looker3:::cached_token_is_invalid` = function(...) FALSE,
    `looker3:::pull_look_api_call` = function(...) NULL,
    `httr::content` = function(...) iris, {
      expect_identical(run_look(1), iris)
    })
  })

test_that("run_look can trigger a re-login if the cache is invalid", {
  with_mock(
    `looker3:::setup_using_env_vars` = function() {
      list(LOOKER_URL = "https://fake.looker.com:111/api/3.0/",
           LOOKER_ID = "whatever",
           LOOKER_SECRET = "shhhhh")
    },
    `looker3:::login_api_call` = function(...) NULL,
    `looker3:::logout_api_call` = function(...) NULL,
    `looker3:::validate_response` = function(...) NULL,
    `looker3:::cached_token_is_invalid` = function(...) TRUE,
    `looker3:::pull_look_api_call` = function(...) NULL,
    `httr::content` = function(...) list(access_token = "TOKENYO", expires_in = 0), {
      token_cache$set("token", list(token = "FAKE_TOKEN"))
      expect_equal(token_cache$get("token")$token, "FAKE_TOKEN")
      run_look(1)
      expect_equal(token_cache$get("token")$token, "TOKENYO")
      token_cache$set("token", list(token = "FAKE_TOKEN"))
      expect_equal(token_cache$get("token")$token, "FAKE_TOKEN")
    })
  })
avantcredit/looker3 documentation built on May 11, 2019, 4:06 p.m.