def test_releases_get_bad_credentials(self): """ Test getting improperly formatted credentials from header """ releases_view = ReleasesView() encoded_creds = base64.encodestring('blah') headers = {'HTTP_AUTHORIZATION': encoded_creds} creds = releases_view._get_credentials(headers) self.assertEqual(creds, None)
def test_releases_get_module_name(self): """ Test getting module name from GET params """ releases_view = ReleasesView() module = 'test-module' formatted_module_name = 'test/module' get_dict = {'module': module} module_name = releases_view._get_module_name(get_dict) self.assertEqual(formatted_module_name, module_name)
def test_releases_get_credentials(self): """ Test getting credentials from header """ releases_view = ReleasesView() real_creds = ('test', '123') encoded_creds = base64.encodestring('test:123') headers = {'HTTP_AUTHORIZATION': encoded_creds} creds = releases_view._get_credentials(headers) self.assertEqual(real_creds, creds)
def test_releases_get_parameters(self): """ Test getting request parameters from HTTP GET request """ releases_view = ReleasesView() module = 'test-module' path = '/test/' formatted_module_name = 'test/module' get_dict = {'module': module} parameters = releases_view._get_parameters(get_dict, path) self.assertEqual(formatted_module_name, parameters.get('module'))
def test_releases_bad_resource_type(self, mock_get_credentials, mock_get_parameters): """ Test that only consumer or repository resource type is allowed """ mock_get_parameters.return_value = {'module': 'fake-module'} mock_get_credentials.return_value = () mock_request = mock.MagicMock() releases_view = ReleasesView() response = releases_view.get(mock_request, resource_type='foo') self.assertEqual(response.status_code, 404)
def test_releases_missing_auth(self, mock_get_credentials, mock_get_parameters): """ Test that 401 is returned when basic auth is not used for pre 3.3 """ mock_get_parameters.return_value = {'module': 'fake-module'} mock_get_credentials.return_value = () mock_request = mock.MagicMock() releases_view = ReleasesView() response = releases_view.get(mock_request) self.assertEqual(response.status_code, 401)
def test_releases_missing_module(self, mock_get_credentials): """ Test that proper response is returned when module name is not specified """ mock_get_credentials.return_value = () rf = RequestFactory() mock_request = rf.get('/blah/') releases_view = ReleasesView() response = releases_view.get(mock_request, resource_type='repository', resource='repo-id') self.assertEqual(response.status_code, 400) self.assertEqual(response.content, 'Module name is missing.')
def test_releases_get_module_without_version(self, mock_get_credentials, mock_get_parameters, mock_view): """ Test getting a module without specifying a version """ mock_get_parameters.return_value = {'module': 'food/bar'} mock_get_credentials.return_value = ('consumer1', 'repo1') mock_request = mock.MagicMock() mock_view.return_value = self.FAKE_VIEW_DATA releases_view = ReleasesView() response = releases_view.get(mock_request) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, json.dumps(self.FAKE_VIEW_DATA))
from django.conf.urls import patterns, url from pulp_puppet.forge.views.releases import ReleasesView, ReleasesPost36View urlpatterns = patterns('', url(r'^pulp_puppet/forge/([^/]+)/([^/]+)/api/v1/releases.json', ReleasesView.as_view(), name='post_33_releases'), url(r'^api/v1/releases.json', ReleasesView.as_view(), name='pre_33_releases'), url(r'^v3/releases', ReleasesPost36View.as_view(), name='post_36_releases') )
from django.conf.urls import patterns, url from pulp_puppet.forge.views.releases import ReleasesView, ReleasesPost36View from pulp_puppet.forge.views.modules import ModulesView, ModulesPost36View from pulp_puppet.forge.views.files import FilesView, FilesPost36View from pulp.server.db import connection connection.initialize() urlpatterns = patterns('', url(r'^pulp_puppet/forge/([^/]+)/([^/]+)/api/v1/releases.json', ReleasesView.as_view(), name='post_33_releases'), url(r'^api/v1/releases.json', ReleasesView.as_view(), name='pre_33_releases'), url(r'^v3/releases', ReleasesPost36View.as_view(), name='post_36_releases'), url(r'^v3/modules', ModulesPost36View.as_view(), name='post_36_modules'), url(r'^v3/files', FilesPost36View.as_view(), name='post_36_files') )
from django.conf.urls import patterns, url from pulp_puppet.forge.views.releases import ReleasesView, ReleasesPost36View urlpatterns = patterns( '', url(r'^pulp_puppet/forge/([^/]+)/([^/]+)/api/v1/releases.json', ReleasesView.as_view(), name='post_33_releases'), url(r'^api/v1/releases.json', ReleasesView.as_view(), name='pre_33_releases'), url(r'^v3/releases', ReleasesPost36View.as_view(), name='post_36_releases'))