예제 #1
0
def test_no_change():
    generalized_route = Route(FAKE_VIEW, FAKE_ROUTE_NAME, FAKE_SUB_ROUTES)
    specialized_route = generalized_route.create_specialization()

    eq_(FAKE_ROUTE_NAME, specialized_route.name)
    eq_(FAKE_VIEW, specialized_route.view)
    eq_(FAKE_SUB_ROUTES, tuple(specialized_route.sub_routes))
예제 #2
0
    def test_no_change(self):
        generalized_route = Route(FAKE_VIEW, FAKE_ROUTE_NAME)
        intermediate_route = generalized_route.create_specialization()
        specialized_route = intermediate_route.create_specialization()

        eq_(FAKE_ROUTE_NAME, specialized_route.name)
        eq_(FAKE_VIEW, specialized_route.view)
예제 #3
0
    def test_specialization_vs_non_specialization(self):
        generalized_route = Route(None, FAKE_ROUTE_NAME, FAKE_SUB_ROUTES)
        specialized_route = generalized_route.create_specialization()

        route = Route(None, FAKE_ROUTE_NAME, FAKE_SUB_ROUTES)

        assert_non_equivalent(specialized_route, route)
예제 #4
0
    def test_getting_additional_sub_route_by_name(self):
        sub_route = Route(FAKE_VIEW, FAKE_ROUTE_NAME)
        generalized_route = Route(None, None, [sub_route])
        specialized_route = generalized_route.create_specialization()

        retrieved_route = specialized_route.get_route_by_name(FAKE_ROUTE_NAME)
        eq_(sub_route, retrieved_route)
예제 #5
0
    def test_previously_unset(self):
        generalized_route = Route(None, FAKE_ROUTE_NAME)

        view = object()
        specialized_route = generalized_route.create_specialization(view=view)

        eq_(view, specialized_route.view)
예제 #6
0
    def test_existing_direct_sub_route(self):
        sub_route_name = 'sub_route_1'
        sub_route = Route(FAKE_VIEW, sub_route_name)
        route = Route(FAKE_VIEW, FAKE_ROUTE_NAME, [sub_route])

        retrieved_route = route.get_route_by_name(sub_route_name)
        eq_(sub_route, retrieved_route)
예제 #7
0
    def test_previously_set(self):
        generalized_route = Route(FAKE_VIEW, FAKE_ROUTE_NAME)

        overridden_view = object()
        specialized_route = \
            generalized_route.create_specialization(view=overridden_view)

        eq_(overridden_view, specialized_route.view)
예제 #8
0
    def test_getting_specialized_sub_route_by_name(self):
        generalized_route = Route(None, FAKE_ROUTE_NAME)
        specialized_route = generalized_route.create_specialization(
            specialized_sub_routes=[]
            )

        retrieved_route = specialized_route.get_route_by_name(FAKE_ROUTE_NAME)
        eq_(specialized_route, retrieved_route)
예제 #9
0
    def test_sub_route_specializing_current_route(self):
        generalized_route = Route(None, FAKE_ROUTE_NAME)

        sub_route = generalized_route.create_specialization()

        with assert_raises_substring(DuplicatedRouteError, FAKE_ROUTE_NAME):
            generalized_route.create_specialization(
                specialized_sub_routes=[sub_route],
                )
예제 #10
0
    def test_sub_route_collection_against_non_sub_route_collection(self):
        generalized_route = Route(
            FAKE_VIEW,
            FAKE_ROUTE_NAME,
            FAKE_SUB_ROUTES,
            )
        specialized_route = generalized_route.create_specialization()

        assert_non_equivalent(specialized_route.sub_routes, None)
예제 #11
0
    def test_non_existing_sub_route(self):
        sub_route = Route(FAKE_VIEW, 'sub_route_1')
        route = Route(FAKE_VIEW, FAKE_ROUTE_NAME, [sub_route])

        non_existing_route_name = 'non_existing'
        with assert_raises_substring(
            NonExistingRouteError,
            non_existing_route_name,
            ):
            route.get_route_by_name(non_existing_route_name)
예제 #12
0
def test_repr():
    generalized_route = Route(FAKE_VIEW, FAKE_ROUTE_NAME, FAKE_SUB_ROUTES)

    view = object()
    specialized_route = generalized_route.create_specialization(view)

    expected_repr = '<Specialization of {!r} with view {!r}>'.format(
        generalized_route,
        view,
        )
    eq_(expected_repr, repr(specialized_route))
예제 #13
0
    def test_additional_duplicated_sub_route(self):
        sub_route_1 = Route(None, FAKE_ROUTE_NAME)
        generalized_route = Route(FAKE_VIEW, None, [sub_route_1])

        intermediate_route = generalized_route.create_specialization()

        sub_route_2 = Route(None, FAKE_ROUTE_NAME)
        with assert_raises_substring(DuplicatedRouteError, FAKE_ROUTE_NAME):
            intermediate_route.create_specialization(
                additional_sub_routes=[sub_route_2],
                )
