Skip to content

Commit

Permalink
Added in API key call.
Browse files Browse the repository at this point in the history
  • Loading branch information
rachmaninoffpk committed Nov 8, 2024
1 parent 9abacda commit b83545e
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions tests/testthat/test-chemical-APIs-batch.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ test_that('Rate limit warnings', {
expect_warning(chemical_equal_batch(word_list = c('gvfdsr7'), API_key = ctx_key(), rate_limit = -1), 'Setting rate limit to 0 seconds between requests!')
expect_warning(chemical_contains_batch(word_list = c('gvfdsr7'), API_key = ctx_key(), rate_limit = '0'), 'Setting rate limit to 0 seconds between requests!')
expect_warning(chemical_contains_batch(word_list = c('gvfdsr7'), API_key = ctx_key(), rate_limit = -1), 'Setting rate limit to 0 seconds between requests!')
expect_warning(get_msready_by_mass_with_error_batch(mass = 226, error = 1, rate_limit = '0'), 'Setting rate limit to 0 seconds between requests!')
expect_warning(get_msready_by_mass_with_error_batch(mass = 226, error = 1, rate_limit = -1), 'Setting rate limit to 0 seconds between requests!')
expect_warning(get_msready_by_mass_with_error_batch(mass = 226, error = 1, rate_limit = '0', API_key = ctx_key()), 'Setting rate limit to 0 seconds between requests!')
expect_warning(get_msready_by_mass_with_error_batch(mass = 226, error = 1, rate_limit = -1, API_key = ctx_key()), 'Setting rate limit to 0 seconds between requests!')
expect_warning(get_msready_by_mass_batch(start_list = c(1), end_list = c(1), API_key = ctx_key(), rate_limit = '0'), 'Setting rate limit to 0 seconds between requests!')
expect_warning(get_msready_by_mass_batch(start_list = c(1), end_list = c(1), API_key = ctx_key(), rate_limit = -1), 'Setting rate limit to 0 seconds between requests!')
expect_warning(get_msready_by_formula_batch(formula_list = c('CH4'), API_key = ctx_key(), rate_limit = '0'), 'Setting rate limit to 0 seconds between requests!')
Expand Down Expand Up @@ -140,60 +140,60 @@ test_that('Rate limit warnings', {
Sys.sleep(5)

test_that('Numeric range input errors and warnings', {
expect_error(get_chemical_by_property_range_batch(API_key = ''), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), API_key = ''), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_chemical_by_property_range_batch(end_list = c(1), API_key = ''), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c(2, 3), API_key = ''), 'Mismatch in length of `start_list` and `end_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c('2'), API_key = ''), 'Only numeric values allowed in each list!')
expect_error(get_chemical_by_property_range_batch(API_key = ctx_key()), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), API_key = ctx_key()), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_chemical_by_property_range_batch(end_list = c(1), API_key = ctx_key()), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c(2, 3), API_key = ctx_key()), 'Mismatch in length of `start_list` and `end_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c('2'), API_key = ctx_key()), 'Only numeric values allowed in each list!')
#expect_error(get_chemical_by_property_range_batch(start_list = c(1, 2), end_list = c(2, 3), property_list = c('a'), API_key = ''), 'Setting `property_list` to repeat to match length of `start_list/end_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c(2), property_list = c('1', '2'), API_key = ''), 'Mismatch in length of `property_list` and `start_list/end_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c(2), property_list = c('1', '2'), API_key = ctx_key()), 'Mismatch in length of `property_list` and `start_list/end_list`!')

expect_error(get_msready_by_mass_with_error_batch(), 'Please input a list of masses and an error value!')
expect_error(get_msready_by_mass_with_error_batch(masses = c(1)), 'Please input a list of masses and an error value!')
expect_error(get_msready_by_mass_with_error_batch(error = 1), 'Please input a list of masses and an error value!')
expect_error(get_msready_by_mass_with_error_batch(masses = -1, error = 1), 'Please input only positive values for masses!')
expect_warning(get_msready_by_mass_with_error_batch(masses = 1, error = c(1, 2)), 'Using the first positive value contained in error!')
expect_error(get_msready_by_mass_with_error_batch(API_key = ctx_key()), 'Please input a list of masses and an error value!')
expect_error(get_msready_by_mass_with_error_batch(masses = c(1), API_key = ctx_key()), 'Please input a list of masses and an error value!')
expect_error(get_msready_by_mass_with_error_batch(error = 1, API_key = ctx_key()), 'Please input a list of masses and an error value!')
expect_error(get_msready_by_mass_with_error_batch(masses = -1, error = 1, API_key = ctx_key()), 'Please input only positive values for masses!')
expect_warning(get_msready_by_mass_with_error_batch(masses = 1, error = c(1, 2), API_key = ctx_key()), 'Using the first positive value contained in error!')


expect_error(get_msready_by_mass_batch(API_key = ''), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(start_list = c(1), API_key = ''), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(end_list = c(1), API_key = ''), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(start_list = c(1), end_list = c(2,3), API_key = ''), 'Mismatch in length of `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(start_list = c(4), end_list = c('k'), API_key = ''), 'Only numeric values allowed in `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(start = c('TRUE'), end = c(4), API_key = ''), 'Only numeric values allowed in `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(API_key = ctx_key()), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(start_list = c(1), API_key = ctx_key()), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(end_list = c(1), API_key = ctx_key()), 'Please input a list for both `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(start_list = c(1), end_list = c(2,3), API_key = ctx_key()), 'Mismatch in length of `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(start_list = c(4), end_list = c('k'), API_key = ctx_key()), 'Only numeric values allowed in `start_list` and `end_list`!')
expect_error(get_msready_by_mass_batch(start = c('TRUE'), end = c(4), API_key = ctx_key()), 'Only numeric values allowed in `start_list` and `end_list`!')
})

# Pause requests for 5 seconds
Sys.sleep(5)

test_that('Word search errors', {
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c(2), API_key = ''), 'Please input a list for `property_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c(2), property_list = c(1), API_key = ''), 'Please input a character list for `property_list`!')
expect_error(chemical_starts_with_batch(API_key = ''), 'Please input a list of chemical names!')
expect_error(chemical_starts_with_batch(word_list = c(1), API_key = ''), 'Please input a character list for word_list!')
expect_error(chemical_equal_batch(API_key = ''), 'Please input a list of chemical names!')
expect_error(chemical_equal_batch(word_list = c(1), API_key = ''), 'Please input a character list for word_list!')
expect_error(chemical_contains_batch(API_key = ''), 'Please input a list of chemical names!')
expect_error(chemical_contains_batch(word_list = 1, API_key = ''), 'Please input a character list for word_list!')
expect_error(get_msready_by_formula_batch(API_key = ''), 'Please input a list of chemical formulas!')
expect_error(get_msready_by_formula_batch(formula_list = c(1), API_key = ''), 'Please input a character list for formula_list!')
expect_error(get_chemical_lists_by_type_batch(API_key = ''), 'Please input a list of list types!')
expect_error(get_chemical_lists_by_type_batch(type_list = c(1), API_key = ''), 'Please input a character list for type_list!')
expect_error(get_public_chemical_list_by_name_batch(API_key = ''), 'Please input a list of list names!')
expect_error(get_public_chemical_list_by_name_batch(name_list = c(1), API_key = ''), 'Please input a character list for name_list!')
expect_error(get_lists_containing_chemical_batch(API_key = ''), 'Please input a list of DTXSIDs!')
expect_error(get_lists_containing_chemical_batch(chemical_list = c(1), API_key = ''), 'Please input a character list for chemical_list!')
expect_error(get_chemicals_in_list_start_batch(API_key = ''), 'Please input a list for both `list_names` and `words`!')
expect_error(get_chemicals_in_list_start_batch(list_names = c('Biosolids2021'), words = c(1, 2), API_key = ''), 'Mismatch in length of `list_names` and `words`!')
expect_error(get_chemicals_in_list_start_batch(list_names = c(2021), words = c(1)), 'Only character values allowed in `list_names` and `words`!')
expect_error(get_chemicals_in_list_exact_batch(API_key = ''), 'Please input a list for both `list_names` and `words`!')
expect_error(get_chemicals_in_list_exact_batch(list_names = c('Biosolids2021'), words = c('T', 'F'), API_key = ''), 'Mismatch in length of `list_names` and `words`!')
expect_error(get_chemicals_in_list_exact_batch(list_names = c(2021), words = c(1), API_key = ''), 'Only character values allowed in `list_names` and `words`!')
expect_error(get_chemicals_in_list_contain_batch(API_key = ''), 'Please input a list for both `list_names` and `words`!')
expect_error(get_chemicals_in_list_contain_batch(list_names = c('Biosolids2021'), c(1, 2), API_key = ''), 'Mismatch in length of `list_names` and `words`!')
expect_error(get_chemicals_in_list_contain_batch(list_names = c(2021), words = c(1), API_key = ''), 'Only character values allowed in `list_names` and `words`!')
expect_error(get_chemicals_in_list_batch(API_key = ''), 'Please input a list of names of chemical lists!')
expect_error(get_chemicals_in_list_batch(list_name = c(1), API_key = ''), 'Please input a character list for list_names!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c(2), API_key = ctx_key()), 'Please input a list for `property_list`!')
expect_error(get_chemical_by_property_range_batch(start_list = c(1), end_list = c(2), property_list = c(1), API_key = ctx_key()), 'Please input a character list for `property_list`!')
expect_error(chemical_starts_with_batch(API_key = ctx_key()), 'Please input a list of chemical names!')
expect_error(chemical_starts_with_batch(word_list = c(1), API_key = ctx_key()), 'Please input a character list for word_list!')
expect_error(chemical_equal_batch(API_key = ctx_key()), 'Please input a list of chemical names!')
expect_error(chemical_equal_batch(word_list = c(1), API_key = ctx_key()), 'Please input a character list for word_list!')
expect_error(chemical_contains_batch(API_key = ctx_key()), 'Please input a list of chemical names!')
expect_error(chemical_contains_batch(word_list = 1, API_key = ctx_key()), 'Please input a character list for word_list!')
expect_error(get_msready_by_formula_batch(API_key = ctx_key()), 'Please input a list of chemical formulas!')
expect_error(get_msready_by_formula_batch(formula_list = c(1), API_key = ctx_key()), 'Please input a character list for formula_list!')
expect_error(get_chemical_lists_by_type_batch(API_key = ctx_key()), 'Please input a list of list types!')
expect_error(get_chemical_lists_by_type_batch(type_list = c(1), API_key = ctx_key()), 'Please input a character list for type_list!')
expect_error(get_public_chemical_list_by_name_batch(API_key = ctx_key()), 'Please input a list of list names!')
expect_error(get_public_chemical_list_by_name_batch(name_list = c(1), API_key = ctx_key()), 'Please input a character list for name_list!')
expect_error(get_lists_containing_chemical_batch(API_key = ctx_key()), 'Please input a list of DTXSIDs!')
expect_error(get_lists_containing_chemical_batch(chemical_list = c(1), API_key = ctx_key()), 'Please input a character list for chemical_list!')
expect_error(get_chemicals_in_list_start_batch(API_key = ctx_key()), 'Please input a list for both `list_names` and `words`!')
expect_error(get_chemicals_in_list_start_batch(list_names = c('Biosolids2021'), words = c(1, 2), API_key = ctx_key()), 'Mismatch in length of `list_names` and `words`!')
expect_error(get_chemicals_in_list_start_batch(list_names = c(2021), words = c(1), API_key = ctx_key()), 'Only character values allowed in `list_names` and `words`!')
expect_error(get_chemicals_in_list_exact_batch(API_key = ctx_key()), 'Please input a list for both `list_names` and `words`!')
expect_error(get_chemicals_in_list_exact_batch(list_names = c('Biosolids2021'), words = c('T', 'F'), API_key = ctx_key()), 'Mismatch in length of `list_names` and `words`!')
expect_error(get_chemicals_in_list_exact_batch(list_names = c(2021), words = c(1), API_key = ctx_key()), 'Only character values allowed in `list_names` and `words`!')
expect_error(get_chemicals_in_list_contain_batch(API_key = ctx_key()), 'Please input a list for both `list_names` and `words`!')
expect_error(get_chemicals_in_list_contain_batch(list_names = c('Biosolids2021'), c(1, 2), API_key = ctx_key()), 'Mismatch in length of `list_names` and `words`!')
expect_error(get_chemicals_in_list_contain_batch(list_names = c(2021), words = c(1), API_key = ctx_key()), 'Only character values allowed in `list_names` and `words`!')
expect_error(get_chemicals_in_list_batch(API_key = ctx_key()), 'Please input a list of names of chemical lists!')
expect_error(get_chemicals_in_list_batch(list_name = c(1), API_key = ctx_key()), 'Please input a character list for list_names!')
})

