From f6848f0f31c484ea5c8453f0c46af96f91d7b451 Mon Sep 17 00:00:00 2001 From: Sripriya Date: Fri, 26 Aug 2016 16:03:27 -0700 Subject: [PATCH] Modify MyURLComparator to handle deep match on URL MyURLComparator equals method is enhanced to perfom url comparison based on url parts such as scheme, netloc, path and query instead of raw string comparison. pagination methods are modified to wrap the url requests with pagination params within MyURLComparator objects. Change-Id: I69b835dce64d662d1af6a14556fb8281e3b04d63 Closes-Bug: #1617480 --- tackerclient/tests/unit/test_cli10.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tackerclient/tests/unit/test_cli10.py b/tackerclient/tests/unit/test_cli10.py index 64271ecd..261bc691 100644 --- a/tackerclient/tests/unit/test_cli10.py +++ b/tackerclient/tests/unit/test_cli10.py @@ -21,6 +21,7 @@ import cStringIO import fixtures import mox import six +import six.moves.urllib.parse as urlparse import sys import testtools @@ -85,7 +86,17 @@ class MyUrlComparator(mox.Comparator): self.client = client def equals(self, rhs): - return str(self) == rhs + lhsp = urlparse.urlparse(self.lhs) + rhsp = urlparse.urlparse(rhs) + + lhs_qs = urlparse.parse_qsl(lhsp.query) + rhs_qs = urlparse.parse_qsl(rhsp.query) + + return (lhsp.scheme == rhsp.scheme and + lhsp.netloc == rhsp.netloc and + lhsp.path == rhsp.path and + len(lhs_qs) == len(rhs_qs) and + set(lhs_qs) == set(rhs_qs)) def __str__(self): if self.client and self.client.format != FORMAT: @@ -491,9 +502,9 @@ class CLITestV10Base(testtools.TestCase): headers=mox.ContainsKeyValue( 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr1)) self.client.httpclient.request( - end_url(path % myid, fake_query, format=self.format), 'GET', - body=None, - headers=mox.ContainsKeyValue( + MyUrlComparator(end_url(path % myid, fake_query, + format=self.format), self.client), 'GET', + body=None, headers=mox.ContainsKeyValue( 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr2)) self.mox.ReplayAll() cmd_parser = cmd.get_parser("list_" + resources) @@ -523,8 +534,8 @@ class CLITestV10Base(testtools.TestCase): headers=mox.ContainsKeyValue( 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr1)) self.client.httpclient.request( - end_url(path, fake_query, format=self.format), 'GET', - body=None, + MyUrlComparator(end_url(path, fake_query, format=self.format), + self.client), 'GET', body=None, headers=mox.ContainsKeyValue( 'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr2)) self.mox.ReplayAll()