예제 #14
0
    def test_additional_sub_route(self):
        generalized_route = Route(FAKE_VIEW, FAKE_ROUTE_NAME)

        intermediate_route = generalized_route.create_specialization()

        sub_route = Route(None, None)
        specialized_route = intermediate_route.create_specialization(
            additional_sub_routes=[sub_route],
            )

        eq_((sub_route,), tuple(specialized_route.sub_routes))
예제 #15
0
    def test_sibling_specializations_with_same_attributes(self):
        generalized_route = Route(
            FAKE_VIEW,
            FAKE_ROUTE_NAME,
            FAKE_SUB_ROUTES,
            )

        specialized_route_1 = generalized_route.create_specialization()
        specialized_route_2 = generalized_route.create_specialization()

        assert_equivalent(specialized_route_1, specialized_route_2)
예제 #16
0
    def test_length_with_additional_sub_routes(self):
        generalized_route = \
            Route(FAKE_VIEW, FAKE_ROUTE_NAME, FAKE_SUB_ROUTES)

        additional_sub_routes = [Route(None, 'additional_sub_route')]
        specialized_route = generalized_route.create_specialization(
            additional_sub_routes=additional_sub_routes,
            )

        expected_length = len(FAKE_SUB_ROUTES) + len(additional_sub_routes)
        eq_(expected_length, len(specialized_route.sub_routes))
예제 #17
0
 def test_sub_route_duplicating_route_name(self):
     duplicated_route_name = 'route_name'
     generalized_route = Route(FAKE_VIEW, duplicated_route_name)
     sub_route = Route(None, duplicated_route_name)
     with assert_raises_substring(
         DuplicatedRouteError,
         duplicated_route_name,
         ):
         generalized_route.create_specialization(
             additional_sub_routes=[sub_route],
             )
예제 #18
0
    def test_sibling_specializations_with_different_attributes(self):
        generalized_route = Route(
            None,
            FAKE_ROUTE_NAME,
            FAKE_SUB_ROUTES,
            )

        specialized_route_1 = \
            generalized_route.create_specialization(FAKE_VIEW)
        specialized_route_2 = generalized_route.create_specialization()

        assert_non_equivalent(specialized_route_1, specialized_route_2)
예제 #19
0
    def test_specializing_sub_route(self):
        generalized_sub_route = Route(FAKE_VIEW, FAKE_ROUTE_NAME)
        generalized_route = Route(None, None, [generalized_sub_route])

        intermediate_route = generalized_route.create_specialization()

        specialized_sub_route = generalized_sub_route.create_specialization()
        specialized_route = intermediate_route.create_specialization(
            specialized_sub_routes=[specialized_sub_route],
            )

        eq_((specialized_sub_route,), tuple(specialized_route.sub_routes))
예제 #20
0
    def test_uniquely_named_sub_routes(self):
        generalized_route = Route(
            FAKE_VIEW,
            FAKE_ROUTE_NAME,
            FAKE_SUB_ROUTES,
            )
        additional_route = Route(FAKE_VIEW, 'new_name')
        specialized_route = generalized_route.create_specialization(
            additional_sub_routes=[additional_route],
            )

        specialized_route_sub_routes = FAKE_SUB_ROUTES + (additional_route,)

        eq_(specialized_route_sub_routes, tuple(specialized_route.sub_routes))
예제 #21
0
    def test_non_existing_named_sub_route(self):
        generalized_route = Route(None, None)

        non_existing_sub_route_name = 'non_existing_route'
        generalized_sub_route = Route(None, non_existing_sub_route_name)
        specialized_sub_route = generalized_sub_route.create_specialization()

        with assert_raises_substring(
            InvalidSpecializationError,
            non_existing_sub_route_name,
            ):
            generalized_route.create_specialization(
                specialized_sub_routes=[specialized_sub_route],
                )
예제 #22
0
    def test_sub_route_collection_against_different_sub_route_collection(self):
        generalized_route = Route(
            FAKE_VIEW,
            FAKE_ROUTE_NAME,
            FAKE_SUB_ROUTES,
            )
        specialized_route_1 = generalized_route.create_specialization()
        specialized_route_2 = generalized_route.create_specialization(
            additional_sub_routes=[Route(None, None)],
            )

        assert_non_equivalent(
            specialized_route_1.sub_routes,
            specialized_route_2.sub_routes,
            )
예제 #23
0
    def test_non_existing_unnamed_sub_route(self):
        unnamed_sub_route = Route(None, None)
        generalized_route = Route(None, None, [unnamed_sub_route])

        unnamed_generalized_sub_route = Route(FAKE_VIEW, None)
        unnamed_specialized_sub_route = \
            unnamed_generalized_sub_route.create_specialization()

        with assert_raises_substring(
            InvalidSpecializationError,
            repr(unnamed_generalized_sub_route),
            ):
            generalized_route.create_specialization(
                specialized_sub_routes=[unnamed_specialized_sub_route],
                )
