Pact-python : Consumer pacts for POST calls are failing - python-3.x

I am trying to create consumer side pacts for a POST end point using the pact-python library. But it's failing with the error saying "Missing requests".
Here't the client code which makes the POST API call
def create_user(request):
return requests.post("http://localhost:1234/user", data=request).json()
Here's my test class which create the consumer pacts.
class TestUserConsumer(unittest.TestCase):
def test_user_creation(self):
request = {
"name": "Micky",
"age": 0
}
response = {
"id": 1232,
"name": "Micky",
"age": 0
}
pact = Consumer("user_client").has_pact_with(Provider("user_server"))
pact.start_service()
pact.with_request(
method='post',
path='/user',
body=request
).will_respond_with(status=200, body=response)
with pact:
create_user(request)
pact.verify()
pact.stop_service()
The test failed with the following error.
line 268, in verify
assert resp.status_code == 200, resp.text
AssertionError: Actual interactions do not match expected interactions for mock MockService.
Missing requests:
POST /user
The create_user(request) is getting executed, but still the interactions are not recorded on the pact mock server.
Note : The GET API pact creations are working. Only the POSTs are failing.
Appreciate the help.

I figured out the problem. I was not converting my dictionary to json before making the request. Hence the request body format was incorrectly send. This caused a failure on the mock server while verifying the pact.
I also noticed that, the logs didn't get generated initially. This was due to my assertions added before stopping the server. Since the assertions got failed, the pact mock server didn't get stopped. Hence the logs are not generated at all. Once I stopped the server, the logs got added and that helped me to identify the problem.

Related

Dialogflow Webhook call failed. Error: [ResourceName error] Path '' does not match template

