Commit 464835bf authored by w2v1's avatar w2v1
Browse files

removed unecessary files

parent c991905c
Loading
Loading
Loading
Loading
+0 −0

Empty file deleted.

src/api/flask/web/bin/restoredb

deleted100644 → 0
+0 −0

Empty file deleted.

+0 −5
Original line number Diff line number Diff line
#!/bin/bash

cd /tmp/tests/
pytest -s .
# docker compose down test_db
 No newline at end of file
+0 −33
Original line number Diff line number Diff line
import pytest
import sys
import os

from path import Path
directory = Path(__file__).abspath()

# setting path
sys.path.append(directory.parent.parent)
from api.app import create_app

@pytest.fixture()
def app():
    app = create_app()
    app.config.update({
        "TESTING": True,
    })
    yield app


@pytest.fixture()
def client(app):
    return app.test_client()


@pytest.fixture()
def runner(app):
    return app.test_cli_runner()

def test_hello(client):
    response = client.get('/')
    print(response)
    assert response.json == {"H": "Welcome to the API"}
+0 −138
Original line number Diff line number Diff line
import pytest
import sys
import os
import json
from path import Path
directory = Path(__file__).abspath()

# setting path
sys.path.append(directory.parent.parent)

from flask import session, current_app, request
from flask_jwt_extended import create_access_token

# SCRIPT_DIR = os.path.dirname(os.path.abspath(__name__))
# sys.path.append(os.path.dirname(SCRIPT_DIR))

from web.api.app import create_app
from web.api.routes.api.user import _update_user, _create_response, _create_token, _create_logout_response
from api.flask.web.api.database.database import DatabaseClassName

from common.logz import create_logger
logger = create_logger()

mocked_saml_data = {
	"samlNameIdFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
	"samlNameIdNameQualifier": None,
	"samlNameIdSPNameQualifier": None,
	"samlSessionIndex": "_75f6155c-7377-47e0-bd2e-db9037345400",
	"samlUserdata": {
		"http://schemas.microsoft.com/claims/authnmethodsreferences": ["http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/windows"],
		"http://schemas.microsoft.com/identity/claims/displayname": ["test_last, test_first"],
		"http://schemas.microsoft.com/identity/claims/identityprovider": ["https://sts.windows.net/db3dbd43-4c4b-4544-9f8a-0553f9f5f25e/"],
		"http://schemas.microsoft.com/identity/claims/objectidentifier": ["82f38c58-dbe5-4c8b-8d53-d872c7f96cf4"],
		"http://schemas.microsoft.com/identity/claims/tenantid": ["db3dbd43-4c4b-4544-9f8a-0553f9f5f25e"],
		"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress": ["test@test.com"],
		"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname": ["test_first"],
		"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": ["ttt@test.com"],
		"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname": ["test_last"]
	},
	"userEmail": "test@test.com",
	"usertoken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTY3ODQ3NjM0MiwianRpIjoiYzQ1MmRmMjYtOTY4YS00YWY0LTlmYjEtMTM1ZjczOWM4NmE2IiwidHlwZSI6ImFjY2VzcyIsInN1YiI6Im1lZGxlbndrQG9ybmwuZ292IiwibmJmIjoxNjc4NDc2MzQyLCJleHAiOjE2Nzg1NjI3NDJ9.4IF2CFFmUukKYBbN3sF3r-FtLVFQp2n5utNQlQ3n3vY"
}

#fixtures

@pytest.fixture()
def app():

    app = create_app()
    app.config.update({
        "TESTING": True,
    })

    yield app

@pytest.fixture()
def client(app):
    return app.test_client()

@pytest.fixture()
def runner(app):
    return app.test_cli_runner()

@pytest.fixture()
def test_resp(app):
    return app.test_request_context()

#begin tests

def test_user_endpoint(client):
    response = client.get('/user?sso')
    assert response.status_code == 308
    assert response.request.path == "/user"
    response = client.get('/user?acs')
    assert response.status_code == 308
    assert response.request.path == "/user"

def test_create_access_token(client):
    with client:
        with client.session_transaction() as session:
            session['userEmail'] = 'test@ornl.gov'
        response = client.get('/user?sso')
        token = _create_token()
        assert len(token) > 0

def test_update_user(client):
    with client:
        with client.session_transaction() as session:
            session['samlUserdata'] = mocked_saml_data['samlUserdata']
        client.get("/user?sso")
        _update_user()
        attributes = mocked_saml_data
        email = mocked_saml_data['userEmail']
        session['userEmail'] = email
        with DatabaseClassName() as db:
            user = db.get_user_by_email(email)
        assert user[0][0] == 1000
        assert user[0][1] == 'test_first'
        assert user[0][2] == 'test_last'
        assert user[0][3] == 'test@test.com'

def test_create_response(client):
     with client:
        with client.session_transaction() as session:
            email = mocked_saml_data['userEmail']
            session['userEmail'] = email
        response = client.get('/user')
        _create_response()
        assert response.status_code == 308
        assert response.request.path == "/user"

def test_get_user_info(client):
     with client:
        with client.session_transaction() as session:
            email = mocked_saml_data['userEmail']
            session['userEmail'] = email
            access_token = create_access_token(session['userEmail'])
            headers = {
                'Authorization': 'Bearer {}'.format(access_token)
            }
        response = client.get("user/me", headers=headers)
        res = response.data.decode('utf8').replace("'", '"')
        r = json.loads(res)
        assert r['id'] == 1000
        assert r['firstName'] == 'test_first'
        assert r['lastName'] == 'test_last'
        assert r['email'] == 'test@test.com'

def test_logout(client):
    with client:
        response = client.get("/user/logout")
        assert len(session) == 0
        assert response.status_code == 302

def test_create_logout_response(client):
    with client:
        response = _create_logout_response()
        assert response.status_code == 302 
 No newline at end of file