Esempio n. 1
0
class VersionsControllerTest(trove_testtools.TestCase):

    def setUp(self):
        super(VersionsControllerTest, self).setUp()
        self.controller = VersionsController()
        self.assertIsNotNone(self.controller,
                             "VersionsController instance was None")

    def test_index_json(self):
        request = Mock()
        result = self.controller.index(request)
        self.assertIsNotNone(result,
                             'Result was None')
        result._data = Mock()
        result._data.data_for_json = \
            lambda: {'status': 'CURRENT',
                     'updated': '2012-08-01T00:00:00Z',
                     'id': 'v1.0',
                     'links': [{'href': 'http://localhost/v1.0/',
                                'rel': 'self'}]}

        # can be anything but xml
        json_data = result.data("application/json")

        self.assertIsNotNone(json_data,
                             'Result json_data was None')
        self.assertEqual('v1.0', json_data['id'],
                         'Version id is incorrect')
        self.assertEqual('CURRENT', json_data['status'],
                         'Version status is incorrect')
        self.assertEqual('2012-08-01T00:00:00Z', json_data['updated'],
                         'Version updated value is incorrect')

    def test_show_json(self):
        request = Mock()
        request.url_version = '1.0'
        result = self.controller.show(request)
        self.assertIsNotNone(result,
                             'Result was None')
        json_data = result.data("application/json")
        self.assertIsNotNone(json_data, "JSON data was None")

        version = json_data.get('version', None)
        self.assertIsNotNone(version, "Version was None")

        self.assertEqual('CURRENT', version['status'],
                         "Version status was not 'CURRENT'")
        self.assertEqual('2012-08-01T00:00:00Z', version['updated'],
                         "Version updated was not '2012-08-01T00:00:00Z'")
        self.assertEqual('v1.0', version['id'], "Version id was not 'v1.0'")
Esempio n. 2
0
class VersionsControllerTest(testtools.TestCase):
    def setUp(self):
        super(VersionsControllerTest, self).setUp()
        self.controller = VersionsController()
        self.assertIsNotNone(self.controller,
                             "VersionsController instance was None")

    def test_index_json(self):
        request = Mock()
        result = self.controller.index(request)
        self.assertIsNotNone(result, 'Result was None')
        result._data = Mock()
        result._data.data_for_json = \
            lambda: {'status': 'CURRENT',
                     'updated': '2012-08-01T00:00:00Z',
                     'id': 'v1.0',
                     'links': [{'href': 'http://localhost/v1.0/',
                                'rel': 'self'}]}

        # can be anything but xml
        json_data = result.data("application/json")

        self.assertIsNotNone(json_data, 'Result json_data was None')
        self.assertEqual('v1.0', json_data['id'], 'Version id is incorrect')
        self.assertEqual('CURRENT', json_data['status'],
                         'Version status is incorrect')
        self.assertEqual('2012-08-01T00:00:00Z', json_data['updated'],
                         'Version updated value is incorrect')

    def test_show_json(self):
        request = Mock()
        request.url_version = '1.0'
        result = self.controller.show(request)
        self.assertIsNotNone(result, 'Result was None')
        json_data = result.data("application/json")
        self.assertIsNotNone(json_data, "JSON data was None")

        version = json_data.get('version', None)
        self.assertIsNotNone(version, "Version was None")

        self.assertEqual('CURRENT', version['status'],
                         "Version status was not 'CURRENT'")
        self.assertEqual('2012-08-01T00:00:00Z', version['updated'],
                         "Version updated was not '2012-08-01T00:00:00Z'")
        self.assertEqual('v1.0', version['id'], "Version id was not 'v1.0'")
