~ubuntu-branches/debian/stretch/r-cran-rnexml/stretch

« back to all changes in this revision

Viewing changes to tests/testthat/test_publish.R

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2016-04-08 13:58:39 UTC
  • Revision ID: package-import@ubuntu.com-20160408135839-ilq08z8v8p414qpn
Tags: upstream-2.0.6
ImportĀ upstreamĀ versionĀ 2.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
context("publish")
 
2
 
 
3
if(0){  # skip publishing tests.  These were all still passing at last check, but rfigshare configuration for testing is not ideal.  
 
4
  
 
5
  
 
6
  
 
7
# This loads the rOpenSci figshare sandbox credentials, so that the example 
 
8
# can run automatically during check and install.  Unlike normal figshare accounts,
 
9
# data loaded to this testing sandbox is periodically purged.  
 
10
library(rfigshare)
 
11
status <- try(fs_auth(token = "xdBjcKOiunwjiovwkfTF2QjGhROeLMw0y0nSCSgvg3YQxdBjcKOiunwjiovwkfTF2Q", token_secret = "4mdM3pfekNGO16X4hsvZdg"))
 
12
if(is(status, "try-error") || (is(status, "response") && status$status_code != 200)){
 
13
  warning("Could not authenticate figshare, skipping figshare tests")
 
14
} else {
 
15
 
 
16
 
 
17
 
 
18
## Create example file
 
19
  library(geiger)
 
20
  data(geospiza)
 
21
 
 
22
  geiger_nex <- add_trees(geospiza$phy)
 
23
  geiger_nex <- add_characters(geospiza$dat, geiger_nex)
 
24
  geiger_nex <- add_basic_meta(
 
25
    title = "Geospiza phylogeny with character data rendered as NeXML", 
 
26
    creator = "Carl Boettiger", 
 
27
    description = "This example NeXML file was created using the data originally provided in the geiger package for R to illustrate how this data can be stored, shared and distributed as NeXML.", 
 
28
    citation = citation("geiger"), 
 
29
    nexml = geiger_nex)
 
30
 
 
31
 
 
32
  test_that("We can publish to figshare", {
 
33
 
 
34
## Publish 
 
35
  id <- nexml_publish(geiger_nex, visibility="public", repo="figshare")
 
36
 
 
37
 
 
38
## Download and parse publication 
 
39
## Note that at present, only public files can be automatically downloaded from figshare
 
40
  library(rfigshare)
 
41
  test_nex <- nexml_read(fs_download(id))
 
42
 
 
43
## Extract and compare metadata from upload and download 
 
44
  m <- get_metadata(geiger_nex)
 
45
  test_m <- get_metadata(test_nex)
 
46
  expect_equal(m["dc:title"], test_m["dc:title"])
 
47
  expect_equal(m["dc:description"], test_m["dc:description"])
 
48
 
 
49
## Check that DOI resolves -- doesn't for the test account
 
50
#library(httr)
 
51
#page <- GET(test_m[["dc:identifier"]])
 
52
#expect_equal(page$status_code, 200)
 
53
 
 
54
 
 
55
# Check that we avoid repeated metadata entries
 
56
 
 
57
  expect_equal(sum(match(names(test_m), "dc:pubdate"), na.rm=TRUE), 1)
 
58
  expect_equal(sum(match(names(test_m), "cc:license"), na.rm=TRUE), 1)
 
59
 
 
60
 
 
61
  })
 
62
 
 
63
 
 
64
 
 
65
}
 
66
 
 
67
}
 
68