def test_flt_string_field(self):
        op, term = parse_like_term('index-%s' % str(uuid4().hex))

        result = get_flt(Journal.index_at, term, op)

        expected = Q(**{'%s__%s' % (Journal.index_at.name, op): term})

        self.assertEqual(expected.query, result.query)
    def test_flt_embedded_use_licenses(self):

        op, term = parse_like_term('CC-%s' % str(uuid4().hex))
        expected = Q(**{'use_licenses__license_code__%s' % op: term})
        expected |= Q(**{'use_licenses__reference_url__%s' % op: term})
        expected |= Q(**{'use_licenses__disclaimer__%s' % op: term})
        expected_children = [i.query for i in expected.children]

        result = get_flt(Journal.use_licenses, term, op)
        self.assertEqual(expected.operation, result.operation)
        self.assertEqual(expected_children, [i.query for i in result.children])
Beispiel #3
0
    def _search(self, query, search_term):
        op, term = parse_like_term(search_term)

        criteria = None

        for field in self._search_fields:
            flt = get_flt(field, term, op)

            if criteria is None:
                criteria = flt
            else:
                criteria |= flt
        return query.filter(criteria)
    def test_flt_search_reference_issue(self):

        journal = makeOneJournal()
        issue = makeOneIssue({'journal': journal})
        makeOneArticle({'journal': journal, 'issue': issue})

        op, term = parse_like_term(issue.label)
        result = get_flt(Article.issue, term, op)

        issues = Issue.objects.filter(Q(**{'label__%s' % op: term}))
        expected = Q(**{'issue__in': issues})

        self.assertIn('issue__in', result.query)
        self.assertItemsEqual(expected.query['issue__in'], result.query['issue__in'])
    def test_custom_filter_not_like(self):

        journal = makeOneJournal({'title': 'title-%s' % str(uuid4().hex)})
        makeOneIssue({'journal': journal})
        column = Issue.journal
        custom_filter = CustomFilterNotLike(column=column, name=__(u'Periódico'))

        result = custom_filter.apply(Issue.objects, journal.title)

        term, data = parse_like_term(journal.title)
        journals = Journal.objects.filter(Q(**{'title__not__%s' % term: data}))
        expected = Issue.objects.filter(Q(**{'%s__in' % column.name: journals}))

        self.assertItemsEqual(expected, result)
    def test_flt_reference_journal(self):

        journal_fields = {
            'title': 'title-%s' % str(uuid4().hex),
            'title_iso': 'title_iso-%s' % str(uuid4().hex),
            'short_title': 'short_title-%s' % str(uuid4().hex),
            'acronym': 'acronym-%s' % str(uuid4().hex),
            'print_issn': 'print_issn-%s' % str(uuid4().hex),
            'eletronic_issn': 'eletronic_issn-%s' % str(uuid4().hex)}

        journal = makeOneJournal(journal_fields)
        makeOneIssue({'journal': journal})

        for field in journal_fields:
            op, term = parse_like_term(journal[field])
            result = get_flt(Issue.journal, term, op)

            journals = Journal.objects.filter(Q(**{'%s__%s' % (field, op): term}))
            expected = Q(**{'journal__in': journals})

            self.assertIn('journal__in', result.query)
            self.assertItemsEqual(expected.query['journal__in'], result.query['journal__in'])
Beispiel #7
0
 def apply(self, query, value):
     term, data = parse_like_term(value)
     flt = get_flt(self.column, data, "not__%s" % term)
     return query.filter(flt)
    def test_flt_list_field(self):

        op, term = parse_like_term('title-%s' % str(uuid4().hex))
        result = get_flt(Journal.title, term, op)