Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug in search #13

Merged
merged 7 commits into from
Jun 1, 2018
Merged

Fixed bug in search #13

merged 7 commits into from
Jun 1, 2018

Conversation

isteves
Copy link
Collaborator

@isteves isteves commented May 30, 2018

I reworked the search processing with some better regex-ing, and now rt_search("Queue='arcticdata'") works without failing! (at least for me...) I really would like to write some tests, but I'm not sure if we can avoid pinging RT. If you've had any further thoughts on this, let me know.

One possibility is to have sample content(request) results stored in the inst folder (or somewhere else). I can then just test the data processing part of the process.

@amoeba

@amoeba
Copy link
Collaborator

amoeba commented May 30, 2018

LGTM, thanks!

I can't remember if we talked about changing the query param of rt_search to take a list. That might make it easier for the user to know what to type where. What do you think about that?

For your issue of wanting to test your processing code with a formal unit test, your intuition is right on. The way people like to do this is to make what's called a mock. It's basically what you said: save a copy of some response to some function call that usually is slow/can fail/etc and test that. This makes unit test unit tests and not integration tests!

I haven't done this directly with testthat, but there appears to be support: https://github.com/r-lib/testthat/blob/master/R/mock.R. Also see https://www.mango-solutions.com/blog/testing-without-the-internet-using-mock-functions.

R/rt_search.R Outdated
url <- paste0(base_api, "/search/ticket?query=", query)
#based on httr::modify_url()
#possible TODO - turn this into its own function that can be used internally in the package
l <- plyr::compact(list(query = query,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, hadn't seen plyr::compact. Do you think it's possible to do this without adding another dependency? Can tidyr do this so we don't need another dep?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to find it in dplyr/tidyr version of it, though I've noticed people sometimes include the code of other functions in a package to avoid exporting it (I've seen this in particular for %>%). It seems like this could lead to some naming conflicts if both are loaded, but perhaps that's okay in this case?

I asked Twitter and will maybe get an answer there...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this could lead to some naming conflicts if both are loaded, but perhaps that's okay in this case?

I'm not totally sure if you would so long as you don't export the binding.

The code for plyr::compact is just: function(l) Filter(Negate(is.null), l)

so it'd (1) easy to re-write in purrr or just copy the body of the function in and add a comment like # In-lined from https://github.com/hadley/plyr/blob/fe192412748d1ccb6d524caeb5bcf2b5c474fd46/R/utils.r#L42

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so apparently purrr::compact() exists, so I'll just use that (it's listed with keep in the documentation)

@amoeba
Copy link
Collaborator

amoeba commented May 30, 2018

PS: If you wanna leave this as implemented, we can totally merge now and you can add anything else you want later.

@isteves
Copy link
Collaborator Author

isteves commented Jun 1, 2018

I ended up going for the base R version since I haven't used purrr in the package yet.

@amoeba
Copy link
Collaborator

amoeba commented Jun 1, 2018

Right on. Not sure if you had this planned to add by I saw that plyr is still in the DESCRIPTION file.

@isteves
Copy link
Collaborator Author

isteves commented Jun 1, 2018

Good catch! forgot to ctrl + s -___-

@isteves isteves merged commit e55276a into NCEAS:master Jun 1, 2018
@isteves isteves deleted the search branch June 1, 2018 19:35
@amoeba
Copy link
Collaborator

amoeba commented Jun 1, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants