Example #1
0
async def startup():
    initialize()
    await database.connect()
Example #2
0
import asyncio
import os
os.environ['DATABASE_URL'] = 'sqlite:///./test.db'

import mock
import example
from example.models import Package, initialize
from example.server import app
from starlette.testclient import TestClient

loop = asyncio.get_event_loop()

initialize(drop_all=True)  # FIXME: do this before each test to prevent state?
client = TestClient(app)


def test_no_packages():
    response = client.get('/api/v1/packages')
    assert response.status_code == 200
    assert response.json() == []


def test_create_package():
    response = client.post('/api/v1/packages',
                           data='{"name":"hello","version":"2.10"}')
    assert response.status_code == 200
    assert response.json()['id'] == 1
    assert response.json()['status'] == 'created'


def test_list_packages():
Example #3
0
def main():
    print(f'initializing tables for {DATABASE_URL}...')
    initialize()
import os
os.environ['DATABASE_URL'] = 'sqlite:///./test.db'

from example.models import initialize
from example.server import app
from starlette.testclient import TestClient

initialize(drop_all=True)
client = TestClient(app)


def test_hello():
    response = client.get('/hello')
    assert response.status_code == 200
    assert response.json() == {'message': 'Hello World!'}