Пример #1
0
def test_build_tree_cache_error_throws_exception(mock_cache_error, mocker):
    with pytest.raises(Exception):
        cache = InMemoryCache()
        tree_builder = NPMDependenciesTree(NPMRegistryClient('mock_address'),
                                           cache, HtmlTreeRenderer())
        response = tree_builder.build_dependencies_tree(
            'some_package', 'latest')
Пример #2
0
def test_build_tree_server_error_throws_exception(mock_server_error, mocker):
    with pytest.raises(Exception):
        client = NPMRegistryClient('mock_address')
        mocker.spy(client, 'get_package_infromation')
        tree_builder = NPMDependenciesTree(client, InMemoryCache(),
                                           HtmlTreeRenderer())
        response = tree_builder.build_dependencies_tree(
            'some_package', 'latest')
Пример #3
0
def test_build_tree_no_sub_dependencies_success(mock_with_no_dependencies,
                                                mocker):
    cache = InMemoryCache()
    mocker.spy(cache, 'add_package')
    tree_builder = NPMDependenciesTree(NPMRegistryClient('mock_address'),
                                       cache, HtmlTreeRenderer())
    response = tree_builder.build_dependencies_tree('statuses', 'latest')
    assert cache.add_package.call_count == 1
Пример #4
0
def test_build_tree_with_circular_dependencies(
        mock_with_with_circular_dependencies, mocker):
    cache = InMemoryCache()
    mocker.spy(cache, 'add_package')
    tree_builder = NPMDependenciesTree(NPMRegistryClient('mock_address'),
                                       cache, HtmlTreeRenderer())
    response = tree_builder.build_dependencies_tree('express', 'latest')
    assert response == True
    response = tree_builder.get_dependencies_tree('express', 'latest')
    assert response is not None
Пример #5
0
def test_update_latest_version_tree(mock_with_with_dependencies, mocker):
    client = NPMRegistryClient('mock_address')
    cache = InMemoryCache()
    cache.update_latest_version('express', '4.17.0')
    mocker.spy(cache, 'update_latest_version')
    tree_builder = NPMDependenciesTree(client, cache, HtmlTreeRenderer())
    mocker.spy(tree_builder, 'build_dependencies_tree')
    response = tree_builder.update_latest_versions()
    cache.update_latest_version.assert_called_with('express', '4.17.1')
    tree_builder.build_dependencies_tree.assert_called_with(
        'express', 'latest')
Пример #6
0
def test_build_tree_package_deprecated_exception(mock_package_not_found,
                                                 mocker):
    with pytest.raises(DependencyException) as exception:
        client = NPMRegistryClient('mock_address')
        mocker.spy(client, 'get_package_infromation')
        tree_builder = NPMDependenciesTree(client, InMemoryCache(),
                                           HtmlTreeRenderer())
        response = tree_builder.build_dependencies_tree(
            'deprecated_package', 'latest')
        assert client.get_package_infromation.call_count == 1
        assert exception.message == 'deprecated'
Пример #7
0
def update():
    try:
        tree.update_latest_versions()
        return json.dumps({'success':True,'message':'all latest versions were updated'}), 200, {'ContentType':'application/json'} 
    except DependencyException as error:
        return error.message,404
    except Exception as error:
        return error.message,503

@app.route('/packages',methods=['DELETE'])
def clear():
    try:
        tree.clear_dependencies_data()
        return json.dumps({'success':True,'message':'cahce was cleared'}), 200, {'ContentType':'application/json'} 
    except DependencyException as error:
        return error.message,404
    except Exception as error:
        return error.message,503

@app.route('/',methods=['GET'])
def deafult():
    try:
        return html.unescape('<b>Welcome - please use packages route for example <a href="http://nirarmon33.pythonanywhere.com/packages?package=express&version=latest">http://nirarmon33.pythonanywhere.com/packages?package=express&version=latest</a></b>')
    except DependencyException as error:
        return error.message,404
    except Exception as error:
        return 503

if __name__ == '__main__':
    tree = NPMDependenciesTree(NPMRegistryClient('http://registry.npmjs.org/'),InMemoryCache(),HtmlTreeRenderer())
    app.run()