예제 #24
0
    def test_specializations_from_equivalent_generalizations(self):
        generalized_route_1 = Route(
            None,
            FAKE_ROUTE_NAME,
            FAKE_SUB_ROUTES,
            )
        specialized_route_1 = generalized_route_1.create_specialization()

        generalized_route_2 = Route(
            None,
            FAKE_ROUTE_NAME,
            FAKE_SUB_ROUTES,
            )
        specialized_route_2 = generalized_route_2.create_specialization()

        assert_equivalent(specialized_route_1, specialized_route_2)
예제 #25
0
    def test_existing_unnamed_sub_routes(self):
        generalized_sub_route = Route(FAKE_VIEW, None)
        sub_route = Route(None, None)
        generalized_route = Route(
            None,
            FAKE_ROUTE_NAME,
            [generalized_sub_route, sub_route],
            )

        specialized_sub_route = generalized_sub_route.create_specialization()
        specialized_route = generalized_route.create_specialization(
            specialized_sub_routes=[specialized_sub_route],
            )

        # A second sub-route without name shouldn't override the first sub-route
        eq_((specialized_sub_route, sub_route), tuple(specialized_route.sub_routes))
예제 #26
0
    def test_sub_route_with_non_specialized_route(self):
        sub_route_name = 'sub_route_name'
        generalized_sub_route = Route(None, sub_route_name)
        generalized_route = Route(
            FAKE_VIEW,
            FAKE_ROUTE_NAME,
            [generalized_sub_route],
            )
        unspecialized_route = Route(None, sub_route_name)

        with assert_raises_substring(
            InvalidSpecializationError,
            sub_route_name,
            ):
            generalized_route.create_specialization(
                specialized_sub_routes=[unspecialized_route],
                )
예제 #27
0
    def test_existing_named_sub_routes(self):
        generalized_sub_route_name = 'sub_route_name'
        generalized_sub_route = Route(None, generalized_sub_route_name)
        generalized_route = Route(
            FAKE_VIEW,
            FAKE_ROUTE_NAME,
            [generalized_sub_route],
            )

        specialized_sub_route = generalized_sub_route.create_specialization(
            view=FAKE_VIEW,
            )
        specialized_route = generalized_route.create_specialization(
            specialized_sub_routes=[specialized_sub_route],
            )

        eq_((specialized_sub_route,), tuple(specialized_route.sub_routes))
예제 #28
0
    def test_sub_routes_with_duplicated_sub_route_names(self):
        generalized_sub_route_1 = Route(None, 'sub_route_1')
        generalized_sub_route_2 = Route(None, 'sub_route_2')
        generalized_route = Route(
            FAKE_VIEW,
            None,
            [generalized_sub_route_1, generalized_sub_route_2],
            )

        duplicated_sub_route_name = 'duplicated_sub_route_name'
        specialized_sub_route_1 = generalized_sub_route_1.create_specialization(
            additional_sub_routes=[Route(None, duplicated_sub_route_name)],
            )
        specialized_sub_route_2 = generalized_sub_route_2.create_specialization(
            additional_sub_routes=[Route(None, duplicated_sub_route_name)],
            )

        with assert_raises_substring(
            DuplicatedRouteError,
            duplicated_sub_route_name,
            ):
            generalized_route.create_specialization(
                specialized_sub_routes=[
                    specialized_sub_route_1,
                    specialized_sub_route_2,
                    ],
                )
예제 #29
0
    def test_specializing_with_invalid_sub_route(self):
        """
        The same validation routines as in the single inheritance case should be
        used.

        """
        sub_route_1 = Route(None, FAKE_ROUTE_NAME)
        generalized_route = Route(None, None, [sub_route_1])

        intermediate_route = generalized_route.create_specialization()

        sub_route_2 = Route(FAKE_VIEW, FAKE_ROUTE_NAME)
        with assert_raises_substring(
            InvalidSpecializationError,
            FAKE_ROUTE_NAME
            ):
            intermediate_route.create_specialization(
                specialized_sub_routes=[sub_route_2.create_specialization()],
                )
예제 #30
0
    def test_adding_duplicate_sub_route_name(self):
        generalized_sub_route = Route(None, FAKE_ROUTE_NAME)
        generalized_route = Route(FAKE_VIEW, None, [generalized_sub_route])

        duplicated_sub_route_name = 'duplicated_sub_route_name'
        specialized_sub_route = generalized_sub_route.create_specialization(
            additional_sub_routes=[Route(None, duplicated_sub_route_name)],
            )

        additional_sub_route = Route(None, duplicated_sub_route_name)

        with assert_raises_substring(
            DuplicatedRouteError,
            duplicated_sub_route_name,
            ):
            generalized_route.create_specialization(
                additional_sub_routes=[additional_sub_route],
                specialized_sub_routes=[specialized_sub_route],
                )