Ejemplo n.º 1
0
def test_submit_existing_date_failed(perform_handshake):
    date = datetime(2017, 11, 25, 15, 55)
    iso_date = date.isoformat()
    session_id, _, submit_url = perform_handshake()
    rep = post(submit_url,
               data={
                   'a[0]': 'Test',
                   'b[0]': 'Test',
                   't[0]': 'Test',
                   'i[0]': str(int(date.timestamp())),
                   's': session_id
               })
    assert rep.status_code == 200, rep.text
    assert rep.text == 'OK'

    for key in ('artists', 'albums', 'tracks'):
        data = get(key, offset=0, limit=100)
        assert len(data['items']) == 1 == data['total']
        item = data['items'][0]
        assert item['plays'] == 1
        assert item['first_play'] == iso_date == item['last_play']
    plays = get('plays', offset=0, limit=100)
    assert len(plays['items']) == 1 == plays['total']
    play = plays['items'][0]
    assert play['track_id'] == 1
    assert play['date'] == iso_date
Ejemplo n.º 2
0
def test_invalid_token(authorization_header):
    response = client.get('/user/me', headers=authorization_header)
    assert response.status_code == 200

    response = client.get('/user/me', headers=create_header('broken_token'))
    assert response.status_code == 401

    response = client.get('/user/me', headers=create_header('bearer broken_token'))
    assert response.status_code == 401
Ejemplo n.º 3
0
def test_role_metrics_equal_probe_role_metrics():
    update_base_metrics()
    response1 = client.get(f'/role/{TEST_ROLE}/metrics')
    print(f'Response role metrics text:\n{response1.text}')
    assert response1.status_code == 200
    response2 = client.get(f'/probe?module=role&target={TEST_ROLE}')
    assert response2.status_code == 200
    assert response2.text == response1.text
    check_role_response(response1)
Ejemplo n.º 4
0
def test_download_run_dne(authorization_header):
    response = client.get('/pipeline/download/', headers=authorization_header)
    assert response.status_code != 200

    response = client.get('/pipeline/download/-1', headers=authorization_header)
    assert response.status_code == 404

    response = client.get('/pipeline/download/0', headers=authorization_header)
    assert response.status_code == 404
Ejemplo n.º 5
0
def test_get_bonds_bad_creds(client):
    response = client.get("/api/v1/bonds")
    assert response.status_code == 401
    assert b"Not authorized, please send a valid auth token" in response.data
    token = __create_user(client)['access_token']
    response = client.get("/api/v1/bonds",
                          json=bond,
                          headers={"Authorization": "WrongAuthToken"})
    assert response.status_code == 401
    assert b"Could not validate credentials" in response.data
Ejemplo n.º 6
0
def test_collection_metrics_equal_probe_collection_metrics():
    update_base_metrics()
    response1 = client.get(f'/collection/{TEST_COLLECTION}/metrics')
    print(f'Response collection metrics text:\n{response1.text}')
    assert response1.status_code == 200
    response2 = client.get(
        f'/probe?module=collection&target={TEST_COLLECTION}')
    assert response2.status_code == 200
    assert response2.text == response1.text
    check_collection_response(response1)
Ejemplo n.º 7
0
def test_goods_get(token):
    response = client.post(
        "/warehouses",
        json={"address": "somemagicaddress"},
        headers={"Authorization": token},
    )
    assert response.status_code == 200

    names_and_codes = ["a", "b", "c"]
    for nc in names_and_codes:
        good_data = {
            "name": nc,
            "code": nc,
            "warehouse_id": response.json()["id"],
        }
        response_ = client.post(
            "/goods",
            json=good_data,
            headers={"Authorization": token},
        )
        assert response_.status_code == 200

    query = {"page": len(names_and_codes) - 1, "per_page": 1}
    response = client.get("/goods",
                          params=query,
                          headers={"Authorization": token})
    query["total_pages"] = len(names_and_codes)

    assert len(response.json()["data"]) == query["per_page"]
    assert response.json()["pagination"] == query
