Skip to content

Commit b7a0341

Browse files
committed
adjustments after an API release
1 parent bb8cb6f commit b7a0341

File tree

3 files changed

+43
-32
lines changed

3 files changed

+43
-32
lines changed

Diff for: tests/testthat/test-api-bugs.R

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_that("Queries returning non-utility patents don't page well", {
1+
test_that("Queries returning non-utility patents well", {
22
skip_on_cran()
33
only_utility_qry <- with_qfuns(
44
and(
@@ -18,7 +18,7 @@ test_that("Queries returning non-utility patents don't page well", {
1818

1919
all_types_res <- search_pv(only_utility_qry, all_pages = TRUE)
2020
expect_true(
21-
nrow(all_types_res$data$patents) != all_types_res$query_results$total_hits
21+
nrow(all_types_res$data$patents) == all_types_res$query_results$total_hits
2222
)
2323
})
2424

@@ -41,6 +41,7 @@ test_that("inventors.inventor and assignees.assignee aren't returned
4141
expect_no_error(good_res$data$patents$assignees[[1]]$assignee)
4242
})
4343

44+
# this seems to have been fixed- empty lists are returned
4445
# See bug report in PatentsView API repo: PVS-1125
4546
test_that("Fields that are all NULL don't return at all", {
4647
skip_on_cran()
@@ -59,12 +60,12 @@ test_that("Fields that are all NULL don't return at all", {
5960

6061
result1 <- search_pv(query, fields = fields, sort = sort, size = 1000)
6162
no_cpc_at_issue <- colnames(result1$data$patents)
62-
expect_false("cpc_at_issue" %in% no_cpc_at_issue)
63+
expect_true("cpc_at_issue" %in% no_cpc_at_issue)
6364

6465
result2 <- search_pv(query, fields = fields, sort = sort, size = 10)
65-
two_field_result <- colnames(result2$data$patents)
66+
three_field_result <- colnames(result2$data$patents)
6667
# only returns: c("patent_id", "uspc_at_issue")
67-
expect_true(length(two_field_result) == 2)
68+
expect_true(length(three_field_result) == 3)
6869
})
6970

7071
# Reported to the API team PVS-1147
@@ -173,6 +174,7 @@ test_that("We can't sort by all fields", {
173174
expect_lt(length(results), length(sorts_to_try))
174175
})
175176

177+
# this is fixed, w/d patents only come back if option exclude_withdrawn is false
176178

177179
# PVS-1342 Underlying data issues
178180
# There are ~8,000 patents that were in the bulk XML files that PatentsView is
@@ -191,7 +193,7 @@ test_that("Withdrawn patents are still present in the database", {
191193

192194
query <- qry_funs$eq("patent_id" = withdrawn)
193195
results <- search_pv(query, method = "POST")
194-
expect_equal(results$query_results$total_hits, length(withdrawn))
196+
expect_equal(results$query_results$total_hits, 0)
195197
})
196198

197199
# PVS-1342 Underlying data issues
@@ -212,3 +214,15 @@ test_that("Missing patents are still missing", {
212214

213215
expect_equal(results$query_results$total_hits, 0)
214216
})
217+
218+
# PVS-1884 The publication endpoint's rule_47_flag is always false
219+
test_that("Querying the publication endpoint on rule_47_flag isn't meaningful", {
220+
skip_on_cran()
221+
222+
res <- search_pv(qry_funs$eq(rule_47_flag = TRUE), endpoint = "publication")
223+
expect_equal(res$query_results$total_hits, 0)
224+
225+
res <- search_pv(qry_funs$eq(rule_47_flag = FALSE), endpoint = "publication")
226+
expect_gt(res$query_results$total_hits, 8000000)
227+
228+
})

Diff for: tests/testthat/test-check-query.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ test_that("errors are thrown on invalid queries", {
3838
)
3939

4040
expect_error(
41-
search_pv(qry_funs$eq("rule_47_flag" = TRUE), endpoint = "publication"),
42-
"^.* must be of type character$"
41+
search_pv(qry_funs$eq("rule_47_flag" = "TRUE"), endpoint = "publication"),
42+
"^.* must be a boolean$"
4343
)
4444

4545
expect_error(

Diff for: tests/testthat/test-search-pv.R

+21-24
Original file line numberDiff line numberDiff line change
@@ -146,38 +146,36 @@ test_that("We can call all the legitimate HATEOAS endpoints", {
146146
})
147147

148148
test_that("Shorthand specification of fields results in expected results", {
149-
149+
skip_on_cran()
150150
query <- TEST_QUERIES[["patent"]]
151151

152+
# We ask for all of assignee's nested fields (total of 9 fields currently).
153+
# It gets turned into a shorthand request, however now 11 fields are returned.
154+
# Returned but not requested: assignee and assignee_location_id
155+
# Now the test is really that the shorthand notation was used and
156+
# that we got back all of the requested fields, ignoring the extras
152157
all_assn_flds <- get_fields("patent", groups = "assignees")
153-
full_res <- search_pv(query, fields = all_assn_flds)
158+
full_res <- search_pv(query, fields = all_assn_flds, method = "POST")
159+
api_request <- httr2::last_request()$body$data
160+
expect_true(grepl('"f":\\["assignees","patent_id"\\]', api_request))
161+
162+
unnested_requested_flds <- sub(".*\\.(.*)", "\\1", all_assn_flds)
163+
returned_flds <- names(full_res$data$patents$assignees[[1]])
164+
expect_true(all(unnested_requested_flds %in% returned_flds))
154165

166+
# Here we explicitly request 8 fields but we get 9 back. We get assignee_id back
167+
# as well as assignee (that we didn't ask for). The opposite is not true,
168+
# asking for just assignee doesn't return assignee or assignee_id
155169
no_city <- all_assn_flds[all_assn_flds != "assignees.assignee_city"]
156170
no_city_res <- search_pv(query, fields = no_city)
157171

158-
no_city_has_seven <- length(no_city_res$data$patents$assignees[[1]]) == 7
159-
all_cols_has_nine <- length(full_res$data$patents$assignees[[1]]) == 9
160-
expect_true(no_city_has_seven&& all_cols_has_nine)
161-
})
162-
163-
test_that("nested shorthand produces the same results as fully qualified ones", {
164-
skip_on_cran()
165-
166-
# The API now allows you to use the `group` name in place of all the field
167-
# names belonging to that group when specifying which fields you want. The
168-
# group names are given in fieldsdf$group.
169-
# This is indirectly testing our parse of the OpenAPI object in
170-
# data-raw/fieldsdf.R
171-
all_qualified_fields <- fieldsdf[
172-
fieldsdf$endpoint == "patent" & fieldsdf$group == "application",
173-
"field"
174-
]
172+
unnested_requested_flds <- sub(".*\\.(.*)", "\\1", no_city)
173+
returned_flds <- names(no_city_res$data$patents$assignees[[1]])
175174

176-
query <- TEST_QUERIES[["patent"]]
177-
shorthand_res <- search_pv(query, fields = "application")
178-
qualified_res <- search_pv(query, fields = all_qualified_fields)
175+
# we request "assignee" but don't get "assignee" or "assignee_id" back
176+
# so we can't expect_true TODO move to api-bugs?
177+
expect_false(all(unnested_requested_flds %in% returned_flds))
179178

180-
expect_equal(shorthand_res$data, qualified_res$data)
181179
})
182180

183181
test_that("The 'after' parameter works properly", {
@@ -189,7 +187,6 @@ test_that("The 'after' parameter works properly", {
189187
expect_gt(results$query_results$total_hits, 1000)
190188

191189
after <- results$data$patents$patent_id[[nrow(results$data$patents)]]
192-
after <- pad_patent_id(after)
193190
subsequent <- search_pv(big_query, after = after, sort = sort)
194191

195192
expect_equal(nrow(subsequent$data$patents), 1000)

0 commit comments

Comments
 (0)