예제 #1
0
파일: test_api.py 프로젝트: olymk2/serJax
def test_status():
    """Get size in waiting"""
    with fetch_api_lock() as (app, mpty, spty, mport, sport, rlock, lock):
        response = app.put('/open',
                           data={'port': sport},
                           headers={'api_lock': lock})
        response = app.get('/status')
        assert response.status_code == 201
예제 #2
0
파일: test_api.py 프로젝트: olymk2/serJax
def test_read_data():
    """test reading data from api"""
    with fetch_api_lock() as (app, mpty, spty, mport, sport, rlock, lock):
        response = app.put('/open',
                           data={'port': sport},
                           headers={'api_lock': lock})
        response = app.get('/recv', headers={'api_lock': lock})
        assert response.status_code == 201
예제 #3
0
파일: test_api.py 프로젝트: olymk2/serJax
def test_open_non_existant_port():
    """testing opening a serial port that does not exist"""
    with fetch_api_lock() as (app, mpty, spty, mport, sport, rlock, lock):
        # response = app.get('/close')
        response = app.put('/open',
                           data={'port': '/dev/ttyNull'},
                           headers={'api_lock': lock})
        assert response.status_code == 404
예제 #4
0
파일: test_api.py 프로젝트: olymk2/serJax
def test_get_port_list():
    """Get a list of ports this can be done by anyone at any time no locking involved"""
    with fetch_api_lock() as (app, mpty, spty, mport, sport, rlock, lock):
        response = app.get('/ports')
        assert response.status_code == 201

        json_data = json.loads(response.get_data().decode('ascii'))
        assert sport in json_data.get('ports')
        assert mport in json_data.get('ports')
예제 #5
0
파일: test_api.py 프로젝트: olymk2/serJax
def test_in_waiting():
    """Get size in waiting"""
    with fetch_api_lock() as (app, mpty, spty, mport, sport, rlock, lock):
        response = app.put('/open',
                           data={'port': sport},
                           headers={'api_lock': lock})
        response = app.get('/waiting', headers={'api_lock': lock})

        assert response.status_code == 201

        json_data = json.loads(response.get_data().decode('ascii'))
        assert json_data.get('size') == 0
예제 #6
0
파일: test_api.py 프로젝트: olymk2/serJax
def test_write_data():
    """test writting data to the api"""
    with fetch_api_lock() as (app, mpty, spty, mport, sport, rlock, lock):
        send_data = u'ello'
        response = app.put('/open',
                           data={'port': sport},
                           headers={'api_lock': lock})
        response = app.put('/write',
                           data={'data': send_data},
                           headers={'api_lock': lock})
        assert send_data == os.read(mpty, 1024).decode('ascii')
        assert response.status_code == 201
예제 #7
0
파일: test_api.py 프로젝트: olymk2/serJax
def test_open_port():
    """helper to get lock and open serial port"""
    with fetch_api_lock() as (app, mpty, spty, mport, sport, rlock, lock):
        app.put('/open', data={'port': sport}, headers={'api_lock': lock})
예제 #8
0
파일: test_api.py 프로젝트: olymk2/serJax
def test_open_port_when_api_is_locked():
    """testing opening a serial port when the api is locked"""
    with fetch_api_lock() as (app, mpty, spty, mport, sport, rlock, lock):
        response = app.get('/open')
        assert response.status_code == 404
예제 #9
0
파일: test_api.py 프로젝트: olymk2/serJax
def test_create_api_lock():
    """Test that we can get an api_lock key"""
    with fetch_api_lock() as (app, mpty, spty, mport, sport, rlock, lock):
        assert len(lock) > 36
        assert rlock.status_code == 201