Ejemplo n.º 8
0
def test_empty_db():
    assert get('counters') == {
        'artists': 0,
        'albums': 0,
        'tracks': 0,
        'plays': 0
    }
Ejemplo n.º 9
0
def test_counters_with_data():
    assert get('counters') == {
        'artists': 1,
        'albums': 1,
        'tracks': 1,
        'plays': 1
    }
Ejemplo n.º 10
0
    def test_users_get(self, client):
        token = create_token()
        res = client.get('/api/users', content_type='application/json')

        if res.status_code != 200:
            raise ValueError(
                'The res.status_code must be 200, please check your code!')
    def testGetAll(self, client):
        """get all users data from users table"""

        token = createTokenAdmin()
        res = client.get('/v1/users/all',
                         headers={'Authorization': 'Bearer ' + token})
        assert res.status_code == 200
Ejemplo n.º 12
0
def test_toc_import(client):
    r = client.post('/v1/toc', data={'file': 'data/toc_100.enex'})
    assert int(r.get_json()['added']) == 100

    entry = client.get('/v1/toc').get_json()[1]
    assert entry['guid'] == '2df0f7b4-bec0-4005-a5ec-ebc3633ac303'
    assert entry['title'] == 'Kubernetes ConfigMaps and Secrets'
    def testGetOneByAdmin(self, client):
        """test get a specific user data using admin token"""

        token = createTokenAdmin()
        res = client.get('/v1/users/admin/2',
                         headers={'Authorization': 'Bearer ' + token})
        assert res.status_code == 200
Ejemplo n.º 14
0
 def test_user_get_confirmation_valid(self, client):
     token = create_token()
     res = client.get('/api/users/preferences/confirmations/1',
                     headers={'Authorization':'Bearer ' + token},
                     content_type='application/json')
     if res.status_code != 200:
         raise ValueError('The res.status_code must be 200, please check your code')
Ejemplo n.º 15
0
 def testHistoryGetByUser(self, client):
     """test get all data from reward history by user"""
     token = createTokenUser()
     res = client.get('/v1/reward_history/user',
                      headers={'Authorization': "Bearer " + token},
                      content_type='application/json')
     assert res.status_code == 200
Ejemplo n.º 16
0
def test_role_metrics_from_cache():
    update_base_metrics()
    # Test JSON from cache. Cached JSON has 'null' for some fields
    response = client.get(f'/test_role/{TEST_ROLE}/metrics')
    print(f'Response role metrics text:\n{response.text}')
    assert response.status_code == 200
    check_role_response(response)
Ejemplo n.º 17
0
def test_add_container(authorization_header,
                       form_data: dict = None,
                       user_id: int = None,
                       file: bytes = None) -> dict:
    if not form_data:
        form_data = {
            "user_id": user_id,
            "name": 'Default Container',
            "description": 'A Default Container',
            "filename": 'Dockerfile',
            "is_input_container": False,
            "is_output_container": False,
            "is_shared": False
        }

    if not user_id:
        me = client.get('/user/me', headers=authorization_header)
        assert me.status_code == 200
        form_data['user_id'] = me.json()['id']

    form_data['file'] = file if file else (io.BytesIO(b"test bytes"),
                                           'test.jpg')
    response = client.post('/container/',
                           data=form_data,
                           headers=authorization_header)

    assert response.status_code == 200
    return response.json()
Ejemplo n.º 18
0
def test_collection_metrics():
    update_base_metrics()
    response = client.get(f'/collection/{TEST_COLLECTION}/metrics')
    print(f'Response collection metrics text:\n{response.text}')
    assert response.status_code == 200
    check_collection_response(response)
    print(f'Response collection metrics text:\n{response.text}')
Ejemplo n.º 19
0
def test_collection_metrics_from_cache():
    update_base_metrics()
    # Test JSON from cache. Cached JSON has 'null' for some fields
    response = client.get(f'/test_collection/{TEST_COLLECTION}/metrics')
    print(f'Response collection metrics text:\n{response.text}')
    assert response.status_code == 200
    check_collection_response(response)
