def authenticated_client(populate_users): token = jwt.encode( { 'sub': populate_users[0].email, 'iat': populate_users[0].last_password_change + timedelta(seconds=1), 'exp': datetime.utcnow() + timedelta(minutes=30), }, yeti_config.core.secret_key).decode('UTF-8') AuthenticatedFlaskClient.token = token app.test_client_class = AuthenticatedFlaskClient return app.test_client()
"""Tests for the Observable API.""" import json import pytest from yeti.webapp import app app.testing = True client = app.test_client() # pylint: disable=fixme # TODO: Consider using pytest-flask for easier testing flask stuff, e.g.: # - Access to url_for objects to test routes # - Access to .json attribute of request @pytest.mark.usefixtures("clean_db") def test_index(populate_hostnames): """Test that a GET request fetches all Observables.""" rv = client.get('/api/observables/') response = json.loads(rv.data) assert len(response) == len(populate_hostnames) for element in response: assert isinstance(element['value'], str) @pytest.mark.usefixtures("clean_db") def test_get(populate_hostnames): """Test fetching single Observable by ID.""" rv = client.get('/api/observables/{0:d}/'.format(populate_hostnames[0].id)) response = json.loads(rv.data)