Skip to content

Commit

Permalink
Merge pull request #104 from FAIRDataPipeline/update-tests
Browse files Browse the repository at this point in the history
update tests
  • Loading branch information
soniamitchell authored Jul 6, 2021
2 parents 1a7ee58 + 77fc02e commit 2e00cbc
Show file tree
Hide file tree
Showing 83 changed files with 585 additions and 463 deletions.
128 changes: 11 additions & 117 deletions .github/workflows/test-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
# Define operating systems
matrix:
config:
- {os: windows-latest, r: 'release'}
# - {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-16.04, r: '3.6.3'} # Boydorr Server
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
# - {os: ubuntu-16.04, r: '3.6.3'} # Boydorr Server
# - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

steps:
# Checkout repo
Expand Down Expand Up @@ -55,6 +55,12 @@ jobs:
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

# Install local registry
- name: Install registry
run: |
/bin/bash -c "$(curl -fsSL https://data.scrc.uk/static/localregistry.sh)"
shell: bash

# Install system_requirements requirements on macOS
- name: Install system requirements (macOS-latest)
if: runner.os == 'macOS'
Expand All @@ -64,16 +70,6 @@ jobs:
brew install gdal
shell: bash

# Install system_requirements on ubuntu 16.04 (Boydorr)
- name: Install system requirements (ubuntu-16.04)
if: matrix.config.os == 'ubuntu-16.04'
run : |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "16.04"), sep = "\n")')
shell: bash

# Install system requirements on ubuntu 20.04
- name: Install system requirements (ubuntu-20.04)
if: matrix.config.os == 'ubuntu-20.04'
Expand All @@ -91,120 +87,18 @@ jobs:
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

# Run CMD check on all but Boydorr (convert2grid test will fail on Boydorr)
# Use SCRC_API_TOKEN (PAT from Jonathan Hollocombe) to interact with the data
# registry
- name: Check (All but Boydorr)
if: matrix.config.os != 'ubuntu-16.04'
# Run CMD check
- name: Run CMD check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
SCRC_API_TOKEN: ${{ secrets.SCRC_API_TOKEN }}
R_CHECK_SYSTEM_CLOCK: 0
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

# Run CMD check on Boydorr usinging BOYDORR: "TRUE" to skip convert2grid test
# Use SCRC_API_TOKEN (PAT from Jonathan Hollocombe) to interact with the data
# registry
- name: Check (Boydorr)
if: matrix.config.os == 'ubuntu-16.04'
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
SCRC_API_TOKEN: ${{ secrets.SCRC_API_TOKEN }}
BOYDORR: "TRUE"
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

# If anything fails upload results to artifacts
- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check

# Coverage ------------------------------------------------------------------
# Located within the macOS-latest (release) job

- name: Test coverage (setup)
# Only when main is pushed
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && runner.os == 'macOS'
# Use the default GITHUB_TOKEN as an enviromental version for all steps
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
# Setup keychain needed to cache github token for upload_toml_to_github test
uses: sinoru/[email protected]

# Add github Personal Access Token to keychain:
# * Needed for upload_toml_to_github test
# * Echoes to git credential-osxkeychain
# * This emulate stdin() line by line
- name: Add credentials in keychain
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && runner.os == 'macOS'
env:
GITHUB_TOKEN: ${{ secrets.SCRC_API_PAT }}
run: |
echo "\
protocol=https
host=github.com
username=Personal Access Token
password=$GITHUB_TOKEN" | git credential-osxkeychain store
# Run code coverage with RUN_TEST to enable upload_toml_to_github test
# Use SCRC_API_TOKEN (PAT from Jonathan Hollocombe) to interact with the data
# registry
- name: Test coverage
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && runner.os == 'macOS'
env:
SCRC_API_TOKEN: ${{ secrets.SCRC_API_TOKEN }}
RUN_TEST: "TRUE"
run: |
remotes::install_cran("covr")
covr::codecov()
shell: Rscript {0}

# Build and deploy DOCS -----------------------------------------------------
# Located within the macOS-latest (release) job

- name: Build and deploy docs (setup)
# Only when main is pushed
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && runner.os == 'macOS'
# Setup pandoc needed to build docs
uses: r-lib/actions/setup-pandoc@v1

# Install Mac OS requirements
- name: Build and deploy docs (system requirements)
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && runner.os == 'macOS'
run : |
brew install harfbuzz
brew install fribidi
shell: bash

