def testConstructing(self): empty = QUrlQuery() self.assertTrue(empty.isEmpty()) self.assertEqual(empty.queryPairDelimiter(), QUrlQuery.defaultQueryPairDelimiter()) self.assertEqual(empty.queryValueDelimiter(), QUrlQuery.defaultQueryValueDelimiter()) empty.clear(); self.assertTrue(empty.isEmpty())
def build_request(self, query_items): query = QUrlQuery() for k, v in query_items.items(): query.addQueryItem(k, v) url = QUrl(self.base_url) url.setQuery(query) request = QNetworkRequest(self.base_request) request.setUrl(url) return request
def testAllQueryItemsValues(self): url = QUrlQuery() key = 'key' valid_data = ['data', 'valid', 'test'] for i, data in enumerate(valid_data): url.addQueryItem(key, data) self.assertEqual(url.allQueryItemValues(key), list(valid_data[:i + 1]))
def testAddRemove(self): query = QUrlQuery() query.addQueryItem("a", "b"); self.assertTrue(not query.isEmpty()) self.assertTrue(query.hasQueryItem("a")) self.assertEqual(query.queryItemValue("a"), "b") self.assertEqual(query.allQueryItemValues("a"), ["b"])
def testAddQueryItem(self): url = QUrlQuery() valid_data = [('hl', 'en'), ('user', 'konqui')] url.addQueryItem(*valid_data[0]) self.assertEqual(url.queryItems()[0], valid_data[0]) url.addQueryItem(*valid_data[1]) self.assertEqual(sorted(url.queryItems()), sorted(valid_data))
def time_by_city(self, city: str) -> None: url = QUrl(WeatherDate.BASE_URL) query = QUrlQuery() query.addQueryItem("q", city) query.addQueryItem("appid", self.api_key) url.setQuery(query) request = QtNetwork.QNetworkRequest(url) reply: QtNetwork.QNetworkReply = self.manager.get(request) reply.finished.connect(self.tim)
def update_by_city(self, city: str): url = QUrl(WeatherWrapper.BASE_URL) query = QUrlQuery() query.addQueryItem("q", city) query.addQueryItem("appid", self.api_key) url.setQuery(query) request = QtNetwork.QNetworkRequest(url) reply: QtNetwork.QNetworkReply = self.manager.get(request) reply.finished.connect(self._handle_reply)
def testEncodedQueryItems(self): url = QUrl('http://www.google.com/search?q=python&hl=en') valid_data = [(('q'), ('python')), (('hl'), ('en'))] self.assertEqual(sorted(QUrlQuery(url.query()).queryItems()), sorted(valid_data))