Zephyr scale server: uploading test results to Zephyr Scale via the automation API - pytest

I'm using Zepyhr Scale Server and I would like to upload to Zephyr the results of my automation testsuite made with pytest. I've tried this POST request:
post(url="https://{my-jira-host}/rest/atm/1.0/automation/execution/{projectKey}", auth=({my_username}, {my_password}), files={"file":open("test_results.zip","rb")})
but it doesn't work because the response is "errorMessages":["Invalid Custom Format JSON file"]}.
I'm uploading a zip file containing one xml file generated with
pytest --junitxml=output/junitxml_report.xml
as it's explained here https://support.smartbear.com/zephyr-scale-cloud/docs/test-automation/pytest-integration.html
I've tried to make the same request with an API client (Postman) and the error is "Invalid ZIP file", even if I fail the authentication with a wrong username or even if I upload the xml file only.
Maybe someone does the same thing and could help me? I'm a newbie :) thanks!

I found the API documentation lacking, but I managed to enumerate many endpoints.
I've bundled them in a nodejs lib, it won't be of use for your Python script, but the endpoints will be the same... Maybe they can help you on your way.
https://www.npmjs.com/package/#dbouckaert/zephyr-scale-reporter
Example: get all testcases for a project
/**
* This function will get all testcases for a certain project and add them to variables.testCasesArray
* #returns {void}
*/
export const getAllTestcases = async (): Promise<void> => {
await request(variables.url)
.get(`/rest/tests/1.0/project/${variables.projectId}/testcases`)
.auth(variables.username, variables.password)
.expect(200)
.then((res) => {
variables.testCasesArray = res.body.testCases;
});
};

Related

Attempting a Google Drive partial Download (Flutter) throws a header error

