Пример #1
0
    def test_should_return_datasender_with_space_seperated_projects_and_groups(
            self):
        # required_field_names = ['field_name1', 'projects']
        query = MagicMock()
        result = SimpleResult()
        result.projects = ["p1", "p2"]
        result.customgroups = ["g1", "g2"]

        result2 = SimpleResult()
        result2.projects = ["p1", "p2", "p3"]
        result2.customgroups = ["g2"]

        query.hits = [result, result2]

        datasenders = DatasenderQueryResponseCreator().create_response(query)
        self.assertEquals(datasenders, [
            [
                "", "", "", "", "", "", "p1, p2",
                '<img alt="Yes" src="/media/images/right_icon.png" class="device_checkmark">',
                "g1, g2", ""
            ],
            [
                "", "", "", "", "", "", "p1, p2, p3",
                '<img alt="Yes" src="/media/images/right_icon.png" class="device_checkmark">',
                "g2", ""
            ]
        ])
Пример #2
0
    def post(self, request, *args, **kwargs):
        user = request.user
        manager = get_database_manager(user)
        search_parameters = {}
        search_filters = json.loads(request.POST.get('search_filters', ''))
        search_text = request.POST.get('sSearch', '').strip()
        search_filters.update({"search_text": search_text})
        search_parameters.update(
            {"start_result_number": int(request.POST.get('iDisplayStart'))})
        search_parameters.update(
            {"number_of_results": int(request.POST.get('iDisplayLength'))})
        search_parameters.update(
            {"sort_field": self._get_order_field(request.POST, manager)})
        search_parameters.update({"search_filters": search_filters})
        search_parameters.update(
            {"order": "-" if request.POST.get('sSortDir_0') == "desc" else ""})

        query_fields, datasenders = get_data_sender_search_results(
            manager, search_parameters)
        total_count = get_data_sender_without_search_filters_count(
            manager, search_parameters)
        filtered_count = get_data_sender_count(manager, search_parameters)
        datasenders = DatasenderQueryResponseCreator().create_response(
            datasenders)

        return HttpResponse(jsonpickle.encode(
            {
                'data': datasenders,
                'iTotalDisplayRecords': filtered_count,
                'iDisplayStart': int(request.POST.get('iDisplayStart')),
                "iTotalRecords": total_count,
                'iDisplayLength': int(request.POST.get('iDisplayLength'))
            },
            unpicklable=False),
                            content_type='application/json')
Пример #3
0
 def test_should_not_add_check_symbol_if_no_email_id(self):
     result = []
     check_img = '<img alt="Yes" src="/media/images/right_icon.png" class="device_checkmark">'
     datasender = {'name': 'name'}
     DatasenderQueryResponseCreator().add_check_symbol_for_row(
         datasender, result)
     self.assertListEqual(result, [check_img])
Пример #4
0
 def test_add_check_symbol_for_datasender_row(self):
     result = []
     check_img = '<img alt="Yes" src="/media/images/right_icon.png" class="device_checkmark">'
     datasender = {'email': '*****@*****.**'}
     DatasenderQueryResponseCreator().add_check_symbol_for_row(
         datasender, result)
     self.assertListEqual(result, [check_img + check_img + check_img])
Пример #5
0
    def test_should_return_datasender_with_field_values_specified(self):
        required_field_names = ['field_name1', 'field_name2']
        query = Mock()
        query.values_dict.return_value = [{
            "field_name1": "field_value11",
            "field_name2": "field_value12"
        }, {
            "field_name1": "field_value21",
            "field_name2": "field_value22"
        }]

        datasenders = DatasenderQueryResponseCreator().create_response(
            required_field_names, query)
        query.values_dict.assert_called_with(("field_name1", "field_name2"))
        self.assertEquals(datasenders, [["field_value11", "field_value12"],
                                        ["field_value21", "field_value22"]])
Пример #6
0
    def test_should_return_datasender_with_space_seperated_projects(self):
        required_field_names = ['field_name1', 'projects']
        query = Mock()
        query.values_dict.return_value = [{
            "field_name1": "field_value11",
            "projects": ["p1", "p2"]
        }, {
            "field_name1": "field_value21",
            "projects": ["p1", "p2", "p3"]
        }]

        datasenders = DatasenderQueryResponseCreator().create_response(
            required_field_names, query)
        query.values_dict.assert_called_with(("field_name1", "projects"))
        self.assertEquals(
            datasenders,
            [["field_value11", "p1, p2"], ["field_value21", "p1, p2, p3"]])
Пример #7
0
    def post(self, request, project_name, *args, **kwargs):
        user = request.user
        manager = get_database_manager(user)
        project_name_unquoted = lowercase_and_strip_accents(
            unquote(project_name))
        search_parameters = {}
        search_filters = {}
        search_text = lower(request.POST.get('sSearch', '').strip())
        search_filters.update({"search_text": search_text})
        search_parameters.update(
            {"start_result_number": int(request.POST.get('iDisplayStart'))})
        search_parameters.update(
            {"number_of_results": int(request.POST.get('iDisplayLength'))})
        search_parameters.update({
            "sort_field":
            DATASENDER_DISPLAY_FIELD_ORDER[int(request.POST.get('iSortCol_0'))
                                           - 1]
        })
        search_parameters.update(
            {"order": "-" if request.POST.get('sSortDir_0') == "desc" else ""})
        search_filters.update({"project_name": project_name_unquoted})
        search_parameters.update({"search_filters": search_filters})

        query_fields, search_results = get_data_sender_search_results(
            manager, search_parameters)
        total_count = get_data_sender_without_search_filters_count(
            manager, search_parameters)
        filtered_count = get_data_sender_count(manager, search_parameters)
        query_fields.remove('projects')
        datasenders = DatasenderQueryResponseCreator().create_response(
            search_results, show_projects=False)

        return HttpResponse(jsonpickle.encode(
            {
                'data': datasenders,
                'iTotalDisplayRecords': filtered_count,
                'iDisplayStart': int(request.POST.get('iDisplayStart')),
                "iTotalRecords": total_count,
                'iDisplayLength': int(request.POST.get('iDisplayLength'))
            },
            unpicklable=False),
                            content_type='application/json')