예제 #1
0
파일: test.py 프로젝트: inauros/epam_app
    def setUp(self):
        self.config = config = configparser.ConfigParser()
        config.read('../config.ini')
        
        # write test config
        config['db']['test_database'] = 'test_epam_app'
        
        with open('../config.ini', 'w') as f:
            config.write(f)

        params_for_db = {'host': config['db']['host'],
                         'user': config['db']['user'],
                         'password': config['db']['password'],
                         'database': config['db']['database']}
        

        # create test DB
        with psycopg2.connect(**params_for_db) as connect:
            connect.set_isolation_level(0)
            with connect.cursor() as cursor:
                try:
                    cursor.execute('drop database test_epam_app')
                finally:
                    cursor.execute('create database test_epam_app')
                    
            
        from app.main import app
        app.testing = True
        self.app = app.test_client()
예제 #2
0
async def test_pages_charts(testapp):
    pages = [
        "403",
        "404",
        "500",
        "blank",
        "contacts",
        "e_commerce",
        "forgot-password",
        "invoice-print",
        "invoice",
        "lockscreen",
        "login",
        "pace",
        "profile",
        "project_add",
        "project_detail",
        "project_edit",
        "projects",
        "recover-password",
        "register",
    ]

    for page in pages:
        url = f"/pages/examples/{page}"
        client = app.test_client()
        response = await client.get(url)
        assert response.status_code == 200
예제 #3
0
    def setUp(self):
        db.drop_all()
        db.create_all()
        self.client = app.test_client()

        #add basic data to database
        new_drug = drug(DRUGid='e28b7d9c-e817-47c1-b227-97d8eca021a7',\
                        code='2062', name='杏仁', unit='克', alias=' ',\
                        py='xr', wb='sw', isClassical='1', SPETid=' ',\
                        illustration='', createDay='2008-03-25 01=42=59.000',\
                        optrid='c6543358-354b-4986-a06f-bd61b0cde15d', state='3')
        db.session.add(new_drug)

        new_fixedrecipe = fixedrecipe(FREPid='65dd5753-aad0-4261-94d3-09a67bd4f9a1',\
                        code='378', name='华盖散', effect='', py='HGS', wb='WUA', isClassical='1',\
                        SPETid=' ', illustration='', createDay='2008-03-25 02:05:10.000',\
                        optrid='c6543358-354b-4986-a06f-bd61b0cde15d', state='3')
        db.session.add(new_fixedrecipe)

        new_fixedrecipeItem = fixedrecipeItem(FRITid='9c18a29f-faa1-494d-839c-7a89cba439e8',\
                            DRUGid='e28b7d9c-e817-47c1-b227-97d8eca021a7',\
                            FREPid='65dd5753-aad0-4261-94d3-09a67bd4f9a1',\
                            quality='9.0000', sequence='0', illustration='')
        db.session.add(new_fixedrecipeItem)

        db.session.commit()
예제 #4
0
def client():

    redis_client = fakeredis.FakeStrictRedis()
    app.config['redis-client'] = redis_client
    app.config['TESTING'] = True
    client = app.test_client()
    yield client
예제 #5
0
def client():
    app.config['TESTING'] = True

    ctx = app.test_request_context()
    ctx.push()

    return app.test_client()
예제 #6
0
def test_vader_empty_response():

    from app.main import app
    datastring = {"responses": [""]}
    res = app.test_client().post('/getKeywordsWithSentiment/', json=datastring)
    result = json.loads(res.data.decode('utf-8'))
    assert result['words'] == [[]]
예제 #7
0
def test_pytextrank_empty_phrases():

    from app.main import app
    datastring = {"responses": ["the"]}
    res = app.test_client().post('/getKeywordsBatch/', json=datastring)
    result = json.loads(res.data.decode('utf-8'))
    assert result['words'] == [[]]
