Example #1
0
def test_new_curd(context):
    "It should be possible to create new curds based on requirements files"

    # Given that I have a file that contains a list of dependencies of a fake
    # project
    manager = CurdManager(FIXTURE('project1', '.curds'),
                          {'index-url': 'http://localhost:8000/simple'})
    requirements = (
        FIXTURE('project1', 'requirements.txt'),
        FIXTURE('project1', 'development.txt'),
    )
    uid = manager.add(requirements)

    # When I create the new curd
    curd = manager.new(uid)

    # Then I see the curd was downloaded correctly created
    os.path.isdir(FIXTURE('project1', '.curds')).should.be.true
    os.path.isdir(FIXTURE('project1', '.curds', uid)).should.be.true

    (os.path.isfile(
        FIXTURE('project1', '.curds', uid,
                'gherkin-0.1.0-py27-none-any.whl')).should.be.true)
    (os.path.isfile(
        FIXTURE('project1', '.curds', uid,
                'forbiddenfruit-0.1.0-py27-none-any.whl')).should.be.true)
Example #2
0
def test_has_curd(context):
    "It should be possible to find curds saved locally"

    # Given that I have a curd hash, a curd manager linked to a curdcache
    curd_id = '682f87d84c80d0a85c9179de681b3474906113b3'
    path = FIXTURE('project1', '.curds')
    settings = {'index-url': 'http://localhost:8000/simple'}
    manager = CurdManager(path, settings)
    curd = manager.new(
        manager.add([
            FIXTURE('project1', 'requirements.txt'),
            FIXTURE('project1', 'development.txt'),
        ]))

    # When I retrieve the unknown curd
    curd = manager.get(curd.uid)

    # Then I see that my curd was properly retrieved
    curd.should.be.a(Curd)
    curd.uid.should.equal(curd_id)
    curd.path.should.equal(os.path.join(path, curd_id))

    # mocking the created prop
    with patch('os.stat') as stat:
        stat.return_value.st_ctime = 1376943600
        curd.created.should.equal(datetime(2013, 8, 19, 16, 20))
Example #3
0
def test_retrieve_curd(context):
    "It should be possible to download tar packages with curds"

    manager = CurdManager(FIXTURE('project1', '.curds'),
                          {'index-url': 'http://localhost:8000/simple'})
    uid = manager.add([FIXTURE('project1', 'requirements.txt')])

    # Given that I have an http client that exposes the server API that
    # currently contains a curd
    curd = manager.new(uid)
    app = Server(manager, __name__)
    client = app.test_client()

    # When I try to retrieve the curd page
    with app.test_request_context():
        result = client.get(url_for('curd', uid=curd.uid))

    # Then I see I received a tar package containing the wheel of the package
    # described inside of the `requirements` file
    result.status_code.should.equal(200)
    result.mimetype.should.equal('application/tar')

    # And I see that the tar file received contains the right package list
    tar = tarfile.open(name='{}.tar'.format(uid),
                       mode='r',
                       fileobj=StringIO(result.data))
    [info.name for info in tar].should.equal([
        'gherkin-0.1.0-py27-none-any.whl',
    ])
Example #4
0
def test_no_curd(context):
    "CurdManager.get() should return None when it can't find a specific curd"

    # Given that I have an instance of a curd manager
    curd_manager = CurdManager(FIXTURE('project1', '.curds'))

    # When I try to get a curd I know that does not exist
    curd = curd_manager.get('I-know-you-dont-exist')

    # Then I see it returns None
    curd.should.be.none
Example #5
0
def test_list_curds(context):
    "It should be possible to list available curds in a manager"

    # Given that I have a newly created curd
    manager = CurdManager(FIXTURE('project1', '.curds'),
                          {'index-url': 'http://localhost:8000/simple'})
    curd1 = manager.new(manager.add([FIXTURE('project1', 'requirements.txt')]))

    # When I list all the curds
    curds = manager.available()

    # Then I see that the curd1 that I just created is inside of the list
    curds.should.contain(curd1)
