Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add tests for python and JS with pytest and jest. Update some g…
…h actions versions
- Loading branch information
Showing
14 changed files
with
237 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type {Config} from 'jest'; | ||
|
||
const config: Config = { | ||
preset: 'ts-jest', | ||
verbose: true, | ||
// testEnvironment: 'node', | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {describe, expect, test} from '@jest/globals'; | ||
import {Nanopub, NpProfile} from "../pkg/node"; | ||
|
||
const privKey=`MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCjY1gsFxmak6SOCouJPuEzHNForkqFhgfHE3aAIAx+Y5q6UDEDM9Q0EksheNffJB4iPqsAfiFpY0ARQY92K5r8P4+a78eu9reYrb2WxZb1qPJmvR7XZ6sN1oHD7dd/EyQoJmQsmOKdrqaLRbzR7tZrf52yvKkwNWXcIVhW8uxe7iUgxiojZpW9srKoK/qFRpaUZSKn7Z/zgtDH9FJkYbBsGPDMqp78Kzt+sJb+U2W+wCSSy34jIUxx6QRbzvn6uexc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kntwewmf3i7V8lT8ZTwVRsmObWU60ySJ8qKuwoBQodki2VX12NpMN1wgWe3qUUlr6gLJU4xAoGAet6nD3QKwk6TTmcGVfSWOzvpaDEzGkXjCLaxLKh9GreM/OE+h5aN2gUoFeQapG5rUwI/7Qq0xiLbRXw+OmfAoV2XKv7iI8DjdIh0F06mlEAwQ/B0CpbqkuuxphIbchtdcz/5ra233r3BMNIqBl3VDDVoJlgHPg9msOTRy13lFqc=`; | ||
const orcid="https://orcid.org/0000-0000-0000-0000"; | ||
const unsignedRdf = `@prefix : <http://purl.org/nanopub/temp/mynanopub#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
@prefix dc: <http://purl.org/dc/terms/> . | ||
@prefix pav: <http://purl.org/pav/> . | ||
@prefix prov: <http://www.w3.org/ns/prov#> . | ||
@prefix np: <http://www.nanopub.org/nschema#> . | ||
@prefix npx: <http://purl.org/nanopub/x/> . | ||
@prefix ex: <http://example.org/> . | ||
:Head { | ||
: np:hasAssertion :assertion ; | ||
np:hasProvenance :provenance ; | ||
np:hasPublicationInfo :pubinfo ; | ||
a np:Nanopublication . | ||
} | ||
:assertion { | ||
ex:mosquito ex:transmits ex:malaria . | ||
} | ||
:provenance { | ||
:assertion prov:hadPrimarySource <http://dx.doi.org/10.3233/ISU-2010-0613> . | ||
} | ||
:pubinfo { | ||
: dc:created "2014-07-24T18:05:11+01:00"^^xsd:dateTime ; | ||
pav:createdBy <http://orcid.org/0000-0002-1267-0234> ; | ||
a npx:ExampleNanopub . | ||
}` | ||
|
||
describe('Tests for the curies npm package', () => { | ||
// NOTE: `await init()` only needed in browser environment | ||
|
||
test('publish np', async () => { | ||
const profile = new NpProfile(privKey, orcid, "Your Name", ""); | ||
const np = await new Nanopub(unsignedRdf).publish(profile); | ||
|
||
console.log("Published Nanopub:", np.info()); | ||
expect(np.info().published).toBeDefined(); | ||
// expect(np.info().trusty_hash).toBe("RAE9traVUygMTJ-k8E1_pVNy3gtf7uUvtHJtPeU64WpA4"); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pytest | ||
from nanopub_sign import Nanopub, NpProfile, get_np_server | ||
|
||
rdf_str = """@prefix : <http://purl.org/nanopub/temp/mynanopub#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
@prefix dc: <http://purl.org/dc/terms/> . | ||
@prefix pav: <http://purl.org/pav/> . | ||
@prefix prov: <http://www.w3.org/ns/prov#> . | ||
@prefix np: <http://www.nanopub.org/nschema#> . | ||
@prefix npx: <http://purl.org/nanopub/x/> . | ||
@prefix ex: <http://example.org/> . | ||
:Head { | ||
: np:hasAssertion :assertion ; | ||
np:hasProvenance :provenance ; | ||
np:hasPublicationInfo :pubinfo ; | ||
a np:Nanopublication . | ||
} | ||
:assertion { | ||
ex:mosquito ex:transmits ex:malaria . | ||
} | ||
:provenance { | ||
:assertion prov:hadPrimarySource <http://dx.doi.org/10.3233/ISU-2010-0613> . | ||
} | ||
:pubinfo { | ||
: dc:created "2014-07-24T18:05:11+01:00"^^xsd:dateTime ; | ||
pav:createdBy <http://orcid.org/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8O7LeAZNlb0FsrtD7NU+Hciywo8qESiA7UYDkU6+hsmxaI01DsttMIdG4lSBbEjA7t4IQC5lyr7xiQKBgQCN87YGJ40Y5ZXCSgOZDepz9hqX2KGOIfnUv2HvXsIfiUwqTXs6HbD18xg3KL4myIBOvywSM+4ABYp+foY+Cpcq2btLIeZhiWjsKIrw71+Q/vIe0YDb1PGf6DsoYhmWBpdHzR9HN+hGjvwlsYny2L9Qbfhgxxmsuf7zeFLpQLijjwKBgH7TD28k8IOk5VKec2CNjKd600OYaA3UfCpP/OhDl/RmVtYoHWDcrBrRvkvEEd2/DZ8qw165Zl7gJs3vK+FTYvYVcfIzGPWA1KU7nkntwewmf3i7V8lT8ZTwVRsmObWU60ySJ8qKuwoBQodki2VX12NpMN1wgWe3qUUlr6gLJU4xAoGAet6nD3QKwk6TTmcGVfSWOzvpaDEzGkXjCLaxLKh9GreM/OE+h5aN2gUoFeQapG5rUwI/7Qq0xiLbRXw+OmfAoV2XKv7iI8DjdIh0F06mlEAwQ/B0CpbqkuuxphIbchtdcz/5ra233r3BMNIqBl3VDDVoJlgHPg9msOTRy13lFqc=""" | ||
|
||
# Instantiate nanopub profile | ||
profile = NpProfile( | ||
private_key=private_key, | ||
orcid_id="https://orcid.org/0000-0000-0000-0000", | ||
name="", | ||
introduction_nanopub_uri="" | ||
) | ||
|
||
def test_check(): | ||
np = Nanopub.check(rdf_str) | ||
assert not np.info()["trusty_hash"] | ||
assert not np.info()["published"] | ||
|
||
def test_sign(): | ||
np = Nanopub.sign( | ||
rdf=rdf_str, | ||
profile=profile, | ||
) | ||
assert np.info()["trusty_hash"] | ||
assert not np.info()["published"] | ||
|
||
def test_publish(): | ||
np = Nanopub.publish( | ||
rdf=rdf_str, | ||
profile=profile, | ||
server_url=None, | ||
) | ||
# print("Published", np.info()) | ||
# print(np.get_rdf()) | ||
assert np.info()["trusty_hash"] | ||
assert np.info()["published"] | ||
|
||
def test_get_np_server(): | ||
print(f"Random server: {get_np_server()}") | ||
assert len(get_np_server()) > 3 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
cargo test | ||
|
||
./scripts/test-js.sh | ||
./scripts/test-python.sh |
Oops, something went wrong.