Beispiel #1
0
 def _test_valid_date_filter(self, filtername, date, awaited_result):
     f = Filters()
     try:
         f.add(filtername, date)
     except Exception:
         self.fail("Valid date could not be added: {}".format(filtername))
     self.assertEqual(f.get_formatted_filters(), awaited_result)
Beispiel #2
0
 def test_add_valid_doi_filter(self):
     f = Filters()
     try:
         f.add('doi', self.valid_doi)
     except Exception:
         self.fail("Valid DOI could not be added")
     self.assertEqual(f.get_formatted_filters(), "doi:10.1063/1.3458497")
Beispiel #3
0
 def test_add_valid_doi_filter(self):
     f = Filters()
     try:
         f.add('doi', self.valid_doi)
     except Exception:
         self.fail("Valid DOI could not be added")
     self.assertEqual(f.get_formatted_filters(), "doi:10.1063/1.3458497")
Beispiel #4
0
 def _test_valid_date_filter(self, filtername, date, awaited_result):
     f = Filters()
     try:
         f.add(filtername, date)
     except Exception:
         self.fail("Valid date could not be added: {}".format(filtername))
     self.assertEqual(f.get_formatted_filters(), awaited_result)
Beispiel #5
0
 def test_add_valid_has_funder_filter(self):
     f = Filters()
     try:
         f.add('has-funder', True)
     except Exception:
         self.fail("Valid has-funder could not be added")
     # use lower() since "True" and "False" are written with capital first
     # letters
     self.assertEqual(f.get_formatted_filters().lower(),
                      "has-funder:true".lower())
Beispiel #6
0
 def test_add_valid_has_funder_filter(self):
     f = Filters()
     try:
         f.add('has-funder', True)
     except Exception:
         self.fail("Valid has-funder could not be added")
     # use lower() since "True" and "False" are written with capital first
     # letters
     self.assertEqual(f.get_formatted_filters().lower(),
             "has-funder:true".lower())
Beispiel #7
0
def filter_domains(domains):
    for domain in domains:
        filter = Filters(config)
        a = filter.is_select_tld(domain)
        b = filter.is_proper_length(domain)
        c = filter.contains_keyword(domain)

        if not os.path.exists("results"):
            os.makedirs("results")
        fx = open(os.path.join('results', f'results_{filename}'), 'a')
        if a is True and b is True and c is True:
            print(domain)
            fx.write(domain + '\n')
        fx.close()
Beispiel #8
0
 def test_multiple_filter_entries(self):
     f = Filters()
     f.add('doi', self.valid_doi)
     f.add('from-pub-date', '2013')
     for entry in f.get_formatted_filters().split(','):
         self.assertIn(entry,
                       ["doi:10.1063/1.3458497", "from-pub-date:2013"])
Beispiel #9
0
 def test_multiple_filter_entries(self):
     f = Filters()
     f.add('doi', self.valid_doi)
     f.add('from-pub-date', '2013')
     for entry in f.get_formatted_filters().split(','):
         self.assertIn(entry, ["doi:10.1063/1.3458497",
             "from-pub-date:2013"])
Beispiel #10
0
    def prepare_search_query(self, string, sort='score', order='desc', \
            year=None, type_=None, rows=20):
        valid_sort_methods = ('score', 'updated', 'deposited', 'indexed',
                              'published')
        if sort not in valid_sort_methods:
            raise ValueError("Sort method not supported. Valid values are: \
{}".format(", ".join(valid_sort_methods)))

        valid_order_methods = ('asc', 'desc')
        if order not in valid_order_methods:
            raise ValueError("Order method not supported. Valid values are: \
{}".format(", ".join(valid_order_methods)))

        filters = Filters()
        payload = {'query': string, 'sort': sort, 'order': order, 'rows': rows}
        if year is not None:
            filters.add('from-pub-date', year)
        if type_ is not None:
            filters.add('type', type_)

        # load all filter values
        payload['filter'] = filters.get_formatted_filters()

        return urllib.parse.urlencode(payload)
Beispiel #11
0
    def prepare_search_query(self, string, sort='score', order='desc', \
            year=None, type_=None, rows=20):
        valid_sort_methods = ('score', 'updated', 'deposited', 'indexed',
                'published')
        if sort not in valid_sort_methods:
            raise ValueError("Sort method not supported. Valid values are: \
{}".format(", ".join(valid_sort_methods)))

        valid_order_methods = ('asc', 'desc')
        if order not in valid_order_methods:
            raise ValueError("Order method not supported. Valid values are: \
{}".format(", ".join(valid_order_methods)))

        filters = Filters()
        payload = {'query': string, 'sort': sort, 'order': order, 'rows': rows}
        if year is not None:
            filters.add('from-pub-date', year)
        if type_ is not None:
            filters.add('type', type_)

        # load all filter values
        payload['filter'] = filters.get_formatted_filters()

        return urllib.parse.urlencode(payload)
Beispiel #12
0
 def test_add_invalid_doi_filter(self):
     f = Filters()
     self.assertRaises(ValueError, f.add, 'doi', self.invalid_doi)
Beispiel #13
0
 def test_empty_filter(self):
     f = Filters()
     self.assertEqual(f.get_formatted_filters(), "")
Beispiel #14
0
 def test_add_invalid_until_index_date_filter(self):
     f = Filters()
     self.assertRaises(ValueError, f.add, 'until-index-date', "20132")
Beispiel #15
0
 def test_add_valid_license_url_filter(self):
     f = Filters()
     try:
         f.add('license.url', 'http://example.com/this/is/a/test.html')
     except Exception:
         self.fail("Valid license.url could not be added")
Beispiel #16
0
 def test_add_valid_license_url_filter(self):
     f = Filters()
     try:
         f.add('license.url', 'http://example.com/this/is/a/test.html')
     except Exception:
         self.fail("Valid license.url could not be added")
Beispiel #17
0
 def test_add_invalid_from_pub_date_filter(self):
     f = Filters()
     self.assertRaises(ValueError, f.add, 'from-pub-date', "20132")
Beispiel #18
0
 def test_add_invalid_license_url_filter(self):
     f = Filters()
     self.assertRaises(ValueError, f.add, 'license.url',
                       'httpf://example.com/this/is/a/invalid/url.html')
Beispiel #19
0
 def test_add_invalid_until_deposition_date_filter(self):
     f = Filters()
     self.assertRaises(ValueError, f.add, 'until-deposition-date', "20132")
Beispiel #20
0
 def test_add_valid_full_text_version_filter(self):
     f = Filters()
     try:
         f.add('full-text.version', '1.01.beta')
     except Exception:
         self.fail("Valid full-text.version could not be added")
Beispiel #21
0
 def test_add_invalid_has_funder_filter(self):
     f = Filters()
     self.assertRaises(ValueError, f.add, 'has-funder', "true")
Beispiel #22
0
 def test_add_invalid_full_text_version_filter(self):
     f = Filters()
     self.assertRaises(ValueError, f.add, 'full-text.version', 4)
Beispiel #23
0
 def test_empty_filter(self):
     f = Filters()
     self.assertEqual(f.get_formatted_filters(), "")
Beispiel #24
0
 def test_add_valid_full_text_version_filter(self):
     f = Filters()
     try:
         f.add('full-text.version', '1.01.beta')
     except Exception:
         self.fail("Valid full-text.version could not be added")