Esempio n. 3
0
class VersionsControllerTest(trove_testtools.TestCase):
    def setUp(self):
        super(VersionsControllerTest, self).setUp()
        self.controller = VersionsController()
        self.assertIsNotNone(self.controller,
                             "VersionsController instance was None")

    def tearDown(self):
        super(VersionsControllerTest, self).tearDown()
        cfg.CONF.clear_override('public_endpoint')

    def test_index_json(self):
        request = Mock()
        result = self.controller.index(request)
        self.assertIsNotNone(result, 'Result was None')
        result._data = Mock()
        result._data.data_for_json = \
            lambda: {'status': 'CURRENT',
                     'updated': '2012-08-01T00:00:00Z',
                     'id': 'v1.0',
                     'links': [{'href': 'http://localhost/v1.0/',
                                'rel': 'self'}]}

        # can be anything but xml
        json_data = result.data("application/json")

        self.assertIsNotNone(json_data, 'Result json_data was None')
        self.assertEqual('v1.0', json_data['id'], 'Version id is incorrect')
        self.assertEqual('CURRENT', json_data['status'],
                         'Version status is incorrect')
        self.assertEqual('2012-08-01T00:00:00Z', json_data['updated'],
                         'Version updated value is incorrect')

    def test_index_json_with_public_endpoint(self):
        cfg.CONF.set_override('public_endpoint', "https://example.com:8779")
        req = webob.Request.blank('/')
        resp = self.controller.index(req)
        result = resp.data('application/json')['versions']
        expected = [{
            'status':
            'CURRENT',
            'updated':
            '2012-08-01T00:00:00Z',
            'id':
            'v1.0',
            'links': [{
                'href': 'https://example.com:8779/v1.0/',
                'rel': 'self'
            }]
        }]
        self.assertEqual(expected, result)

    def test_show_json(self):
        request = Mock()
        request.url_version = '1.0'
        result = self.controller.show(request)
        self.assertIsNotNone(result, 'Result was None')
        json_data = result.data("application/json")
        self.assertIsNotNone(json_data, "JSON data was None")

        version = json_data.get('version', None)
        self.assertIsNotNone(version, "Version was None")

        self.assertEqual('CURRENT', version['status'],
                         "Version status was not 'CURRENT'")
        self.assertEqual('2012-08-01T00:00:00Z', version['updated'],
                         "Version updated was not '2012-08-01T00:00:00Z'")
        self.assertEqual('v1.0', version['id'], "Version id was not 'v1.0'")

    def test_show_json_with_public_endpoint(self):
        cfg.CONF.set_override('public_endpoint', "https://example.com:8779")
        req = webob.Request.blank('/')
        req.url_version = '1.0'
        resp = self.controller.show(req)
        result = resp.data('application/json')['version']
        expected = {
            'status': 'CURRENT',
            'updated': '2012-08-01T00:00:00Z',
            'id': 'v1.0',
            'links': [{
                'href': 'https://example.com:8779/',
                'rel': 'self'
            }]
        }
        self.assertEqual(expected, result)
class VersionsControllerTest(testtools.TestCase):

    def setUp(self):
        super(VersionsControllerTest, self).setUp()
        self.controller = VersionsController()
        self.assertIsNotNone(self.controller,
                             "VersionsController instance was None")

    def test_index_json(self):
        request = Mock()
        result = self.controller.index(request)
        self.assertIsNotNone(result,
                             'Result was None')
        result._data = Mock()
        result._data.data_for_json = \
            lambda: {'status': 'CURRENT',
                     'updated': '2012-08-01T00:00:00Z',
                     'id': 'v1.0',
                     'links': [{'href': 'http://localhost/v1.0/',
                                'rel': 'self'}]}

        # can be anything but xml
        json_data = result.data("application/json")

        self.assertIsNotNone(json_data,
                             'Result json_data was None')
        self.assertEqual('v1.0', json_data['id'],
                         'Version id is incorrect')
        self.assertEqual('CURRENT', json_data['status'],
                         'Version status is incorrect')
        self.assertEqual('2012-08-01T00:00:00Z', json_data['updated'],
                         'Version updated value is incorrect')

    def test_index_xml(self):
        request = Mock()
        result = self.controller.index(request)
        self.assertIsNotNone(result, 'Result was None')

        id = VERSIONS['1.0']['id']
        status = VERSIONS['1.0']['status']
        base_url = BASE_URL
        updated = VERSIONS['1.0']['updated']
        version = Version(id, status, base_url, updated)

        result._data = Mock()
        result._data.data_for_xml = lambda: {'versions': [version]}

        xml_data = result.data("application/xml")
        self.assertIsNotNone(xml_data, 'Result xml_data was None')

        versions = xml_data['versions']
        self.assertIsNotNone(versions, "Versions was None")
        self.assertTrue(len(versions) == 1, "Versions length was != 1")
        v = versions[0]

        self.assertEqual('v1.0', v.id,
                         'Version id is incorrect')
        self.assertEqual('CURRENT', v.status,
                         'Version status is incorrect')
        self.assertEqual('2012-08-01T00:00:00Z', v.updated,
                         'Version updated value is incorrect')

    def test_show_json(self):
        request = Mock()
        request.url_version = '1.0'
        result = self.controller.show(request)
        self.assertIsNotNone(result,
                             'Result was None')
        json_data = result.data("application/json")
        self.assertIsNotNone(json_data, "JSON data was None")

        version = json_data.get('version', None)
        self.assertIsNotNone(version, "Version was None")

        self.assertEqual('CURRENT', version['status'],
                         "Version status was not 'CURRENT'")
        self.assertEqual('2012-08-01T00:00:00Z', version['updated'],
                         "Version updated was not '2012-08-01T00:00:00Z'")
        self.assertEqual('v1.0', version['id'], "Version id was not 'v1.0'")

    def test_show_xml(self):
        request = Mock()
        request.url_version = '1.0'
        result = self.controller.show(request)
        self.assertIsNotNone(result,
                             'Result was None')
        xml_data = result.data("application/xml")
        self.assertIsNotNone(xml_data, "XML data was None")

        version = xml_data.get('version', None)
        self.assertIsNotNone(version, "Version was None")
        self.assertEqual('CURRENT', version.status,
                         "Version status was not 'CURRENT'")
        self.assertEqual('2012-08-01T00:00:00Z', version.updated,
                         "Version updated was not '2012-08-01T00:00:00Z'")
        self.assertEqual('v1.0', version.id, "Version id was not 'v1.0'")
