Skip to content

bovine.testing

bovine.testing

The goal of the testing module is to provide some examples of commonly used things to make writing tests easier.

Usage examples

For public_key and private_key

>>> from bovine.crypto.helper import pem_private_key_to_pem_public_key
>>> pem_private_key_to_pem_public_key(private_key) == public_key
True

For ed25519_key and did_key

>>> from bovine.crypto import private_key_to_did_key
>>> private_key_to_did_key(ed25519_key) == did_key
True

For activity_factory see also ActivityFactory

>>> activity_factory.like("http://bovine.example").build()
{'@context': 'https://www.w3.org/ns/activitystreams',
    'type': 'Like',
    'actor': 'http://actor.example',
    'published': '2024-09-26T18:35:42Z',
    'object': 'http://bovine.example'}

For object_factory see also ObjectFactory and the provided note

>>> object_factory.note(content="moo").build()
{'@context': 'https://www.w3.org/ns/activitystreams',
    'type': 'Note',
    'attributedTo': 'http://actor.example',
    'published': '2024-09-26T18:35:42Z',
    'content': 'moo'}

>>> note
{'@context': 'https://www.w3.org/ns/activitystreams',
    'type': 'Note',
    'attributedTo': 'http://actor.example',
    'to': ['https://www.w3.org/ns/activitystreams#Public'],
    'cc': ['http://actor.example/followers'],
    'published': '...',
    'content': 'moo'}

activity_factory module-attribute

activity_factory = ActivityFactory(actor)

The activity factory for the actor

activity_factory_id module-attribute

activity_factory_id = ActivityFactory(
    actor, id_generator=make_id
)

The activity factory for the actor with predefined id generator

actor module-attribute

actor = {
    "@context": [
        "https://www.w3.org/ns/activitystreams",
        "https://w3id.org/security/v1",
    ],
    "publicKey": {
        "id": "http://actor.example#name",
        "owner": "http://actor.example",
        "publicKeyPem": public_key,
    },
    "id": "http://actor.example",
    "type": "Person",
    "inbox": "http://actor.example/inbox",
    "outbox": "http://actor.example/outbox",
    "followers": "http://actor.example/followers",
}

Example of an ActivityStreams Actor

did_key module-attribute

did_key = f'did:key:{public_key_multibase}'

A did key

ecp256_key module-attribute

ecp256_key = (
    "z42twTcNeSYcnqg1FLuSFs2bsGH3ZqbRHFmvS9XMsYhjxvHN"
)

A NIST P-256 private key

ed25519_key module-attribute

ed25519_key = (
    "z3u2Yxcowsarethebestcowsarethebestcowsarethebest"
)

An Ed25519 private key encoded in multibase

note module-attribute

note = build()

Example of a Note object

object_factory module-attribute

object_factory = ObjectFactory(actor)

The object factory for the actor

private_key module-attribute

private_key = private_key

An RSA private key

public_key module-attribute

public_key = public_key

The public key corresponding to private_key

public_key_multibase module-attribute

public_key_multibase = (
    "z6MkekwC6R9bj9ErToB7AiZJfyCSDhaZe1UxhDbCqJrhqpS5"
)

A public ed25519 key encoded in multibase