test_scanr_structures.py 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import scanr_structures
  4. from searx.testing import SearxTestCase
  5. class TestScanrStructuresEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. dicto = defaultdict(dict)
  9. dicto['pageno'] = 1
  10. params = scanr_structures.request(query, dicto)
  11. self.assertIn('url', params)
  12. self.assertIn(query, params['data'])
  13. self.assertIn('scanr.enseignementsup-recherche.gouv.fr', params['url'])
  14. def test_response(self):
  15. self.assertRaises(AttributeError, scanr_structures.response, None)
  16. self.assertRaises(AttributeError, scanr_structures.response, [])
  17. self.assertRaises(AttributeError, scanr_structures.response, '')
  18. self.assertRaises(AttributeError, scanr_structures.response, '[]')
  19. response = mock.Mock(text='{}')
  20. self.assertEqual(scanr_structures.response(response), [])
  21. response = mock.Mock(text='{"data": []}')
  22. self.assertEqual(scanr_structures.response(response), [])
  23. json = u"""
  24. {
  25. "request":
  26. {
  27. "query":"test_query",
  28. "page":1,
  29. "pageSize":20,
  30. "sortOrder":"RELEVANCY",
  31. "sortDirection":"ASC",
  32. "searchField":"ALL",
  33. "from":0
  34. },
  35. "total":2471,
  36. "results":[
  37. {
  38. "id":"200711886U",
  39. "label":"Laboratoire d'Informatique de Grenoble",
  40. "kind":"RNSR",
  41. "publicEntity":true,
  42. "address":{"city":"Grenoble","departement":"38"},
  43. "logo":"/static/logos/200711886U.png",
  44. "acronym":"LIG",
  45. "type":{"code":"UR","label":"Unit\xe9 de recherche"},
  46. "level":2,
  47. "institutions":[
  48. {
  49. "id":"193819125",
  50. "label":"Grenoble INP",
  51. "acronym":"IPG",
  52. "code":"UMR 5217"
  53. },
  54. {
  55. "id":"130021397",
  56. "label":"Universit\xe9 de Grenoble Alpes",
  57. "acronym":"UGA",
  58. "code":"UMR 5217"
  59. },
  60. {
  61. "id":"180089013",
  62. "label":"Centre national de la recherche scientifique",
  63. "acronym":"CNRS",
  64. "code":"UMR 5217"
  65. },
  66. {
  67. "id":"180089047",
  68. "label":"Institut national de recherche en informatique et en automatique",
  69. "acronym":"Inria",
  70. "code":"UMR 5217"
  71. }
  72. ],
  73. "highlights":[
  74. {
  75. "type":"projects",
  76. "value":"linguicielles d\xe9velopp\xe9s jusqu'ici par le GETALP\
  77. du <strong>LIG</strong> en tant que prototypes op\xe9rationnels.\
  78. \\r\\nDans le contexte"
  79. },
  80. {
  81. "type":"acronym",
  82. "value":"<strong>LIG</strong>"
  83. },
  84. {
  85. "type":"websiteContents",
  86. "value":"S\xe9lection\\nListe structures\\nD\xe9tail\\n\
  87. Accueil\\n200711886U : <strong>LIG</strong>\
  88. Laboratoire d'Informatique de Grenoble Unit\xe9 de recherche"},
  89. {
  90. "type":"publications",
  91. "value":"de noms. Nous avons d'abord d\xe9velopp\xe9 LOOV \
  92. (pour <strong>Lig</strong> Overlaid OCR in Vid\xe9o), \
  93. un outil d'extraction des"
  94. }
  95. ]
  96. },
  97. {
  98. "id":"199511665F",
  99. "label":"Laboratoire Bordelais de Recherche en Informatique",
  100. "kind":"RNSR",
  101. "publicEntity":true,
  102. "address":{"city":"Talence","departement":"33"},
  103. "logo":"/static/logos/199511665F.png",
  104. "acronym":"LaBRI",
  105. "type":{"code":"UR","label":"Unit\xe9 de recherche"},
  106. "level":2,
  107. "institutions":[
  108. {
  109. "id":"130006356",
  110. "label":"Institut polytechnique de Bordeaux",
  111. "acronym":"IPB",
  112. "code":"UMR 5800"
  113. },
  114. {
  115. "id":"130018351",
  116. "label":"Universit\xe9 de Bordeaux",
  117. "acronym":null,
  118. "code":"UMR 5800"
  119. },
  120. {
  121. "id":"180089013",
  122. "label":"Centre national de la recherche scientifique",
  123. "acronym":"CNRS",
  124. "code":"UMR 5800"
  125. },
  126. {
  127. "id":"180089047",
  128. "label":"Institut national de recherche en informatique et en automatique",
  129. "acronym":"Inria",
  130. "code":"UMR 5800"
  131. }
  132. ],
  133. "highlights":[
  134. {
  135. "type":"websiteContents",
  136. "value":"Samia Kerdjoudj\\n2016-07-05\\nDouble-exponential\
  137. and <strong>triple</strong>-exponential bounds for\
  138. choosability problems parameterized"
  139. },
  140. {
  141. "type":"publications",
  142. "value":"de cam\xe9ras install\xe9es dans les lieux publiques \
  143. a <strong>tripl\xe9</strong> en 2009, passant de 20 000 \
  144. \xe0 60 000. Malgr\xe9 le"
  145. }
  146. ]
  147. }
  148. ]
  149. }
  150. """
  151. response = mock.Mock(text=json)
  152. results = scanr_structures.response(response)
  153. self.assertEqual(type(results), list)
  154. self.assertEqual(len(results), 2)
  155. self.assertEqual(results[0]['title'], u"Laboratoire d'Informatique de Grenoble")
  156. self.assertEqual(results[0]['url'], 'https://scanr.enseignementsup-recherche.gouv.fr/structure/200711886U')
  157. self.assertEqual(results[0]['content'],
  158. u"linguicielles d\xe9velopp\xe9s jusqu'ici par le GETALP "
  159. u"du LIG en tant que prototypes "
  160. u"op\xe9rationnels. Dans le contexte")
  161. self.assertEqual(results[1]['img_src'],
  162. 'https://scanr.enseignementsup-recherche.gouv.fr//static/logos/199511665F.png')
  163. self.assertEqual(results[1]['content'],
  164. "Samia Kerdjoudj 2016-07-05 Double-exponential and"
  165. " triple-exponential bounds for "
  166. "choosability problems parameterized")
  167. self.assertEqual(results[1]['url'], 'https://scanr.enseignementsup-recherche.gouv.fr/structure/199511665F')
  168. self.assertEqual(results[1]['title'], u"Laboratoire Bordelais de Recherche en Informatique")