PyRal Rally Specific queries work but generic queries not returning data - rally

When I use the PyRal get() function no results are returned, but if I use specific built-in get functions (e.g., getProjects(), getWorkspaces()) all data is returned correctly. Am I using the general get() incorrectly or do I have a configuration issue?
For the setup:
import sys
from pyral import Rally, rallyWorkset
server, user, password, apikey, workspace, project = <appropriate values>
rally = Rally(server, user, password, apikey=apikey, workspace=workspace, project=project)
These calls respond correctly (i.e., expected data returned):
workspacesAll = rally.getWorkspaces()
projectsAll = rally.getProjects(workspace=workspace)
No data returned for this call, no errors. The User Story exists in Rally.
query_criteria = 'FormattedID = "US220220"'
response = rally.get('HierarchicalRequirement', fetch=True, query=query_criteria)
Have also tried using "UserStory" instead of "HierarchicalRequirement" and other query criteria all without success.

It will work if you go thru all Projects (not parent):
query_criteria = 'FormattedID = "US220220"'
response_req = rally.get('HierarchicalRequirement', fetch=True, projectScopeDown=True, query=query_criteria)
response = response_req.next()
print response.details()

Related

Could I get some help on changing auth tokens mid test? [duplicate]

In my framework I have headers.js file. I am calling that js file on background of every feature file using the command * configure headers = read('headers.js'). This working as expected, some scenarios I need to change the 'client-id' value. For example headers.js has a client-id=xyz, I need to change client-id=abc for couple of scenarios rest all are using client-id as xyz (my headers have 20 different values, I don't want to write that in require feature files) Is there any way to modify one value from the headers.js file and use that as a header for the request?
The configured headers always is the last to be applied. So the best solution for you is to create a second headers-xyz.js and for only those needed scenarios do * configure headers = read('headers-xyz.js').
It is up to you to refactor the js code so that you can re-use most of it. For example, this might work:
function() {
var fun = karate.read('headers.js');
var res = fun();
res['client-id'] = 'xyz';
return res;
}

No such table Django Database

So I created a model for storing credentials from Gmail users.
I wanted to make migrations but it says that there is no such table:
django.db.utils.OperationalError: no such table: mainApp_credentialsmodel
My models:
from django.db import models
# Create your models here.
from django.contrib.auth.models import User
from django.db import models
import json
class CredentialsModel(models.Model):
id = models.ForeignKey(User, primary_key=True,on_delete=models.CASCADE)
credential = models.CharField(max_length=1000)
Calling that model for checking authorization:
SCOPES = 'https://www.googleapis.com/auth/gmail.readonly'
store = CredentialsModel.objects.all()
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('mainApp/client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('gmail', 'v1', http=creds.authorize(Http()))
python manage.py makemigrations
If that error keep happening, check your migrations folder and check the files inside. Also check If your database is online, in case you have a database online, I've got this problem last week, but it was a problem with azure.
In last case I would create the table (model) again, changing the name to something similar, but If you have a significant amount of data in that table, then I think you can't do that.
It looks like your authorization code - including the query on CredentialsModel - is at module level. This means it runs when the module is imported, which happens before the migration has had a chance to run.
You must ensure that any database-accessing code is inside a function or method and is not invoked globally.

nexus3 api how to search component from groupId and artifactId

I search a way to request components or assets from groupId and artefactId.
Documentation provides any help about how to create this request.
This doc has been a great help.
Unfortunately, it's not enough to resolve my need and I try to create query to request components from groupId and artefactId like that:
Query.builder().where('group = ').param('###').and('name = ').param('###').and('version = ').param('###).build()
Last time I played my script it throwed java.lang.StackOverflowError. After increasing memory, I had the same result. It seems there is too much components to return, but in my nexus repository there's only one component with such group, name and version.
What's wrong with this query?
Is there someone pass this difficulty (it was so easy with nexus2 and rest api!) and retrieve components information with a groovy script?
Here is the script I successfully uploaded and use. You may easily add version to your requests - the parameter will be, for example, "snapshots-lib,com.m121.somebundle,someBundle,7.2.1-SNAPSHOT,all". As you may see, I decided to filter the sequence locally, because did not find the way to specify in query version parameter.
{
"name": "listgroup",
"type": "groovy",
"content": "import org.sonatype.nexus.repository.storage.Query;
import org.sonatype.nexus.repository.storage.StorageFacet;
import groovy.json.JsonOutput;
def repositoryId = args.split(',')[0];
def groupId = args.split(',')[1];
def artifactId = args.split(',')[2];
def baseVersion = args.split(',')[3];
def latestOnly = args.split(',')[4];
def repo = repository.repositoryManager.get(repositoryId);
StorageFacet storageFacet = repo.facet(StorageFacet);
def tx = storageFacet.txSupplier().get();
tx.begin();
def components = tx.findComponents(Query.builder().where('group = ').param(groupId).and('name = ').param(artifactId).build(), [repo]);
def found = components.findAll{it.attributes().child('maven2').get('baseVersion')==baseVersion}.collect{def version = it.attributes().child('maven2').get('version');\"${version}\"};
// found = found.unique().sort();
def latest = found.isEmpty() ? found : found.last();
tx.commit();
def result = latestOnly == 'latest' ? JsonOutput.toJson(latest) : JsonOutput.toJson(found);
return result;"
}
okee,
in fact my needs are :
i want to retrieve last release version and its date of a component by group and artefact.
I definitely leave the groovy API option.
A way i found consists in use of extdirect api. This "rest" api is used by nexus frontend to communicate with backend. No documentation exists.
I do a call to extdirect api to retrieve all versions from a component by group and artefact. I parse the results to get the last version on a release (snapshot and releases).
It's not really good because this call retrieves all the versions on all repositories and could be huge.
Another call to extdirect api to find the release date from the component id of the last release version.
I hope someday nexus publishs official documentation of an useful rest api.

Issue in getting iteration data from rally API

I am using following url to get the iteration data from rally.
I then parse the json data received.
def query = URLEncoder.encode("(Project.Name contains \"1 Prime Infrastructure\")", "UTF-8")
def rallyURL = "https://us1.rallydev.com/slm/webservice/v2.0/iteration?query="+query+"&fetch=true&start=1&pagesize=200"
The issue is it giving 0 records. But when i change the name to some other project the data comes.
Probably it is because of the default workspace for my username and password. I want project data from different workspace.
I have access to all this workspace.
can someone tell how to set the workspace before making an api call so that i can get the iteration data ??
Thanks,
You can simply include a workspace parameter in your url to override the default:
&workspace=/workspace/12345
You can also always further refine your results to a specific project:
&project=/project/12345
Or to a specific hierarchy:
&projectScopeUp=true
&projectScopeDown=true

Recent changes to Rally C# REST API?

1) Earlier this week I was able to create defects and testcases using the Create method, which took 2 arguments at the time (a string and the DynamicJsonObject). However now, it needs three. I understand that one of these is now the workspace reference. How do I go about getting the workspace reference? For creating defects and testcases, I am using an empty string, and this seems to be working correctly for me. Is this to be expected?
2) For creating test case results, I am having a bit of trouble.
DynamicJsonObject newTCResult = new DynamicJsonObject();
newTCResult["Date"] = DateTime.Now.ToString("yyyyMMdd");
newTCResult["TestCase"] = "/testcase/11271454106";
newTCResult["Notes"] = "test";
newTCResult["Build"] = "13.1.0.90";
newTCResult["Verdict"] = "Pass";
CreateResult cr = restApi.Create(" ", "TestCaseResult", newTCResult);
As of right now, absolutely nothing is happening when I run this. I was able to do this successfully earlier this week (when I was able to use the Create method with two arguments). I feel that the problem is because I don't have a valid workspace reference. I followed the suggestion of another user in a similar question prior to this which worked for earlier, however now I am having this problem.
I was finally able to resolve this. It appears that the date field needs to be converted to UTC, so my code now looks something like this
newTCResult["Date"] = DateTime.UtcNow.ToString("o");
After making that small change results were working correctly.
It's somewhat surprising that Creates on Stories or Defects work with an empty string for a Workspace ref, although I suspect that on the server-side, the Webservices API is just using Default Workspace for the User of concern.
Either way, here's how you can get a ref to the Workspace of interest:
String myWorkspaceName = "My Workspace";
// Get a Reference to Target Workspace
Request workspaceRequest = new Request("workspace");
workspaceRequest.Fetch = new List<string>()
{
"Name",
"ObjectID"
};
workspaceRequest.Query = new Query("Name", Query.Operator.Equals, myWorkspaceName);
QueryResult workspaceQueryResults = restApi.Query(workspaceRequest);
var targetWorkspace = workspaceQueryResults.Results.First();
Console.WriteLine("Found Target Workspace: " + targetWorkspace["Name"]);
String workspaceRef = targetWorkspace["_ref"];
You can then use workspaceRef in your call to restApi.Create().