示例#1
0
 def test_search(self):
     admin_auth = HmacAuth("edd", self.admin_ice_user.email)
     ice = IceApi(admin_auth)
     # pRS426 is one of the items in the ice_entries.csv file
     results = ice.search("pRS426")
     # multiple matching entries, check that one is found
     # ceiling on number of results depends on how often test suite runs
     self.assertNotEqual(len(results), 0)
示例#2
0
def search_strain(request):
    """ Autocomplete delegates to ICE search API. """
    auth = HmacAuth(key_id=settings.ICE_KEY_ID, username=request.user.email)
    ice = IceApi(auth=auth, verify_ssl_cert=settings.ICE_VERIFY_CERT)
    ice.timeout = settings.ICE_REQUEST_TIMEOUT
    term = request.GET.get("term", "")
    results = ice.search(term)
    return JsonResponse({"rows": results})
    def handle(self, *args, **options):
        # get the username argument
        username = options["username"]

        # get ICE authentication configured via EDD's config files (secrets.env and / or
        # settings/local.py)
        auth = HmacAuth(key_id=settings.ICE_KEY_ID, username=username)
        ice = IceApi(auth, verify_ssl_cert=settings.ICE_VERIFY_CERT)
        ice.timeout = settings.ICE_REQUEST_TIMEOUT

        try:
            self.stdout.write("Contacting ICE at %s" % ice.base_url)

            part_id = options.get("part_id")

            if part_id:
                self.stdout.write('Requesting part "%s"' % part_id)
                entry = ice.get_entry(part_id)
                if entry:
                    self.stdout.write("Found the part!")
                else:
                    self.stdout.write(f'Part "{part_id}" was not found in ICE')
            else:
                search_term = options.get("term", "")
                if options.get("advanced", False):
                    self.stdout.write(
                        f'Searching ICE for term "{search_term}" (advanced search)'
                    )
                    results_page = ice.search_entries(search_term)
                    self.print_advanced_search(results_page, username)

                else:
                    self.stdout.write(
                        f'Searching ICE for term "{search_term}" '
                        f"(simple UI-facing search)")
                    entry_info = ice.search(search_term)
                    self.print_simple_search(entry_info)
        except Exception as e:
            raise CommandError(e)
示例#4
0
 def search_ice_as_action(self, request, queryset):
     # intentionally throw error when multiple users selected
     user = queryset.get()
     context = self.admin_site.each_context(request)
     auth = HmacAuth(key_id=settings.ICE_KEY_ID, username=user.email)
     ice = IceApi(auth=auth, verify_ssl_cert=settings.ICE_VERIFY_CERT)
     ice.timeout = settings.ICE_REQUEST_TIMEOUT
     results = []
     term = request.POST.get("term", None)
     if term is not None:
         try:
             results = ice.search(term)
         except IceApiException:
             self.message_user(
                 request,
                 "Failed to execute search in ICE, check the ICE logs.",
                 messages.ERROR,
             )
     context.update(ice=ice.base_url, results=results, impersonate=user)
     return render(request,
                   "admin/strain_impersonate_search.html",
                   context=context)