Skip to content

Commit

Permalink
Tests for documents model and CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
polyatail committed Feb 13, 2019
1 parent fc37150 commit 101d782
Show file tree
Hide file tree
Showing 9 changed files with 20,361 additions and 14 deletions.
3 changes: 2 additions & 1 deletion onecodex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import re
import sys
import time
import warnings

from onecodex.api import Api
Expand Down Expand Up @@ -130,7 +131,7 @@ def _size_formatter(size):
docs_list = sorted(
docs_list,
reverse=True,
key=lambda x: dateutil.parser.parse(x['created_at']).timestamp()
key=lambda x: time.mktime(dateutil.parser.parse(x['created_at']).timetuple())
)

for doc in docs_list:
Expand Down
308 changes: 308 additions & 0 deletions tests/api_data/documents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
[
{
"$uri": "/api/v1/documents/a375a9e4c1484df1",
"created_at": "2019-02-08T13:54:36.768056-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
{
"$ref": "/api/v1/users/2466143688c341db"
}
],
"downloads_remaining": null,
"filename": "foobar_report.pdf",
"size": 442139,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/0dc8710bb7bc4006",
"created_at": "2019-02-08T17:35:32.076268-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/2466143688c341db"
},
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "report_demo_0.4.0rc1.ipynb",
"size": 345742,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/1a9cb99039ea4b74",
"created_at": "2019-02-08T17:42:28.209949-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "andy's report.pdf",
"size": 442331,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/289bf5b57205434c",
"created_at": "2019-02-11T10:32:31.295023-08:00",
"description": null,
"downloaders": [],
"downloads_remaining": null,
"filename": "tiny.fq.gz",
"size": 24400,
"uploader": {
"$ref": "/api/v1/users/2466143688c341db"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/b7e59a0e037f4eeb",
"created_at": "2019-02-11T13:35:55.998538-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "new test report.pdf",
"size": 441968,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/140a59776ea54327",
"created_at": "2019-02-11T14:17:53.296754-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/2466143688c341db"
},
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "exceptionally long filename that is way way too long.pdf",
"size": 442160,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/8b3d04db987542cf",
"created_at": "2019-02-11T16:48:02.820663-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "output_13_0.png",
"size": 61535,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/ae535382f2104c9e",
"created_at": "2019-02-11T16:48:02.824373-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
{
"$ref": "/api/v1/users/2466143688c341db"
}
],
"downloads_remaining": null,
"filename": "output_17_2.png",
"size": 30297,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/39a78f513cdf46e7",
"created_at": "2019-02-11T16:48:02.856574-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "output_16_0.png",
"size": 158956,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/e89fbbcd95f142a8",
"created_at": "2019-02-11T16:48:02.864876-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
{
"$ref": "/api/v1/users/2466143688c341db"
}
],
"downloads_remaining": null,
"filename": "output_15_0.png",
"size": 363390,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/4a46cca64e4c46d9",
"created_at": "2019-02-11T16:48:12.839417-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "One Codex.htm",
"size": 18151,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/4eb36bbbc85241f7",
"created_at": "2019-02-11T16:48:12.849215-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "report_formatting.rtf",
"size": 1011,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/058e49a62e654c04",
"created_at": "2019-02-11T16:48:12.854066-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
{
"$ref": "/api/v1/users/2466143688c341db"
}
],
"downloads_remaining": null,
"filename": "report_demo_pdf.pdf",
"size": 445617,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/8760cfa6cac54bdf",
"created_at": "2019-02-11T16:50:35.541875-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
{
"$ref": "/api/v1/users/2466143688c341db"
}
],
"downloads_remaining": null,
"filename": "OneCodexTakeHome.zip",
"size": 373741,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/11724f3462f249ea",
"created_at": "2019-02-12T15:25:29.291358-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "run all and save.pdf",
"size": 441888,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/2cceb2d10d0b41b6",
"created_at": "2019-02-12T15:27:55.577591-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "Röö's report.pdf",
"size": 441882,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
},
{
"$uri": "/api/v1/documents/a4f6727a840a4df0",
"created_at": "2019-02-12T15:59:30.483304-08:00",
"description": null,
"downloaders": [
{
"$ref": "/api/v1/users/4ada56103d9a48b8"
}
],
"downloads_remaining": null,
"filename": "report.pdf",
"size": 442074,
"uploader": {
"$ref": "/api/v1/users/4ada56103d9a48b8"
},
"valid_until": null
}
]
54 changes: 53 additions & 1 deletion tests/api_data/schema.json
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
{"$schema": "http://json-schema.org/draft-04/hyper-schema#", "description": "The One Codex API (v1) -- programmatic access to One Codex's suite of microbial genomics data storage, analysis, and query tools.", "properties": {"account": {"$ref": "/api/v1/account/schema#"}, "alignments": {"$ref": "/api/v1/alignments/schema#"}, "analyses": {"$ref": "/api/v1/analyses/schema#"}, "classifications": {"$ref": "/api/v1/classifications/schema#"}, "controls": {"$ref": "/api/v1/controls/schema#"}, "jobs": {"$ref": "/api/v1/jobs/schema#"}, "metadata": {"$ref": "/api/v1/metadata/schema#"}, "panels": {"$ref": "/api/v1/panels/schema#"}, "projects": {"$ref": "/api/v1/projects/schema#"}, "reports": {"$ref": "/api/v1/reports/schema#"}, "samples": {"$ref": "/api/v1/samples/schema#"}, "tags": {"$ref": "/api/v1/tags/schema#"}, "users": {"$ref": "/api/v1/users/schema#"}}, "title": "One Codex API (v1)", "version_info": {"api_version": "v1", "cli_version": "0.2.0"}}
{
"$schema": "http://json-schema.org/draft-04/hyper-schema#",
"description": "The One Codex API (v1) -- programmatic access to One Codex's suite of microbial genomics data storage, analysis, and query tools.",
"properties": {
"account": {
"$ref": "/api/v1/account/schema#"
},
"alignments": {
"$ref": "/api/v1/alignments/schema#"
},
"analyses": {
"$ref": "/api/v1/analyses/schema#"
},
"classifications": {
"$ref": "/api/v1/classifications/schema#"
},
"controls": {
"$ref": "/api/v1/controls/schema#"
},
"documents": {
"$ref": "/api/v1/documents/schema#"
},
"jobs": {
"$ref": "/api/v1/jobs/schema#"
},
"metadata": {
"$ref": "/api/v1/metadata/schema#"
},
"panels": {
"$ref": "/api/v1/panels/schema#"
},
"projects": {
"$ref": "/api/v1/projects/schema#"
},
"reports": {
"$ref": "/api/v1/reports/schema#"
},
"samples": {
"$ref": "/api/v1/samples/schema#"
},
"tags": {
"$ref": "/api/v1/tags/schema#"
},
"users": {
"$ref": "/api/v1/users/schema#"
}
},
"title": "One Codex API (v1)",
"version_info": {
"api_version": "v1",
"cli_version": "0.2.0"
}
}
19,885 changes: 19,884 additions & 1 deletion tests/api_data/schema_all.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/api_data/users.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"$uri": "/api/v1/users/4ada56103d9a48b8", "email": "asmngs@onecodex.com", "username": null}]
[{"$uri": "/api/v1/users/4ada56103d9a48b8", "email": "asmngs@onecodex.com", "username": null},{"$uri": "/api/v1/users/2466143688c341db", "email": "recipient@onecodex.com", "username": null}]
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ def update_metadata_callback(req):
"download_uri": "http://localhost:3000/mock/download/url"
},
"GET::mock/download/url": "1234567890",
"POST::api/v1/documents/a4f6727a840a4df0/download_uri": {
"download_uri": "http://localhost:3000/mock/download/url"
},
}

# explicitly load classification results for testing subset_reads
Expand Down
Loading

0 comments on commit 101d782

Please sign in to comment.