Exemple #1
0
    def test_get_all_tool_ids_returns_successfully_from_datastore(self):
        tool_a = model.Tool(tool_id='tool_a')
        tool_b = model.Tool(tool_id='tool_b')
        tool_c = model.Tool(tool_id='tool_c')
        expected_ids = ['tool_a', 'tool_b', 'tool_c']

        tool_a.put()
        tool_b.put()
        tool_c.put()

        actual_ids = model.get_all_tool_ids()
        self.assertItemsEqual(actual_ids, expected_ids)
        self.assertTrue(model.is_valid_tool('tool_c'))
        self.assertFalse(model.is_valid_tool('this_is_an_invalid_tool_id'))
Exemple #2
0
    def get(self):
        """Handles an HTTP GET request.

        The URL must be in the following format:
        'http://mlab-ns.appspot.com/tool-name?query_string',
        where tool-name is one of the tools running on M-Lab.
        For more information about the URL and the supported arguments
        in the query string, see the design doc at http://goo.gl/48S22.
        """
        query = lookup_query.LookupQuery()
        query.initialize_from_http_request(self.request)

        # Check right away whether we should proxy this request.
        url = reverse_proxy.try_reverse_proxy_url(query,
                                                  datetime.datetime.now())
        if url:
            # NB: if sending the proxy url is unsuccessful, then fall through to
            # regular request handling.
            success = self.send_proxy_response(url)
            if success:
                logging.info('[reverse_proxy],true,%s', url)
                return

        logging.info('Policy is %s', query.policy)

        client_signature = query.calculate_client_signature()
        lookup_resolver = resolver.new_resolver(query.policy, client_signature)
        sliver_tools = lookup_resolver.answer_query(query)

        if sliver_tools is None:
            # NOTE: at this point, we know that either the query is invalid
            # (e.g. bad tool_id) or that a valid query has no capacity.
            if model.is_valid_tool(query.tool_id):
                # A.K.A. "no capacity".
                return util.send_no_content(self)
            else:
                # Invalid tool, so report "404 Not Found".
                return util.send_not_found(self, query.response_format)

        if query.response_format == message.FORMAT_JSON:
            self.send_json_response(sliver_tools, query)
        elif query.response_format == message.FORMAT_HTML:
            self.send_html_response(sliver_tools, query)
        elif query.response_format == message.FORMAT_REDIRECT:
            self.send_redirect_response(sliver_tools, query)
        elif query.response_format == message.FORMAT_BT:
            self.send_bt_response(sliver_tools, query)
        elif query.response_format == message.FORMAT_MAP:
            candidates = lookup_resolver.get_candidates(query)
            self.send_map_response(sliver_tools, query, candidates)
        else:
            # TODO (claudiu) Discuss what should be the default behaviour.
            # I think json it's OK since is valid for all tools, while
            # redirect only applies to web-based tools.

            self.send_json_response(sliver_tools, query)

        # At this point, the client has received a response but the server has
        # not closed the connection.
        self.log_location(query, sliver_tools)

        # TODO (claudiu) Add a FORMAT_TYPE column in the BigQuery schema.
        self.log_request(query, sliver_tools)
Exemple #3
0
 def test_get_all_tool_ids_no_stored_tools_returns_empty(self):
     self.assertItemsEqual(model.get_all_tool_ids(), [])
     self.assertFalse(model.is_valid_tool('any_tool_id'))