예제 #8
0
    def setUp(self):
        db.drop_all()
        db.create_all()
        self.client = app.test_client()

        #add basic data to database
        new_drug = drug(DRUGid='e28b7d9c-e817-47c1-b227-97d8eca021a7',\
                        code='2062', name='杏仁', unit='克', alias=' ',\
                        py='xr', wb='sw', isClassical='1', SPETid=' ',\
                        illustration='', createDay='2008-03-25 01=42=59.000',\
                        optrid='c6543358-354b-4986-a06f-bd61b0cde15d', state='3')
        db.session.add(new_drug)

        new_fixedrecipe = fixedrecipe(FREPid='65dd5753-aad0-4261-94d3-09a67bd4f9a1',\
                        code='378', name='华盖散', effect='', py='HGS', wb='WUA', isClassical='1',\
                        SPETid=' ', illustration='', createDay='2008-03-25 02:05:10.000',\
                        optrid='c6543358-354b-4986-a06f-bd61b0cde15d', state='3')
        db.session.add(new_fixedrecipe)

        new_fixedrecipeItem = fixedrecipeItem(FRITid='9c18a29f-faa1-494d-839c-7a89cba439e8',\
                            DRUGid='e28b7d9c-e817-47c1-b227-97d8eca021a7',\
                            FREPid='65dd5753-aad0-4261-94d3-09a67bd4f9a1',\
                            quality='9.0000', sequence='0', illustration='')
        db.session.add(new_fixedrecipeItem)

        db.session.commit()
async def test_pages_mailbox(testapp):
    pages = ["compose", "mailbox", "read-mail"]

    for page in pages:
        url = f"/pages/mailbox/{page}"
        client = app.test_client()
        response = await client.get(url)
        assert response.status_code == 200
예제 #10
0
async def test_pages_forms(testapp):
    pages = ["advanced", "editors", "general", "validation"]

    for page in pages:
        url = f"/pages/forms/{page}"
        client = app.test_client()
        response = await client.get(url)
        assert response.status_code == 200
예제 #11
0
async def test_pages(testapp):
    pages = ["calendar", "gallery", "widgets"]

    for page in pages:
        url = f"/pages/{page}"
        client = app.test_client()
        response = await client.get(url)
        assert response.status_code == 200
예제 #12
0
def test_pytextrank_exception_response():

    from app.main import app
    datastring = {"words": [""]}
    with pytest.raises(Exception):
        res = app.test_client().post('/getKeywordsBatch/', json=datastring)
        result = json.loads(res.data.decode('utf-8'))
        assert result['words'] == [[]]
예제 #13
0
def client(request):
    test_client = app.test_client()

    def teardown():
        pass  # databases and resourses have to be freed at the end. But so far we don't have anything

    request.addfinalizer(teardown)
    return test_client
예제 #14
0
async def test_pages_tables(testapp):
    pages = ["data", "jsgrid", "simple"]

    for page in pages:
        url = f"/pages/tables/{page}"
        client = app.test_client()
        response = await client.get(url)
        assert response.status_code == 200
예제 #15
0
    def setUp(self):
        # set up the test DB
        self.db = tested_db
        self.db.create_all()
        self.db.session.add(Person(id=1, name="Alice"))
        self.db.session.add(Person(id=2, name="Bob"))
        self.db.session.commit()

        self.app = tested_app.test_client()
예제 #16
0
def test_to_game_coverage():
    # Arrange
    client = app.test_client()

    # Act
    body = {"url": "https://www.meetup.com/indypy/"}
    response = client.post("/top-word", json=body)

    return response
예제 #17
0
def client():
    app.config["TESTING"] = True

    with app.test_client() as client:
        init_db()
        yield client

    db_session.remove()
    os.unlink(config().DATABASE_URL.replace("sqlite:///", ""))
def app_fixture():
    app.config['SQLALCHEMY_DATABASE_URI'] = TEST_DATABASE_URI
    app.config['TESTING'] = True
    client = app.test_client()
    with app.app_context():
        db.init_app(app)
    app.app_context().push()
    db.create_all()
    yield client
    os.remove("app/test_project.db")
예제 #19
0
def test_pytextrank():

    from app.main import app
    datastring = {"responses": ["Life is good"]}
    res = app.test_client().post('/getKeywordsBatch/', json=datastring)
    result = json.loads(res.data.decode('utf-8'))
    assert len(result['words']) == 1
    assert result['words'][0][0]['phrase'] == "life"
    assert result['words'][0][0]['count'] == 1
    assert result['words'][0][0]['rank'] == 1.0
예제 #20
0
def test_end_to_end():
    # Arrange
    client = app.test_client()

    # Act
    body = {"url": "https://www.meetup.com/indypy/"}
    response = client.post("/top-word", json=body)

    # Assert
    assert response.status_code == HTTPStatus.OK
예제 #21
0
    def setUpClass(cls):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///testdb.sqlite3'

        if not api.resources:
            add_resources(api)
            api.init_app(app)

        cls.test_client = app.test_client()
