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)
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))
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))
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', ])
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)
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', ])
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)
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)
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)
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)
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)
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)
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), }])
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), }])