# Build documentation with pkgdown
- name: Build Docs
if: github.event_name == 'push' && github.ref == 'refs/heads/mains' && runner.os == 'macOS'
run: |
install.packages("pkgdown")
pkgdown::build_site()
shell: Rscript {0}

# Create a development branch and commit to it
- name: Commit to development branch
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && runner.os == 'macOS'
run: |
git checkout -b development
git add .
git commit -m '[skip ci]'
shell: bash

# Deploy the docs using JamesIves/github-pages-deploy-action
- name: Deploy Docs
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && runner.os == 'macOS'
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
GITHUB_TOKEN: ${{ secrets.SCRC_API_PAT }}
BASE_BRANCH: development
BRANCH: main # The branch the action should deploy to.
FOLDER: docs # The folder the action should deploy.
TARGET_FOLDER: docs
COMMIT_MESSAGE: 'build docs [skip ci]'
7 changes: 5 additions & 2 deletions R/fair_pull.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#' fair_pull
#'
#' @param path path
#' @param endpoint a \code{string} specifying the registry endpoint
#'
#' @export
#'
fair_pull <- function(path = "config.yaml") {
fair_pull <- function(path = "config.yaml",
endpoint = "http://localhost:8000/api/") {

run_server()

Expand Down Expand Up @@ -47,7 +49,8 @@ fair_pull <- function(path = "config.yaml") {
# Download raw data to data store and register in data registry
for (i in seq_along(register)) {
register_external_object(yaml = yaml,
register_this = register[[i]])
register_this = register[[i]],
endpoint = endpoint)
}
}

Expand Down
8 changes: 6 additions & 2 deletions R/fair_run.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
#'
#' @param path string
#' @param skip don't bother checking whether the repo is clean
#' @param endpoint a \code{string} specifying the registry endpoint
#'
#' @export
#'
fair_run <- function(path = "config.yaml", skip = FALSE) {
fair_run <- function(path = "config.yaml",
endpoint = "http://localhost:8000/api/",
skip = FALSE) {

run_server()

Expand Down Expand Up @@ -156,7 +159,8 @@ fair_run <- function(path = "config.yaml", skip = FALSE) {

entries <- get_entry("data_product",
list(name = write_dataproduct,
namespace = write_namespace_id))
namespace = write_namespace_id),
endpoint = endpoint)

if (is.null(entries)) {
write_version <- "0.0.1"
Expand Down
6 changes: 4 additions & 2 deletions R/get_entry.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ get_entry <- function(table, query, endpoint = "http://localhost:8000/api/") {

is_queryable(table, query)

output <- httr::GET(paste0(endpoint, table, ""),
query = query,
api_url <- paste0(endpoint, table)
api_url <- file.path(dirname(api_url), basename(api_url), "")

output <- httr::GET(api_url, query = query,
httr::add_headers(.headers = h)) %>%
httr::content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(simplifyVector = FALSE)
Expand Down
12 changes: 9 additions & 3 deletions R/get_existing.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' the results, default is \code{TRUE}
#' @param detail a \code{string} specifying what level of detail to return;
#' options are \code{"all"} for all details or \code{"id"} for just URL and IDs
#' @param endpoint a \code{string} specifying the registry endpoint
#'
#' @return Returns a \code{data.frame} of entries in table, default is limited
#' to 100 entries
Expand All @@ -24,7 +25,10 @@
#' get_existing("data_product")
#' }
#'
get_existing <- function(table, limit_results = TRUE, detail = "all") {
get_existing <- function(table,
limit_results = TRUE,
detail = "all",
endpoint = "http://localhost:8000/api/") {

if (!check_table_exists(table))
usethis::ui_stop(paste(
Expand All @@ -34,11 +38,13 @@ get_existing <- function(table, limit_results = TRUE, detail = "all") {
key <- get_token()
h <- c(Authorization = paste("token", key))

api_url <- paste0(endpoint, table)
api_url <- file.path(dirname(api_url), basename(api_url), "")

tryCatch({

# Get the 100 newest results
output <- httr::GET(paste("http://localhost:8000/api", table, "",
sep = "/"),
output <- httr::GET(api_url,
httr::add_headers(.headers = h)) %>%
httr::content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(simplifyVector = FALSE)
Expand Down
10 changes: 7 additions & 3 deletions R/get_fields.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#' Use API endpoint to produce a list of fields for a table. Requires API key.
#'
#' @param table a \code{string} specifying the name of the table
#' @param endpoint a \code{string} specifying the registry endpoint
#'
#' @return Returns a \code{data.frame} of fields and their attributes set to
#' "none"
#'
#' @export
#' @keywords internal
#'
get_fields <- function(table){
get_fields <- function(table, endpoint = "http://localhost:8000/api/"){

# Users and Groups are valid tables but cannot be posted to
if (table == "users" | table == "groups")
Expand All @@ -19,9 +21,11 @@ get_fields <- function(table){
key <- get_token()
h <- c(Authorization = paste("token", key))

api_url <- paste0(endpoint, table)
api_url <- file.path(dirname(api_url), basename(api_url), "")

# Perform an options request
out <- httr::VERB("OPTIONS", paste("http://localhost:8000/api", table, "",
sep = "/"),
out <- httr::VERB("OPTIONS", api_url,
httr::add_headers(.headers = h)) %>%
httr::content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(simplifyVector = FALSE)
Expand Down
7 changes: 4 additions & 3 deletions R/get_table_optional.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#' Get optional fields
#'
#' @param table a \code{string} specifying the name of the table
#' @param endpoint a \code{string} specifying the registry endpoint
#'
#' @return Returns a \code{data.frame} of optional fields and thier properties
#' @return Returns a \code{data.frame} of optional fields and their properties
#' @export
#' @keywords internal
#'
get_table_optional <- function(table){
get_table_optional <- function(table, endpoint){
# if(! check_table_exists(table))
# stop("Unknown Table")
optional <- get_fields(table) %>%
optional <- get_fields(table, endpoint) %>%
filter(!.data$read_only) %>%
filter(!.data$required)
}
10 changes: 7 additions & 3 deletions R/get_table_queryable.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#' Get queryable fields
#'
#' @param table a \code{string} specifying the name of the table
#' @param endpoint a \code{string} specifying the registry endpoint
#'
#' @return Returns a character vector of queryable fields
#' @export
#' @keywords internal
#'
get_table_queryable <- function(table) {
out <- httr::VERB("OPTIONS", paste("http://localhost:8000/api", table, "",
sep = "/")) %>%
get_table_queryable <- function(table, endpoint) {

api_url <- paste0(endpoint, table)
api_url <- file.path(dirname(api_url), basename(api_url), "")

out <- httr::VERB("OPTIONS", api_url) %>%
httr::content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(simplifyVector = FALSE)
as.character(out$filter_fields)
Expand Down
5 changes: 3 additions & 2 deletions R/get_table_readable.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#' Get readable fields
#'
#' @param table name of table
#' @param endpoint a \code{string} specifying the registry endpoint
#'
#' @return a dataframe of readable fields and their properties
#' @export
#' @keywords internal
#'
get_table_readable <- function(table){
get_table_readable <- function(table, endpoint){
# if(! check_table_exists(table))
# stop("Unknown Table")
readable <- get_fields(table)
readable <- get_fields(table, endpoint)
}
5 changes: 3 additions & 2 deletions R/get_table_writable.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#' Get writable fields
#'
#' @param table a \code{string} specifying the name of the table
#' @param endpoint a \code{string} specifying the registry endpoint
#'
#' @return Returns a character vector of writable fields
#' @export
#' @keywords internal
#'
get_table_writable <- function(table){
get_table_writable <- function(table, endpoint){
# if(!check_table_exists(table))
# stop("Unknown Table")

get_fields(table) %>%
get_fields(table, endpoint) %>%
filter(!.data$read_only)
}
7 changes: 4 additions & 3 deletions R/get_tables.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#' Get tables from registry
#'
#' Use api endpoint to produce a list of tables
#' @param live whether or not to get the tables directly from the API
#' @param endpoint a \code{string} specifying the registry endpoint
#'
#' @return a character vector of tables
#' @export
#' @keywords internal
#'
get_tables <- function(live = FALSE){
httr::GET(paste("http://localhost:8000/api", "", sep = "/")) %>%
get_tables <- function(endpoint = "http://localhost:8000/api/"){

httr::GET(endpoint) %>%
httr::content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(simplifyVector = FALSE) %>%
names()
Expand Down
Loading

0 comments on commit 2e00cbc

Please sign in to comment.