Skip to content

Commit

Permalink
Update test_sg_sync_function_tester.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Fujio-Turner committed Aug 24, 2024
1 parent 7da4ebe commit a6de214
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions test/test_sg_sync_function_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def test_httpRequest_put(self, mock_request):
headers={'Content-Type': 'application/json'},
auth=HTTPBasicAuth("bob", "12345")
)

@patch('requests.request')
def test_getChangesFeed(self, mock_request):
changes_feed = {
Expand All @@ -101,10 +102,13 @@ def test_getChangesFeed(self, mock_request):
mock_response.raise_for_status = MagicMock()
mock_request.return_value = mock_response

result = self.work.getChangesFeed(userName="bob", password="12345", channels="bob")
result = self.work.getChangesFeed(
userName="bob", password="12345", channels="bob"
)

self.assertEqual(result, changes_feed)
url = f"{self.work.sgHost}:{self.work.sgPort}/{self.work.constructDbUrl()}/_changes?filter=sync_gateway/bychannel&channels=bob"
url = (f"{self.work.sgHost}:{self.work.sgPort}/{self.work.constructDbUrl()}/"
f"_changes?filter=sync_gateway/bychannel&channels=bob")
mock_request.assert_called_once_with(
"GET", url,
json=None, headers={'Content-Type': 'application/json'},
Expand All @@ -123,7 +127,8 @@ def test_postPurge(self, mock_request):
result = self.work.postPurge(["foo"])

self.assertEqual(result, purge_response)
url = f"{self.work.sgHost}:{self.work.sgAdminPort}/{self.work.constructDbUrl()}/_purge"
url = (f"{self.work.sgHost}:{self.work.sgAdminPort}/"
f"{self.work.constructDbUrl()}/_purge")
purge_data = {"foo": ["*"]}
mock_request.assert_called_once_with(
"POST", url,
Expand All @@ -139,9 +144,13 @@ def side_effect(*args, **kwargs):
mock_response.raise_for_status = MagicMock()

if args[0] == "GET":
mock_response.json.return_value = {"_id": "foo", "_rev": "1-a", "channels": ["bob"]}
mock_response.json.return_value = {
"_id": "foo", "_rev": "1-a", "channels": ["bob"]
}
elif args[0] == "PUT":
mock_response.json.return_value = {"ok": True, "id": "foo", "rev": "1-a"}
mock_response.json.return_value = {
"ok": True, "id": "foo", "rev": "1-a"
}
elif args[0] == "DELETE":
mock_response.json.return_value = {"ok": True}
elif args[0] == "POST" and "/_purge" in args[1]:
Expand Down Expand Up @@ -199,7 +208,8 @@ def side_effect(*args, **kwargs):
auth=HTTPBasicAuth(self.work.sgAdminUser, self.work.sgAdminPassword)
),
unittest.mock.call(
"GET", f"{sgAdminUrl}/_changes?filter=sync_gateway/bychannel&channels=bob",
"GET",
f"{sgAdminUrl}/_changes?filter=sync_gateway/bychannel&channels=bob",
json=None, headers={'Content-Type': 'application/json'},
auth=HTTPBasicAuth(self.work.sgAdminUser, self.work.sgAdminPassword)
),
Expand Down

0 comments on commit a6de214

Please sign in to comment.