Ejemplo n.º 20
0
    def testGetAllRewards(self, client):
        """test get all rewards data from rewards table using valid token"""
        token = createTokenAdmin()
        res = client.get('/v1/rewards',
                         headers={'Authorization': 'Bearer ' + token})

        res_json = json.loads(res.data)
        assert res.status_code == 200
Ejemplo n.º 21
0
def test_get_project(setup_db):
    response = client.get("/projects/1")

    assert response.status_code == 200
    assert response.json() == {
        "id": 1,
        "name": "TEST_PROJECT1",
    }
    def testGetAllByUser(self, client):
        """Test get all users data from users table using user token
        Only admin can see data from all users, hence request will get 403 respond"""

        token = createTokenUser()
        res = client.get('/v1/users/all',
                         headers={'Authorization': 'Bearer ' + token})
        assert res.status_code == 403
    def testTrashCategoriesGetByUser(self, client):
        """Test getting all data from trash category table using token from an user account"""

        token = createTokenUser()
        res = client.get('/v1/trash_category',
                         headers={'Authorization': "Bearer " + token},
                         content_type='application/json')
        assert res.status_code == 200
    def testUserOrderGet(self, client):
        """test get all order data for corresponding user from orders table"""

        token = createTokenUser()
        res = client.get(
            'v1/orders/user', headers={'Authorization': "Bearer " + token}, content_type='application/json')

        assert res.status_code == 200
Ejemplo n.º 25
0
 def test_invitations_get_none(self, client):
     token = create_token2()
     res = client.get('/api/invitations',
                     headers={'Authorization':'Bearer ' + token},
                     content_type='application/json')
     res_json = json.loads(res.data)
     if res.status_code != 200:
         raise ValueError('The res.status_code must be 200, please check your code')
Ejemplo n.º 26
0
def test_get_settings():
    with database_mock() as db:
        db: StandardDatabase
        insert_mocks(db, "users")
        insert_mocks(db, "settings")
        with authed_request(client, "alice", ALICE_PASSWORD) as params:
            result = client.get("/settings", **params).json()
            assert result == json.loads(mocks.settings.alice.json(by_alias=True))
    def testGetOneUserNotFound(self, client):
        """Test get a specific user data using another user's token.
        User with id 100 has not been created, hence will get a 404(Not Found) error"""

        token = createTokenUser()
        res = client.get('/v1/users/100',
                         headers={'Authorization': 'Bearer ' + token})
        assert res.status_code == 404
    def testOrderGet(self, client):
        """test get all order data from orders table"""

        token = createTokenAdmin()

        res = client.get(
            '/v1/orders', headers={'Authorization': "Bearer " + token}, content_type='application/json')
        assert res.status_code == 200
Ejemplo n.º 29
0
    def testGetUserInformation(self, client):
        """test get user's jwt claims"""
        token = createTokenUser()
        res = client.get('/v1/auth',
                         headers={'Authorization': 'Bearer ' + token})

        res_json = json.loads(res.data)
        assert res.status_code == 200
    def testTrashGet(self, client):
        """Test getting all data from trashes table using valid token"""

        token = createTokenAdmin()
        res = client.get('/v1/trash',
                         headers={'Authorization': "Bearer " + token},
                         content_type='application/json')
        assert res.status_code == 200
Ejemplo n.º 31
0
def test_get_urls():
    rules = [
        ('/', 200),
        ('/all/', 200),
        ('/all/1/', 200),
        ('/xmlrpc/', 200),
        ('/json/', 200),
        ('/about/', 200),
        ('/help/', 200),
        ('/help/advanced/', 200),
        ('/help/api/', 200),
        ('/help/integration/', 200),
        ('/help/pasting/', 200),
        ('/language/de/', 302),
        ('/language/en/', 302),
        ]
    for rule, code in rules:
        resp = client.get(rule)
        assert code == resp.status_code