Beispiel #1
0
    def test_neighbourhood_active_false(self):
        neighbourhood_looking_for = create_neighbourhood('Target')
        other_neighbourhood = create_neighbourhood('Non-target')

        obj_in = create_resale_apartment(
            rooms=3,
            neighbourhood=neighbourhood_looking_for,
        )
        obj_out1 = create_resale_apartment(
            rooms=4,
            neighbourhood=other_neighbourhood,
        )
        obj_out2 = create_resale_apartment(
            rooms=2,
            neighbourhood=neighbourhood_looking_for,
            is_active=False,
        )
        obj_out3 = create_resale_apartment(
            rooms=1,
            neighbourhood=neighbourhood_looking_for,
            status=STATUS_SOLD_WITHOUT_US,
        )

        q = self.get_default_queryset().filter(
            neighbourhood=neighbourhood_looking_for)

        response = self.get_resale_list(
            get_params={'neighbourhood': neighbourhood_looking_for.pk})

        self.assertResponseObjectListAppropriate(
            response,
            queryset_for_comparison=q,
            amount_in=1,
            must_in=[obj_in],
            must_out=[obj_out1, obj_out2, obj_out3, self.apartment])
Beispiel #2
0
    def test_search_by_any_text_neigbourhood(self):
        target_neigbourhood = create_neighbourhood('МЫС')
        non_target_neigbourhood = create_neighbourhood('Дом Обороны')
        number_of_rc_with_target_neigbourhood = 6

        # target ResidentalComplexes
        self.RCWithBuildingWithApartmentFactory(
            number_of_rc_with_target_neigbourhood,
            "Target RC",
            rc_kwargs={'neighbourhood': target_neigbourhood})

        # non target ResidentalComplexes
        self.RCWithBuildingWithApartmentFactory(
            10,
            "Non-Target RC",
            rc_kwargs={'neighbourhood': non_target_neigbourhood
                       }) + self.RCWithBuildingWithApartmentFactory(
                           10,
                           "no-active RC with appropriate neigbourhood",
                           rc_kwargs={
                               'is_active': False,
                               'neighbourhood': target_neigbourhood,
                           })

        resp = self.client.get(
            reverse('new_buildings:residental-complex-list'),
            {'any_text': target_neigbourhood.name})
        self.assertEqual(resp.status_code, 200)
        self.assertTrue(
            len(resp.context['residental_complexes']) ==
            number_of_rc_with_target_neigbourhood)
Beispiel #3
0
    def test_search_by_any_text(self):
        target_part = 'detach'
        neighbourhood_looking_for = create_neighbourhood('Semi' + target_part)
        street_looking_for = create_street(target_part + 'ed')
        rc_looking_for = create_RC(name='RC' + target_part)

        obj_in1 = create_resale_apartment(
            neighbourhood=neighbourhood_looking_for)
        obj_in2 = create_resale_apartment(street=street_looking_for)
        obj_in3 = create_resale_apartment(residental_complex=rc_looking_for)

        obj_out1 = create_resale_apartment(rooms=2)
        obj_out2 = create_resale_apartment(rooms=3)
        obj_out3 = create_resale_apartment(rooms=4)

        q = self.get_default_queryset().filter(
            Q(neighbourhood=neighbourhood_looking_for)
            | Q(street=street_looking_for)
            | Q(residental_complex=rc_looking_for))

        response = self.get_resale_list(get_params={'any_text': target_part})

        self.assertResponseObjectListAppropriate(
            response,
            queryset_for_comparison=q,
            amount_in=3,
            must_in=[
                obj_in1,
                obj_in2,
                obj_in3,
            ],
            must_out=[obj_out1, obj_out2, obj_out3, self.apartment])
Beispiel #4
0
def create_resale_apartment(**kwargs):
    owner_name = kwargs.pop('owner_name', "NAME")
    owner_phone_number = kwargs.pop('owner_phone_number', "+79999999999")
    neighbourhood = kwargs.pop(
        'neighbourhood',
        create_neighbourhood(),
    )
    street = kwargs.pop('street', create_street())
    total_area = kwargs.pop('total_area', DEFAULT_TOTAL_AREA)
    building = kwargs.pop('building', 777)
    price = kwargs.pop('price', DEFAULT_PRICE)
    agency_price = kwargs.pop('agency_price', price)
    rooms = kwargs.pop('rooms', DEFAULT_ROOMS)

    return ResaleApartment.objects.create(
        agency_price=agency_price,
        price=price,
        owner_name=owner_name,
        owner_phone_number=owner_phone_number,
        neighbourhood=neighbourhood,
        street=street,
        building=building,
        total_area=total_area,
        layout=create_mock_image_file(),
        rooms=rooms,
        **kwargs)
Beispiel #5
0
    def test_neighbourhood(self):
        neighbourhood_looking_for = create_neighbourhood('Target')
        other_neighbourhood = create_neighbourhood('Non-target')

        obj_in1 = create_resale_apartment(
            rooms=3, neighbourhood=neighbourhood_looking_for)
        obj_in2 = create_resale_apartment(
            rooms=4, neighbourhood=neighbourhood_looking_for)
        obj_out = create_resale_apartment(rooms=2,
                                          neighbourhood=other_neighbourhood)

        q = self.get_default_queryset().filter(
            neighbourhood=neighbourhood_looking_for)

        response = self.get_resale_list(
            # Important use neighbourhood_looking_for.pk
            get_params={'neighbourhood': neighbourhood_looking_for.pk})

        self.assertResponseObjectListAppropriate(
            response,
            queryset_for_comparison=q,
            amount_in=2,
            must_in=[obj_in1, obj_in2],
            must_out=[obj_out, self.apartment])
Beispiel #6
0
def create_RC(name='RC', description='smthng', is_active=True, **kwargs):
    """ Creates Residental Complex.
    Adds builder, neighbourhood and type_of_complex objs automatically
    if its not provides"""
    builder = kwargs.pop('builder', create_builder())
    neighbourhood = kwargs.pop('neighbourhood', create_neighbourhood())
    type_of_complex = kwargs.pop('type_of_complex', create_type_of_complex())

    return ResidentalComplex.objects.create(name=name,
                                            description=description,
                                            is_active=is_active,
                                            builder=builder,
                                            neighbourhood=neighbourhood,
                                            type_of_complex=type_of_complex,
                                            **kwargs)