Dynamic fields passed in Resource - django-rest-framework

I'm trying to handle dynamic CSV, meaning I have no control over the format of the headers so my Idea is the frontend will parse the CSV first get the headers and pass it along with the file. So my question how should I handle dynamic fields using django-import-export?

Related

In jmeter want to add 2 parameter into body(Json).Record and replay is working,but want to pass 2 parameter in Json,so can pass values from CSV file

I am working on one of the JMeter script and I have one question regarding an item. If I want add both the parameters into body data(Json format) then how can I do? When I record and play it is working fine but I want to modify the script by passing both parameters in Json format, so that I can pass the values from CSV file
Please see screenshot:
One of the value is Json format and other one is button. I know how to pass the multiple values but here one of the parameter is button.
I have passed both the parameters into body data and tried replaying the script but not able to do it with the button parameter. please help here
Your screenshot is not visible.
JMeter doesn't know anything about HTML buttons, it acts on HTTP protocol level
If you want to have the possibility to parameterize any data which is being sent by JMeter just put this data into the CSV file and replace the recorded hard-coded values with the variables defined in the CSV Data Set Config.
Use Debug Sampler and View Results Tree listener combination to see what are the JMeter Variables values and how does request look like. You will also have the possibility to compare the recorded and parameterized requests.

How to maintain json data for multiple testcases in robotframework

please suggest me how to maintain json POST data(for API testing) for multiple test cases in robotframework based on your past experience. Whether to maintain it in excel and separate json files?
If you have a "template" JSON and need to parameterize individual values you can use CSV Data Set Config for supplying these values, you request would be something like:
{
"parameter1": "${value1}",
"parameter2": "${value2}"
}
where these ${value1} and ${value2} will be populated from CSV data set config
If you need to send totally different JSON with each request it will make sense to put all the payload files into some folder and then:
Use Directory Listing Config to read the file paths into JMeter Variables
Use __FileToString() function for reading the file content into the HTTP Request body data
It's better to store POST data as separate JSON file. Here is how I would store:
- testdata
- json
- sample_file1.json
- sample_file2.json
There is advanced option if you don't like to store pre-defined JSON file for each test case but rather to generate one. You can use JSON Schema to generate JSON files, all you have to do is to create schema and generate JSON files based on that schema.

Passing whole body as a variable to a POST request

I'm trying to create a simple stress test using JMeter. I have mostly GET requests and a couple POST requests. My main goal is to make this test as reusable as possible. I want to implement it in a way that the user would have to provide a CSV file with the following headers:
method;path;postBody
The values would look something like:
GET;/path/to/resource;''
POST;/path/to/resource;'{"key":"value","key":"value","key":"value"}'
Now POST (PUT, PATCH etc ..) bodies differ from one request to another. Providing ${postBody} to Body Data tab does not work "${postBody}" as well.
Is there a way to achieve this? Command line solutions are more than welcome as well.
EDIT: To clarify, I'm using the UI interface. When I input ${postBody} in the Body Data tab the UI complains. When switching from the Body Data tab to another one I get the following prompt:
Remove "'" around the request and it should work.
Regarding the warning you get, it is not an error, it is just that in JMeter those 2 tabs are exclusive:
Parameters tabs is for input of parameters in the form as name=value
Body data is for your kind of requirement
So can you test my hypothesis which is to remove the quote around the request in CSV file ?
If it still fails, please show the logs.
You can remain in Body Data tab,
Add after pathPost your optional query parameters for GET request:
${pathPost}?${getPramaters}
Don't worry about the ? it's just seperate path from parameters
Also consider changing variable name to path, more suitable because it can be POST.
In JSON , seperate between values while in CSV default is also ,
I suggest you can your CSV delimiter, In CSV Data Set Config Choose different Delimiter as ; and add your data in CSV accordingly (remove extra ' characters):
POST;/path/to/resource;{"key":"value","key":"value","key":"value"}
Notice: Allow quoted data keep default value False

How can I log the value of a variable sent in an HTTP Request sent from JMeter, if the value was first read in from a csv file

I would like to read the exact value of a variable I use to pass through an HTTP Request. I first read in many values of variables using the CSV Data Set Config. For the username, it is in the form of an email address. So, I have a variable called "email" in the Data Set Config. In the actual HTTP Request, for "name", I call it "username". For the "Value" field for this same "username", I added a time() function to it like this so I would end up creating unique users in my tests:
${email}${__time()
When I view the "Request" in a View Results Tree, I can see my parameter is listed correctly:
username=email1%40email.com1390854377360
I do not care if this is correct in real world terms. I already know that is not a valid email. That is ok for now.
What I want to know is how can I log that email that I just created on the fly? I would like to not have to pull in the whole request every time also and then use some type of Regular Expression extractor. It just seems like there should be an easy way to do this.
I think there are 2 ways,
Beanshell Pre/Post processors : you can write custom code in which you can log all your variables in some custom log file
Simple data writer : you can configure it and check save url,save field names,save response data field checkboxes that will give you complete data but in that later postprocessing on result file is required to get all usernames (email in your case).
first approach is easier and allows you create your own logging format(easy to retrieve and use somewhere else).
second approach is somewhat tedious and requires post processing.

django dynamic ajax form

i'm trying to write csv importer for my project that i can use for any model, it should be a wizard that first you upload the csv file, in the second step it generates a form based on the csv file for mapping csv field with database fields, on the first call to the form i should specify the model for the mapping, that can be a hidden input in the first form. on the other hand i want to use ajax for all the process, i don't know what to use exactly so it would be a complete reusable module and also with writing less java-script also how should i generate the second dynamic form. thanks.
Submit the first form through ajax. The request will contain (hidden) which form to use, so just render that form (based on a ModelForm). Make a template for each possible form(model) and return the rendered template accordingly.
The ajax call will remove the first form, on success and replace it with the response (which will be the second form).

Resources