Here's my issue :
I am creating a small application based on audio files stored on Google Drive, in Flutter.
I am using the drive api to make my requests, with these scopes in my google sign in :
GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: [
'email',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/contacts.readonly',
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/docs',
'https://www.googleapis.com/auth/drive.appdata',
],
);
I have an auth element and handle signing in and out. Until then, no issues.
I can also request my files with an implementation looking like this :
var api = widget.api.getAPI();
var files = await api.files.list($fields: '*');
This works perfectly, and so does :
var api = widget.api.getAPI();
var files = await api.files.get("myFileId"); (//does get a file instance)
But since I'd like to retrieve some of the Metadata included in my audio files, and since the drive API doesn't natively support extracting audio metadata and sending it as a google metadata, I thought I'd extract it with a partial download on the file itself.
Here's the catch : I can't seem to get the partial download to work.
Based on the doc, I thought the implementation would look something like this :
import 'package:googleapis/drive/v3.dart' as ga;
(...)
try {
var partiallyDownloadedFile = await api.files.get(
"myFileIdHere",
downloadOptions: ga.PartialDownloadOptions(ga.ByteRange(0, 10))); //should get a ga.Media instance
print("partial download succeeded");
print(partiallyDownloadedFile);
//(...do stuff...)
return;
} catch (err) {
print('Error occured : ');
print(err);
return;
}
But this always throws this error :
ApiRequestError(message: Attempting partial download but got invalid
'Content-Range' header (was: null, expected: bytes 0-10/).)
I tried using it on Wav files, but also MP4 files. The error is always the same, which leads me to believe it's my implementation that's somehow wrong, but I'm not sure what I'm supposed to do to fix it. Is it my request missing the header ? The response not including it ?
While very clear, that error doesn't help me troubleshoot my issue at all. I can't seem to find any documentation on how to conduct a partial media request. I haven't found any example projects to compare it with.
PartialDownloadOptions does not have much documentation.
I could handmake a partial request through the download links (which is how I can read the music to begin with) but the drive API supposedly allows this. Could anyone familiar with Flutter/the google APIs help me correct my implementation?
EDIT : This was due to an error within the commons library in the Dart google APIs, and was (at the very least superficially) fixed thanks to Kevmoo's efforts : https://github.com/google/googleapis.dart/issues/462
It was a Content-Range error happening due to browser specifications with access-control-expose-header compared to iOS/Android-type requests that typically expose every header.

Flutter integration test - how to load a JSON file?

I am writing a Flutter integration test with a mock client that returns a JSON response for each of the REST endpoints my app calls.
These JSON responses are stored in separate JSON files, but I am unable to access the files when the test is running.
I've tried loading the files by creating and reading a new file object. Flutter: how to load file for testing but it could never find the file.
I also tried putting my JSON files into assets. This worked, but also resulted in the test JSON files being bundled when I built the APK.
Simplified Mock Client:
MockClient integrationMockClient = MockClient((request) async {
switch (request.url.toString()) {
case 'https://staging.company.com/api/123':
return Response(readJsonfile('myJsonFile.json'), 200);
Simplified integration test main function - passes mock client in. test_driver/app.dart
void main() async {
enableFlutterDriverExtension();
final app = await initializeApp(
integrationMockClient
);
runApp(app);
}
When I try and read a file it can never find it. Possible because flutterDriver runs the 'real app' with no access to files stored in test directories.
How can I access a JSON file from an integration test without it being bundled in production code/APK?
I encountered similar issues accessing file resources using flutter driver for integration tests. What I did as a workaround was to parse the JSON response directly, instead of storing the JSON response as a file.
Here's a sample that you can try out. This uses https://jsonplaceholder.typicode.com as its endpoint sample.
test('Test http', () async {
final file = await http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));
final json = jsonDecode(file.body.toString());
print('json contents: $json');
print('userId: ${json['userId']}');
final userId = json['userId'];
expect(userId, 1);
});
Put JSON into String variable, like this. const String objectJson = """{JSON}""";
Wrap your JSON with a triple quotation mark """
and use it on integration tests, instead of reading it from a file

How to pass parameter to SOAP request in SOAPUI

I'm newbie to soap and soapui, I'm trying to create a test case in which I will send the same request(XML attachment) many times(about 500), the problem is that each time I need to increment/change a value in the request (the id).
Therefore, I wonder if the is a way to pass this parameter to the attached xml file ? or if there is another ways to do the test case.
Thank you in advance
UPDATE
here is the content of the xml file :
<mod:sendMSG xmlns:mod="http://test.soap/service/model">
<id>${#Project#parameter1}</id>
<date>2016-04-03T04:03:00</date>
<infos>
<firstName>AT </firstName>
<lastName>AT </lastName>
......
</infos>
</mod:sendMSG>
which is included in the soap request, ass shown in the following image :
Test steps:
Groovy Script
SOAP Request (disabled)
I disabled the SOAP Request because it runs once more after the script has already looped the request x times.
Groovy script:
int loops = 500;
for ( iter in 1..loops ) {
//Overwrite the 'parameter1' property at project level
testRunner.testCase.testSuite.project.setPropertyValue("parameter1", iter.toString())
//log.info("iter: " + testRunner.testCase.testSuite.project.getPropertyValue("parameter1"));
// Run the teststep named 'SOAP Request'
def testStep = testRunner.testCase.testSteps['SOAP Request'];
testStep.run( testRunner, context )
}
Now you should be able to run your TestCase. I recommend saving your project before, I had some problems with SoapUI crashing on me when running.

Downloading from google cloud storage with php

Is there a way to achieve downloading via. the google-php-api? I have tried the following:
using the medialink and trying to curl the object (Returns "Login Required")
reading the guzzle response stream (comes back empty even though all the headers have the correct data)
I am able to see everything but the body of the file via. the API.
Edit:
I am of course able to download the file via the medialink, taken it is set to public - however that will not work for this situation.
The solution is as follows...
You must make an authorized HTTP request, to do this you must:
$object = $service->objects->listObjects(BUCKET, OBJECT);
$http = $client->authorize();
$request = new GuzzleHttp\Psr7\Request('GET', $object->getMediaLink());
$response = $http->send($request);
$body = $response->getBody()->read($object->getSize());
The above is a small snippet but the jist of what you need to get the contents of a file.

How to post a file in grails

I am trying to use HTTP to POST a file to an outside API from within a grails service. I've installed the rest plugin and I'm using code like the following:
def theFile = new File("/tmp/blah.txt")
def postBody = [myFile: theFile, foo:'bar']
withHttp(uri: "http://picard:8080/breeze/project/acceptFile") {
def html = post(body: postBody, requestContentType: URLENC)
}
The post works, however, the 'myFile' param appears to be a string rather than an actual file. I have not had any success trying to google for things like "how to post a file in grails" since most of the results end up dealing with handling an uploaded file from a form.
I think I'm using the right requestContentType, but I might have missed something in the documentation.
POSTing a file is not as simple as what you have included in your question (sadly). Also, it depends on what the API you are calling is expecting, e.g. some API expect files as base64 encoded text, while others accept them as mime-multipart.
Since you are using the rest plugin, as far as I can recall it uses the Apache HttpClient, I think this link should provide enough info to get you started (assuming you are dealing with mime-multipart). It shouldn't be too hard to change it around to work with your API and perhaps make it a bit 'groovy-ier'