Example #6
0
def test_curd_manager_add_files():
    "It should be possible to add new combinations of files to be hashed"

    # Given that I have a manager
    manager = CurdManager('/path/to/the/curd/container')

    # When I add new files
    uid = manager.add(['f1.txt', 'f2.txt'])

    # Then I see the internal mapping was updated and the return value is just
    # the result of the hash func
    uid.should.equal('f1.txt,f2.txt')
    manager.mapping.should.equal({
        'f1.txt,f2.txt': ['f1.txt', 'f2.txt'],
    })
Example #7
0
def test_retrieve_remote_curd(context):
    "It should be possible to retrieve remote curds and install them locally"

    # Given that I have curdle manager (with a curd) configured with a remote
    # cache url
    manager = CurdManager(
        FIXTURE('project1', '.curds'),
        {'cache-url': 'http://localhost:8001'})  # where does this addr come
    # from? See `setup_server()`

    # When I retrieve a curd
    with context.patch:  # Both context.{patch,uid} come from
        curd = manager.retrieve(context.uid)  # from `setup_server()`

    # Then I see the curd was correctly retrieved
    os.path.isdir(curd.path).should.be.true
    (os.path.isfile(os.path.join(
        curd.path, 'gherkin-0.1.0-py27-none-any.whl')).should.be.true)
Example #8
0
def test_list_available_curds(context):
    "It should be possible to list available curds"

    manager = CurdManager(FIXTURE('project1', '.curds'),
                          {'index-url': 'http://localhost:8000/simple'})
    uid = manager.add([FIXTURE('project1', 'requirements.txt')])

    # Given that I have a manager with a curd and an http client
    client = Server(manager, __name__).test_client()
    curd = manager.new(uid)

    # When I try to list all the available curds
    result = client.get('/')

    # Then I see that the newly created curd is available in the response list
    loads(result.data).should.equal([{
        'uid': uid,
        'url': '/{}'.format(uid),
    }])
Example #9
0
def test_find_cached_curds(context):
    "It should be possible to find cached curds"

    # Given that I have a newly created curd
    manager = CurdManager(FIXTURE('project1', '.curds'),
                          {'index-url': 'http://localhost:8000/simple'})
    uid = manager.add([FIXTURE('project1', 'requirements.txt')])

    curd1 = manager.new(uid)

    # When I try to get the same curd instead of creating it
    with patch('curdling.old.pip') as pip:
        curd2 = manager.new(uid)

        # Then I see that the pip command was not called in the second time
        pip.wheel.called.should.be.false

    # Then I see curd1 and curd2 are just the same object
    curd1.should_not.be.none
    curd1.should.equal(curd2)
Example #10
0
def test_hit_the_first_page(context):
    "It should be possible hit the first page empty"

    # Given that I have the test client
    manager = CurdManager(FIXTURE('project1', '.curds'))
    client = Server(manager, __name__).test_client()

    # When I hit the main page of the api
    result = client.get('/')

    # Then I see it returned nothing, since we have no curds yet
    result.status_code.should.equal(200)
    loads(result.data).should.equal([])
Example #11
0
def setup_server(context):
    # Setting up a manager that uses our dummy pypi server running on the port
    # 8000. This will create a curd to be served in the next step by our
    # server.
    manager = CurdManager(FIXTURE('project2', '.curds'),
                          {'index-url': 'http://localhost:8000/simple'})
    context.uid = manager.add([FIXTURE('project2', 'requirements.txt')])
    manager.new(context.uid)

    # Retrieving the response of the server without spinning the whole http
    # stuff up. I crave a usable asynchronous API for python!
    server = Server(manager, __name__)
    client = server.test_client()

    # Creating a patched urlopen to replace the original one by this fake one
    # that contains the output read using the test client
    url = '/{}'.format(context.uid)
    response = Mock()
    response.getcode.return_value = 200
    response.bosta = 200
    response.read.side_effect = lambda: client.get(url).data

    context.patch = patch('curdling.old.urllib2.urlopen', lambda p: response)