# Pause requests for 5 seconds
Expand Down Expand Up @@ -250,8 +250,8 @@ test_that('Return data types', {
Sys.sleep(5)

#expect_type(chemical_contains_batch(word_list = c('DTXSID7020182'), API_key = ''), 'list')
expect_type(get_msready_by_mass_with_error_batch(masses = 226, error = 1), 'list')
expect_type(get_msready_by_mass_with_error_batch(masses = c(226, 228), error = 1), 'list')
expect_type(get_msready_by_mass_with_error_batch(masses = 226, error = 1, API_key = ctx_key()), 'list')
expect_type(get_msready_by_mass_with_error_batch(masses = c(226, 228), error = 1, API_key = ctx_key()), 'list')
expect_type(get_msready_by_mass_batch(start_list = c(16.0313), end_list = c(16.0314), API_key = ctx_key()), 'list')
expect_type(get_msready_by_mass_batch(start_list = c(16.0314), end_list = c(16.0314), API_key = ctx_key()), 'list')
#expect_type(get_msready_by_mass_batch(start_list = c(-16.0313), end_list = c(16.0314), API_key = ''), 'list')
Expand All @@ -271,15 +271,15 @@ test_that('Return data types', {
expect_type(get_lists_containing_chemical_batch(chemical_list = c('DTXSID7020182'), API_key = ctx_key()), 'list')
expect_type(get_lists_containing_chemical_batch(chemical_list = c(''), API_key = ctx_key()), 'list')
#expect_type(get_lists_containing_chemical_batch(chemical_list = c('DTXSID7020182'), API_key = ''), 'list')
expect_type(get_chemicals_in_list_start_batch(list_names = '', words = ''), 'list')
expect_type(get_chemicals_in_list_start_batch(list_names = '', words = '', API_key = ctx_key()), 'list')
#expect_type(get_chemicals_in_list_start_batch(list_names = '', words = '', API_key = ''), 'list')
expect_type(get_chemicals_in_list_start_batch(list_names = 'Biosolids2021', words = 'Bis'), 'list')
expect_type(get_chemicals_in_list_exact_batch(list_names = '', words = ''), 'list')
expect_type(get_chemicals_in_list_start_batch(list_names = 'Biosolids2021', words = 'Bis', API_key = ctx_key()), 'list')
expect_type(get_chemicals_in_list_exact_batch(list_names = '', words = '', API_key = ctx_key()), 'list')
#expect_type(get_chemicals_in_list_exact_batch(list_names = '', words = '', API_key = ''), 'list')
expect_type(get_chemicals_in_list_exact_batch(list_names = 'Biosolids2021', words = 'Bis'), 'list')
expect_type(get_chemicals_in_list_contain_batch(list_names = '', words = ''), 'list')
expect_type(get_chemicals_in_list_exact_batch(list_names = 'Biosolids2021', words = 'Bis', API_key = ctx_key()), 'list')
expect_type(get_chemicals_in_list_contain_batch(list_names = '', words = '', API_key = ctx_key()), 'list')
#expect_type(get_chemicals_in_list_contain_batch(list_names = '', words = '', API_key = ''), 'list')
expect_type(get_chemicals_in_list_contain_batch(list_names = 'Biosolids2021', words = 'Bis'), 'list')
expect_type(get_chemicals_in_list_contain_batch(list_names = 'Biosolids2021', words = 'Bis', API_key = ctx_key()), 'list')
expect_type(get_chemicals_in_list_batch(list_names = c('BIOSOLDIS2021'), API_key = ctx_key()), 'list')
expect_type(get_chemicals_in_list_batch(list_names = c(''), API_key = ctx_key()), 'list')
#expect_type(get_chemicals_in_list_batch(list_names = c('BIOSOLDIS2021'), API_key = ''), 'list')
Expand Down

0 comments on commit b83545e

Please sign in to comment.