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_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_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([])
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), }])
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 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)