예제 #22
0
async def test_pages_charts(testapp):
    pages = [
        "chartjs",
        "flot",
        #'inline'
    ]

    for page in pages:
        url = f"/pages/charts/{page}"
        client = app.test_client()
        response = await client.get(url)
        assert response.status_code == 200
예제 #23
0
def client(db):
    app.config["DATABASE_URL"] = TEST_DATABASE
    app.config["TESTING"] = True

    try:
        sql.create_tables(db)
    except Exception:
        pass

    sql.clear_tables(db)
    with app.test_client() as client:
        yield client
예제 #24
0
def client_with_testdata():
    app.config["TESTING"] = True

    with app.test_client() as client:
        init_db()

        file = open("./tests/api/v1/sample_data.sql", mode="r", encoding="utf-8")
        engine.execute(text(file.read()))

        yield client

    db_session.remove()
    os.unlink(config().DATABASE_URL.replace("sqlite:///", ""))
예제 #25
0
async def test_pages_ui(testapp):
    pages = [
        "buttons",
        "general",
        "icons",
        "modals",
        "navbar",
        "ribbons",
        "sliders",
        "timeline",
    ]

    for page in pages:
        url = f"/pages/ui/{page}"
        client = app.test_client()
        response = await client.get(url)
        assert response.status_code == 200
    def test_login(self):
        """ TODO: add user to database first """
        login_url = url_for('index')
        login_data = {'email': '*****@*****.**', 'password': '******'}

        # @see "class EnvironBuilder"
        # https://github.com/mitsuhiko/werkzeug/blob/d4e8b3f46c51e7374388791282e66323f64b3068/werkzeug/test.py#L212
        wsgi_env = {
            'REMOTE_ADDR': '1.2.3.4',
            'HTTP_USER_AGENT':
            'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0'}

        with self.app.test_request_context(environ_base=wsgi_env):
            with app.test_client() as client:
                # Trigger execution of before_request()
                app.preprocess_request()
                response = client.post(login_url, login_data)
                print("Try to login response: {}".format(response))
예제 #27
0
    def test_login(self):
        """ TODO: add user to database first """
        login_url = url_for('index')
        login_data = {'email': '*****@*****.**', 'password': '******'}

        # @see "class EnvironBuilder"
        # https://github.com/mitsuhiko/werkzeug/blob/d4e8b3f46c51e7374388791282e66323f64b3068/werkzeug/test.py#L212
        wsgi_env = {
            'REMOTE_ADDR':
            '1.2.3.4',
            'HTTP_USER_AGENT':
            'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0'
        }

        with self.app.test_request_context(environ_base=wsgi_env):
            with app.test_client() as client:
                # Trigger execution of before_request()
                app.preprocess_request()
                response = client.post(login_url, login_data)
                print("Try to login response: {}".format(response))
예제 #28
0
    def test_user(self):
        c = app.test_client()

        # First add 1 key
        body = {"key": "cool_key", "value": "cool_value"}
        response = c.post("/demo/user/BobLoblaw", json=body)
        data = json.loads(response.get_data())
        self.assertEqual(response.status_code, 200)
        self.assertEqual(data["data"]["cool_key"], "cool_value")

        # Then add a second key, result should return both values
        body = {"key": "gr8_key", "value": "gr8_value"}
        response = c.post("/demo/user/BobLoblaw", json=body)
        data = json.loads(response.get_data())
        self.assertEqual(response.status_code, 200)
        self.assertEqual(data["data"]["cool_key"], "cool_value")
        self.assertEqual(data["data"]["gr8_key"], "gr8_value")

        # Now a get should return both values as well
        response = c.get("/demo/user/BobLoblaw")
        data = json.loads(response.get_data())
        self.assertEqual(response.status_code, 200)
        self.assertEqual(data["data"]["cool_key"], "cool_value")
        self.assertEqual(data["data"]["gr8_key"], "gr8_value")
예제 #29
0
 def test_hello(self):
     c = app.test_client()
     response = c.get("/demo")
     text = response.get_data()
     self.assertEqual(response.status_code, 200)
     self.assertEqual(text, b"Hello, Conducto!")
예제 #30
0
 def test_hacker(self):
     # 'hacker' is not authorized to access this endpoint
     c = app.test_client()
     response = c.get("/demo/user/hacker")
     self.assertEqual(response.status_code, 401)
예제 #31
0
def test_root():
    from app.main import app
    res = app.test_client().get('/')
    assert res
예제 #32
0
def client(app):
    with app.test_client() as client:
        yield client