Skip to content

check_rt_login function #22

Open
Open

Description

@dmullen17

I'm using a simple helper to check if i'm logged in to RT or not for unit testing in https://github.com/NCEAS/awards-bot. It's useful for skipping unit tests when not logged in to RT.

It might make more sense for it (or a more elegant version) to live here. Thoughts?

check_rt_login <- function(rt_base) {
  base_api <- paste(stringr::str_replace(rt_base, "\\/$", ""),
                    "REST", "1.0", sep = "/")
  content <- httr::GET(base_api) %>%
    httr::content()
  
  if (stringr::str_detect(content, "Credentials required")) {
    return(FALSE)
  } else {
    return(TRUE)
  }
}

Activity

  1. isteves commented on Aug 9, 2018

    @isteves
    Contributor

    @dmullen17 sorry, just getting back into RT a bit now. @amoeba and I are currently planning to do some package restructuring to get it CRAN-ready. We're trying to maintain matches to the RT API as much as possible, but I see this as a possible way to modularize the connection-checking part of rt_login. Don't have the bandwidth to fully look into this now, but will try to come back to this eventually!

  2. amoeba commented on Aug 9, 2018

    @amoeba
    Contributor

    We could certainly include something like this. Can you imagine someone using it in an interactive session though or just in a using-rt-in-another-package scenario like yours? If we think enough users might use it, it might be worth considering.

    If most of the utility here can capture the behavior that rt_login's return value could accomplish, I'd probably just stick with rt_login.

    For your unit tests, could you just see if the RT_BASE_URL env var is set to detect whether you should try to run the tests?

  3. added this to the v1.0 milestone on Feb 26, 2020
  4. self-assigned this
    on Feb 26, 2020
  5. amoeba commented on Mar 3, 2020

    @amoeba
    Contributor

    I think having something like this is probably useful but I didn't like the idea of having to make an HTTP call just to find out whether we're logged in. I'm going to move this off of the 1.0 release as it's not a critical.

    If we revisit this in the future, it might be possible to figure out whether we're logged in without making an HTTP call. For example, we could capture the cookies on the rt_login call, store them in the package's state, and query that.

  6. modified the milestones: v1.0, Next release on Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions