Пример #1
0
 def test_context_data(self):
     # Імітуємо будинок з одної квартири:
     floors = ['0']
     entrances = ['1']
     flat = Flat(floor_No=0, entrance_No=1)
     flat.save()
     block_scheme = {
         '0': {
             '1': [
                 flat,
             ]
         }
     }
     # {0: {1: [flat, ], 2: [flat, ]}, 1: {1: [flat, ], 2: [flat, ]},}
     block_length = {'1': 1}
     kwargs = {
         'block_scheme': block_scheme,
         'block_length': block_length,
         'floors': floors,
         'entrances': entrances,
     }
     # Setup request and view.
     request = RequestFactory().get('/flats/scheme/')
     view = FlatScheme()
     view = setup_view(view, request, kwargs)
     # Run.
     context = view.get_context_data()
     # Check.
     self.assertEqual(context['block_scheme'], block_scheme)
     self.assertEqual(context['block_length'], block_length)
     self.assertEqual(context['floors'], floors)
     self.assertEqual(context['entrances'], entrances)
Пример #2
0
 def test_context_data_3(self):
     # Імітуємо будинок з кількох квартир:
     floors = (1, 2)
     entrances = (1, 2)
     DummyFlat().create_dummy_building(floors=floors, entrances=entrances)
     d, floors, entrances = flats.views.block_scheme()
     l = flats.views.block_length(d)
     kwargs = {
         'block_scheme': d,
         'block_length': l,
         'floors': floors,
         'entrances': entrances,
     }
     # dict_print(kwargs, 'kwargs')
     # Setup request and view.
     request = RequestFactory().get('/flats/scheme/')
     view = FlatScheme()
     view = setup_view(view, request, kwargs)
     # Run.
     context = view.get_context_data()
     # Check.
     self.assertEqual(context['block_scheme'], d)
     self.assertEqual(context['block_length'], l)
     self.assertEqual(context['floors'], floors)
     self.assertEqual(context['entrances'], entrances)
Пример #3
0
 def test_context_data_2(self):
     # Імітуємо будинок з кількох квартир:
     flat1 = Flat(floor_No=1, entrance_No=1)
     flat1.save()
     flat2 = Flat(floor_No=2, entrance_No=2)
     flat2.save()
     flat3 = Flat(floor_No=2, entrance_No=2)
     flat3.save()
     floors = ["2", "1"]
     entrances = ["1", "2"]
     block_scheme = {"1": {"1": [flat1]}, "2": {"2": [flat2, flat3]}}
     # {0: {1: [flat, ], 2: [flat, ]}, 1: {1: [flat, ], 2: [flat, ]},}
     block_length = {"1": 1, "2": 2}
     kwargs = {"block_scheme": block_scheme, "block_length": block_length, "floors": floors, "entrances": entrances}
     # Setup request and view.
     request = RequestFactory().get("/flats/scheme/")
     view = FlatScheme()
     view = setup_view(view, request, kwargs)
     # Run.
     context = view.get_context_data()
     # Check.
     self.assertEqual(context["block_scheme"], block_scheme)
     self.assertEqual(context["block_length"], block_length)
     self.assertEqual(context["floors"], floors)
     self.assertEqual(context["entrances"], entrances)
Пример #4
0
 def test_context_data_2(self):
     # Імітуємо будинок з кількох квартир:
     flat1 = Flat(floor_No=1, entrance_No=1)
     flat1.save()
     flat2 = Flat(floor_No=2, entrance_No=2)
     flat2.save()
     flat3 = Flat(floor_No=2, entrance_No=2)
     flat3.save()
     floors = ['2', '1']
     entrances = ['1', '2']
     block_scheme = {'1': {'1': [flat1]}, '2': {'2': [flat2, flat3]}}
     # {0: {1: [flat, ], 2: [flat, ]}, 1: {1: [flat, ], 2: [flat, ]},}
     block_length = {'1': 1, '2': 2}
     kwargs = {
         'block_scheme': block_scheme,
         'block_length': block_length,
         'floors': floors,
         'entrances': entrances,
     }
     # Setup request and view.
     request = RequestFactory().get('/flats/scheme/')
     view = FlatScheme()
     view = setup_view(view, request, kwargs)
     # Run.
     context = view.get_context_data()
     # Check.
     self.assertEqual(context['block_scheme'], block_scheme)
     self.assertEqual(context['block_length'], block_length)
     self.assertEqual(context['floors'], floors)
     self.assertEqual(context['entrances'], entrances)
Пример #5
0
    def test_view_response_container_data(self):
        view = self.cls_view()
        users_list = [
            self.john, self.paul, self.george, self.ringo, self.freddy
        ]
        elemSet = self.get_elemSet(users_list)
        kwargs = self.get_kwargs_for_ajax_data(elemSet)
        ajax_data = DummyAjaxRequest(**kwargs).ajax_data()

        # Очікувані дані з response
        expected_set = []
        expected_set.append(
            self.get_expected(self.john, {}, {
                6: 'yes',
                7: 'yes',
                8: 'yes',
            }))
        expected_set.append(
            self.get_expected(self.paul, {8: True}, {
                6: 'yes',
                7: 'yes',
                8: 'yes',
            }))
        expected_set.append(
            self.get_expected(self.george, {8: True}, {
                6: 'yes',
                7: 'no',
                8: 'yes',
            }))
        expected_set.append(
            self.get_expected(self.ringo, {}, {
                6: 'unknown',
                7: 'no',
                8: 'no',
            }))
        expected_set.append(
            self.get_expected(self.freddy, {}, {
                6: 'no',
                7: 'no',
                8: 'no',
            }))

        request = self.client.request()
        request.POST = ajax_data
        request.user = self.john
        request.session = {}

        view = self.cls_view
        view = setup_view(view, request, **kwargs)

        response = view.as_view()(request, **kwargs)
        group_response_cont = json.loads(response._container[0].decode())
        response_set = group_response_cont['group']
        self.assertEqual(len(response_set), len(users_list))
        for i in range(len(users_list)):
            self.check_view_response_cont(response_set[i], True,
                                          *expected_set[i])
Пример #6
0
 def test_queryset(self):
     request = RequestFactory().get(self.path)
     kwargs = {'pk': 1}
     view = self.cls_view()
     view = setup_view(view, request, **kwargs)
     # view.model = Report
     view.object = self.flat1
     expected = [self.john]
     qs = view.get_queryset()
     self.assertEqual(qs, expected)
Пример #7
0
 def test_queryset(self):
     request = RequestFactory().get(self.path)
     kwargs = {"pk": 1}
     view = self.cls_view()
     view = setup_view(view, request, **kwargs)
     # view.model = Report
     view.object = self.flat1
     expected = [self.john]
     qs = view.get_queryset()
     self.assertEqual(qs, expected)
Пример #8
0
 def test_get_context_data(self):
     root = DummyFolder().create_dummy_root_folder()
     report = DummyFolder().create_dummy_report(root, id=1)
     request = RequestFactory().get('/folders/report/1/preview/')
     kwargs = {'pk': 1}
     view = self.cls_view()
     view = setup_view(view, request, **kwargs)
     view.model = Report
     view.object = report
     expected = get_viewable_extension_list()
     context = view.get_context_data()
     self.assertEqual(context['viewable_extension_list'], expected)
Пример #9
0
    def test_view_response_container_data(self):
        view = self.cls_view()
        users_list = [self.john, self.paul, self.george, self.ringo, self.freddy]
        elemSet = self.get_elemSet(users_list)
        kwargs = self.get_kwargs_for_ajax_data(elemSet)
        ajax_data = DummyAjaxRequest(**kwargs).ajax_data()

        # Очікувані дані з response
        expected_set = []
        expected_set.append(self.get_expected(
                                    self.john,
                                    {},
                                    {6: 'yes', 7: 'yes', 8: 'yes',})
                            )
        expected_set.append(self.get_expected(
                                    self.paul,
                                    {8: True},
                                    {6: 'yes', 7: 'yes', 8: 'yes',})
                            )
        expected_set.append(self.get_expected(
                                    self.george,
                                    {8: True},
                                    {6: 'yes', 7: 'no', 8: 'yes',})
                            )
        expected_set.append(self.get_expected(
                                    self.ringo,
                                    {},
                                    {6: 'unknown', 7: 'no', 8: 'no',})
                            )
        expected_set.append(self.get_expected(
                                    self.freddy,
                                    {},
                                    {6: 'no', 7: 'no', 8: 'no',})
                            )

        request = self.client.request()
        request.POST = ajax_data
        request.user = self.john
        request.session = {}

        view = self.cls_view
        view = setup_view(view, request, **kwargs)

        response = view.as_view()(request, **kwargs)
        group_response_cont = json.loads(response._container[0].decode())
        response_set = group_response_cont['group']
        self.assertEqual(len(response_set), len(users_list))
        for i in range(len(users_list)):
            self.check_view_response_cont(response_set[i], True, *expected_set[i])
Пример #10
0
 def test_context_data_3(self):
     # Імітуємо будинок з кількох квартир:
     floors = (1, 2)
     entrances = (1, 2)
     DummyFlat().create_dummy_building(floors=floors, entrances=entrances)
     d, floors, entrances = flats.views.block_scheme()
     l = flats.views.block_length(d)
     kwargs = {"block_scheme": d, "block_length": l, "floors": floors, "entrances": entrances}
     # dict_print(kwargs, 'kwargs')
     # Setup request and view.
     request = RequestFactory().get("/flats/scheme/")
     view = FlatScheme()
     view = setup_view(view, request, kwargs)
     # Run.
     context = view.get_context_data()
     # Check.
     self.assertEqual(context["block_scheme"], d)
     self.assertEqual(context["block_length"], l)
     self.assertEqual(context["floors"], floors)
     self.assertEqual(context["entrances"], entrances)
Пример #11
0
 def test_context_data(self):
     # Імітуємо будинок з одної квартири:
     floors = ["0"]
     entrances = ["1"]
     flat = Flat(floor_No=0, entrance_No=1)
     flat.save()
     block_scheme = {"0": {"1": [flat]}}
     # {0: {1: [flat, ], 2: [flat, ]}, 1: {1: [flat, ], 2: [flat, ]},}
     block_length = {"1": 1}
     kwargs = {"block_scheme": block_scheme, "block_length": block_length, "floors": floors, "entrances": entrances}
     # Setup request and view.
     request = RequestFactory().get("/flats/scheme/")
     view = FlatScheme()
     view = setup_view(view, request, kwargs)
     # Run.
     context = view.get_context_data()
     # Check.
     self.assertEqual(context["block_scheme"], block_scheme)
     self.assertEqual(context["block_length"], block_length)
     self.assertEqual(context["floors"], floors)
     self.assertEqual(context["entrances"], entrances)