I am using Dialogflow ES and once I got the webhook setup, I haven't been having issues. But after a few months, I just started getting a random error. It seems to be inconsistent as in sometimes I get it for a specific web call and other times it works fine. This is from the Raw API response:
"webhookStatus": {
"code": 3,
"message": "Webhook call failed. Error: [ResourceName error] Path '' does not match template 'projects/{project_id=*}/locations/{location_id=*}/agent/environments/{environment_id=*}/users/{user_id=*}/sessions/{session_id=*}/contexts/{context_id=*}'.."
}
The webhook is in GCP Functions in the same project. I have a simple "ping" function in the same agent that calls the webhook. That works properly and pings the function, records some notes in the function log (so I know the function is being called), and returns a response fine, so I know the webhook is connected and working for other intents in the same agent before and after I get the error above.
Other intents in the same agent work (and this one WAS working), but I get this error now. I also tried recreating the intent and I get the same behavior.
The project is linked to a billing account and I have been getting charged for it, so I don't think it is an issue with being on a trial or otherwise. Though the Dialogflow itself is in "trial", but the linked webhook function is billed.
Where can I find what this error means or where to look to resolve it?
After looking at this with fresh eyes, I found out what was happening.
The issue was a mal-formed output context. I was returning the bad output context sometimes (which explained why sometimes it worked and sometimes it didn't). Specifically, I was returning the parameters directly into the output context without the output context 'name' or 'parameters'. Everything looked like it was working and I didn't get any other errors, but apparently, when Dialogflow receives a bad web response, it generates the unhelpful error above.

How to poll request status in aws-cli?

I am updating a QuickSight data source in my aws account.
aws quicksight update-data-source --cli-input-json file://update-stag-data-source-request.json --output json
And I get the following response:
{
"Status": 202,
"Arn": "arn:aws:quicksight:eu-west-1:<my-aws-account-nr>:datasource/099676d0-99e3-44d7-b581-d6e532e72961",
"DataSourceId": "099676d0-99e3-44d7-b581-d6e532e72961",
"UpdateStatus": "UPDATE_IN_PROGRESS",
"RequestId": "1d304a80-e507-46c3-acb3-237a58237e77"
}
So currently the status of this request is "UPDATE_IN_PROGRESS", but how do I track the status afterwards?
I need to do it, because it seems that the update fails eventually, for reasons unknown. I know that, because I still see the old setup of the data source several minutes later. I believe, if I knew the eventual request status it would help me to debug the issue.
Check the command describe-data-source, it will return the DataSource.Status and, in case of any failure, you can check inside DataSource.ErrorInfo.Message.

is ZONE_RESOURCE_POOL_EXHAUSTED a googleapiclient.errors.httpError?

I am using the googleapiclient(Python) APIs like images().get(), images().insert() etc to list images, create VM instances etc
There were several ZONE_RESOURCE_POOL_EXHAUSTED errors from google cloud last month which caused the following exception in my code
Exception: {'errors': [{'code': 'ZONE_RESOURCE_POOL_EXHAUSTED', 'message': "The zone 'projects/<project-name>/zones/us-central1-b' does not have enough resources available to fulfill the request. Try a different zone, or try again later."}]}
I want to handle this error in my code by sending a unique error code from my server to the client to retry this request after sometime since the error is transient.
I am not able to reproduce this error willfully for the same reason...that its transient
I checked the googleapi code on GitHub at https://github.com/googleapis/google-api-python-client
but couldn't find ZONE_RESOURCE_POOL_EXHAUSTED
I need to verify if its an exception of type "HttpError" or some other class and then can handle it in my code
I am already handling exception of type googleapiclient.errors.HttpError in my code by printing an error message and raising it as urllib.error.HTTPError (the server sends the code e.resp['status'] for this case to the client)
except HttpError as e:
printf('Failed to create %s: %s\n', instanceName,
e._get_reason())
raise HTTPError(
None, int(e.resp['status']), e._get_reason(), "", None)

NodeJS Azure Functions used as a Messenger Bot return an mscorlib error

I'm trying to use Azure Functions as a Messenger bot server using a Generic Webhook. The problem I'm running into is that even running this simple code (most of it is commented out to try & figure out the issue) results in an error (below the code):
module.exports = function (context, data) {
context.log('Webhook was triggered!');
context.res = {
status: 403,
body: ''
}
context.done();
}
Function completed (Failure,
Id=fb0f2178-8b98-4163-a5ae-7ab68eff47cd)
Exception while executing function: Functions.StriverMessenger.
mscorlib: The given key was not present in the dictionary.
Why is this error occurring and how do I get this to work? If I fake out the querystring entries in the run mode inside Azure, the function appears to work as coded. The error occurs when trying to send a Verify request to the Azure Function from Facebook Developer, specifically in Messenger's Webhook setup.
This happens when an empty (or non-json) body is sent to a Function with type WebHook. The handling is poor, and we are improving it per https://github.com/Azure/azure-webjobs-sdk-script/issues/849. This should be deployed within a week and you can then verify.

Browserstack reports successful even when test fails in Nightwatchjs

I just started using nightwatch with browserstack and I'm noticing that when we get a failed test, nightwatch registers the failure, but browserstack does not.
sample test I am using.
Also I am using free trial version of BrowserStack.
My question is:
Are there any ideas how to tell browserstack when a test run failed ?
From BrowserStack doc:
REST API
It is possible to mark tests as either a pass or a fail, using the
following snippet:
var request = require("request");
request({
uri: "https://user:key#www.browserstack.com/automate/sessions/<session-id>.json",
method: "PUT",
form: {
"status": "completed",
"reason":""
}
});
The two
potential values for status can either be completed or error.
Optionally, a reason can also be passed.
My questions are:
How I can get 'session-id' after test execution ?
What if I can see "completed" status in dashboard already ?
A session on BrowserStack has only three types of statuses:
Completed, Error or Timeout. Selenium (and hence, BrowserStack) does not have a way of understanding, if a test has passed or failed. Its by the multiple assertions in your tests that appear on your console, that you infer if a test has passed / failed. These assertions however, do not reach BrowserStack. As you rightly identified, you can use the REST-API, to change the status of the session to 'Error', if you see a failure in your console.
I would suggest fetching the session ID of the test as the test is being executed, since fetching the session ID after the test execution is a lengthy process. In Nightwatch, you can fetch session ID as follows:
browser.session(function(session) {
console.log(session.sessionId);
});
Yes, you can certainly change the status of the session once it is completed. That's where the REST-API comes to help!
If you came here searching for a solution in Python, you could use
requests.put(
"https://api.browserstack.com/automate/sessions/{}.json".format(driver.session_id),
auth=(USERNAME, ACCESS_KEY),
json={"status": "failed", "reason": "test failed"})

Resources