Esempio n. 5
0
class VersionsControllerTest(testtools.TestCase):
    def setUp(self):
        super(VersionsControllerTest, self).setUp()
        self.controller = VersionsController()
        self.assertIsNotNone(self.controller,
                             "VersionsController instance was None")

    def test_index_json(self):
        request = Mock()
        result = self.controller.index(request)
        self.assertIsNotNone(result, 'Result was None')
        result._data = Mock()
        result._data.data_for_json = \
            lambda: {'status': 'CURRENT',
                     'updated': '2012-08-01T00:00:00Z',
                     'id': 'v1.0',
                     'links': [{'href': 'http://localhost/v1.0/',
                                'rel': 'self'}]}

        # can be anything but xml
        json_data = result.data("application/json")

        self.assertIsNotNone(json_data, 'Result json_data was None')
        self.assertEqual('v1.0', json_data['id'], 'Version id is incorrect')
        self.assertEqual('CURRENT', json_data['status'],
                         'Version status is incorrect')
        self.assertEqual('2012-08-01T00:00:00Z', json_data['updated'],
                         'Version updated value is incorrect')

    def test_index_xml(self):
        request = Mock()
        result = self.controller.index(request)
        self.assertIsNotNone(result, 'Result was None')

        id = VERSIONS['1.0']['id']
        status = VERSIONS['1.0']['status']
        base_url = BASE_URL
        updated = VERSIONS['1.0']['updated']
        version = Version(id, status, base_url, updated)

        result._data = Mock()
        result._data.data_for_xml = lambda: {'versions': [version]}

        xml_data = result.data("application/xml")
        self.assertIsNotNone(xml_data, 'Result xml_data was None')

        versions = xml_data['versions']
        self.assertIsNotNone(versions, "Versions was None")
        self.assertTrue(len(versions) == 1, "Versions length was != 1")
        v = versions[0]

        self.assertEqual('v1.0', v.id, 'Version id is incorrect')
        self.assertEqual('CURRENT', v.status, 'Version status is incorrect')
        self.assertEqual('2012-08-01T00:00:00Z', v.updated,
                         'Version updated value is incorrect')

    def test_show_json(self):
        request = Mock()
        request.url_version = '1.0'
        result = self.controller.show(request)
        self.assertIsNotNone(result, 'Result was None')
        json_data = result.data("application/json")
        self.assertIsNotNone(json_data, "JSON data was None")

        version = json_data.get('version', None)
        self.assertIsNotNone(version, "Version was None")

        self.assertEqual('CURRENT', version['status'],
                         "Version status was not 'CURRENT'")
        self.assertEqual('2012-08-01T00:00:00Z', version['updated'],
                         "Version updated was not '2012-08-01T00:00:00Z'")
        self.assertEqual('v1.0', version['id'], "Version id was not 'v1.0'")

    def test_show_xml(self):
        request = Mock()
        request.url_version = '1.0'
        result = self.controller.show(request)
        self.assertIsNotNone(result, 'Result was None')
        xml_data = result.data("application/xml")
        self.assertIsNotNone(xml_data, "XML data was None")

        version = xml_data.get('version', None)
        self.assertIsNotNone(version, "Version was None")
        self.assertEqual('CURRENT', version.status,
                         "Version status was not 'CURRENT'")
        self.assertEqual('2012-08-01T00:00:00Z', version.updated,
                         "Version updated was not '2012-08-01T00:00:00Z'")
        self.assertEqual('v1.0', version.id, "Version id was not 'v1.0'")