예제 #1
0
    def test_items_less_than_limit(self, href_link_mock):
        items = [{"uuid": "123"}]
        req = mock.MagicMock()
        params = mock.PropertyMock(return_value=dict(limit=10))
        type(req).params = params

        builder = common.ViewBuilder()
        results = builder._get_collection_links(req, items, "ignored", "uuid")

        self.assertFalse(href_link_mock.called)
        self.assertThat(results, matchers.HasLength(0))
예제 #2
0
    def test_items_equals_given_limit(self, href_link_mock):
        items = [{"uuid": "123"}]
        req = mock.MagicMock()
        params = mock.PropertyMock(return_value=dict(limit=1))
        type(req).params = params

        builder = common.ViewBuilder()
        results = builder._get_collection_links(req, items,
                                                mock.sentinel.coll_key, "uuid")

        href_link_mock.assert_called_once_with(req, "123",
                                               mock.sentinel.coll_key)
        self.assertThat(results, matchers.HasLength(1))
예제 #3
0
파일: test_common.py 프로젝트: anjoah/nova
    def test_update_link_prefix(self):
        vb = common.ViewBuilder()
        result = vb._update_link_prefix("http://192.168.0.243:24/",
                                        "http://127.0.0.1/compute")
        self.assertEqual("http://127.0.0.1/compute", result)

        result = vb._update_link_prefix("http://foo.x.com/v1",
                                        "http://new.prefix.com")
        self.assertEqual("http://new.prefix.com/v1", result)

        result = vb._update_link_prefix(
                "http://foo.x.com/v1",
                "http://new.prefix.com:20455/new_extra_prefix")
        self.assertEqual("http://new.prefix.com:20455/new_extra_prefix/v1",
                         result)
예제 #4
0
    def test_items_equals_default_limit_with_given(self, href_link_mock):
        items = [{"uuid": "123"}]
        req = mock.MagicMock()
        # Given limit is greater than default max, only return default max
        params = mock.PropertyMock(return_value=dict(limit=2))
        type(req).params = params
        self.flags(max_limit=1, group='api')

        builder = common.ViewBuilder()
        results = builder._get_collection_links(req, items,
                                                mock.sentinel.coll_key, "uuid")

        href_link_mock.assert_called_once_with(req, "123",
                                               mock.sentinel.coll_key)
        self.assertThat(results, matchers.HasLength(1))
예제 #5
0
 def setUp(self):
     super(ViewBuilderLinkTest, self).setUp()
     self.request = self.req("/%s" % self.project_id)
     self.vb = common.ViewBuilder()