def test_invalid_direction(self): """ Calling `read_entries` with invalid direction raises ValueError """ self.assertRaises( ValueError, sync_perform, base_dispatcher, cf.read_entries(self.service_type, self.url, {}, "bad"))
def test_empty(self, rel): """ Does not go further when there are no entries and return [] """ feedstr = self.feed(rel, "link-doesnt-matter", []) seq = [ (self.svc_intent(), const(stub_json_response(feedstr))) ] entries_eff = cf.read_entries( self.service_type, self.url, {}, self.directions[rel]) self.assertEqual(perform_sequence(seq, entries_eff), ([], {}))
def test_no_link(self, rel): """ Returns entries collected till now if there is no rel link """ feedstr = ( '<feed xmlns="http://www.w3.org/2005/Atom">' '<entry><summary>summary</summary></entry></feed>') seq = [ (self.svc_intent({"a": "b"}), const(stub_json_response(feedstr))) ] entries, params = perform_sequence( seq, cf.read_entries( self.service_type, self.url, {"a": "b"}, self.directions[rel])) self.assertEqual(atom.summary(entries[0]), "summary") self.assertEqual(params, {"a": "b"})
def get_clb_node_feed(lb_id, node_id): """ Get the atom feed associated with a CLB node. :param int lb_id: Cloud Load balancer ID :param int node_id: Node ID of in loadbalancer node :returns: Effect of ``list`` of atom entry :class:`Element` :rtype: ``Effect`` """ return cf.read_entries( ServiceType.CLOUD_LOAD_BALANCERS, append_segments('loadbalancers', str(lb_id), 'nodes', '{}.atom'.format(node_id)), {}, cf.Direction.NEXT, "request-get-clb-node-feed").on( itemgetter(0)).on(error=only_json_api_errors( lambda c, b: _process_clb_api_error(c, b, lb_id)))
def test_single_page(self, rel): """ Collects entries and goes to next link if there are entries and returns if next one is empty """ feed1str = self.feed(rel, "https://url?page=2", ["summary1", "summ2"]) feed2str = self.feed(rel, "link", []) seq = [ (self.svc_intent({"a": "b"}), const(stub_json_response(feed1str))), (self.svc_intent({"page": ['2']}), const(stub_json_response(feed2str))) ] entries, params = perform_sequence( seq, cf.read_entries( self.service_type, self.url, {"a": "b"}, self.directions[rel])) self.assertEqual( [atom.summary(entry) for entry in entries], ["summary1", "summ2"]) self.assertEqual(params, {"page": ["2"]})
def test_log_responses(self, rel): """ Each request sent is logged if `log_msg_type` is given """ feed1_str = self.feed(rel, "https://url?page=2", ["summ1", "summ2"]) feed2_str = self.feed(rel, "https://url?page=3", ["summ3", "summ4"]) feed3_str = self.feed(rel, "link", []) seq = [ (self.svc_intent(), const(stub_json_response(feed1_str))), (log_intent("nodemsg", feed1_str, False), noop), (self.svc_intent({"page": ['2']}), const(stub_json_response(feed2_str))), (log_intent("nodemsg", feed2_str, False), noop), (self.svc_intent({"page": ['3']}), const(stub_json_response(feed3_str))), (log_intent("nodemsg", feed3_str, False), noop) ] entries, params = perform_sequence( seq, cf.read_entries( self.service_type, self.url, {}, self.directions[rel], log_msg_type="nodemsg"))
def test_follow_limit(self, rel): """ Collects entries and keeping following rel link until `follow_limit` is reached. """ feeds = [self.feed(rel, "https://url?page={}".format(i + 1), ["summ{}".format(i + 1)]) for i in range(5)] seq = [ (self.svc_intent(), const(stub_json_response(feeds[0]))), (self.svc_intent({"page": ['1']}), const(stub_json_response(feeds[1]))), (self.svc_intent({"page": ['2']}), const(stub_json_response(feeds[2]))), ] entries, params = perform_sequence( seq, cf.read_entries( self.service_type, self.url, {}, self.directions[rel], 3)) self.assertEqual( [atom.summary(entry) for entry in entries], ["summ1", "summ2", "summ3"]) self.assertEqual(params, {"page": ["3"]})
def test_multiple_pages(self, rel): """ Collects entries and goes to next link if there are entries and continues until next link returns empty list """ feed1_str = self.feed(rel, "https://url?page=2", ["summ1", "summ2"]) feed2_str = self.feed(rel, "https://url?page=3", ["summ3", "summ4"]) feed3_str = self.feed(rel, "link", []) seq = [ (self.svc_intent(), const(stub_json_response(feed1_str))), (self.svc_intent({"page": ['2']}), const(stub_json_response(feed2_str))), (self.svc_intent({"page": ['3']}), const(stub_json_response(feed3_str))), ] entries, params = perform_sequence( seq, cf.read_entries( self.service_type, self.url, {}, self.directions[rel])) self.assertEqual( [atom.summary(entry) for entry in entries], ["summ1", "summ2", "summ3", "summ4"]) self.assertEqual(params, {"page": ["3"]})