Route to a CSV file? - ruby

I am writing query output to a CSV file in a folder called 'reports_output' inside my 'report_runs' views folder. The file names need to be generated based upon the name given by users running reports and other parameters like current time etc. I have two issues:
How to generate unique file names using Time.now converted to string of numbers (like version numbers in db/migrate) ? and
How to do correct routing to all these .csv files?
I was able to write files with simple names e.g. Item_List.csv below, but not been able to view the files by clicking on the url to the file in my show view in browser. The error says :
No route matches "/report_runs/report_outputs/Item_List.csv"

1: You can generate a filename that includes the current time using simple string interpolation and you can format the string with Time#strftime:
file_name = "item_list#{Time.now.strftime('%Y%m%d%H%M%S')}.csv"
2: If you want to serve static assets like your .csv files then you can write them to the public folder. So for example if you create a file in public/report_runs/report_outputs/Item_List.csv it will be accessible from the path given in your example.

If you generate the CSV on the fly in the controller, then you can route to it like this:
<%= link_to item_list_path(:format => "csv") %>
Assuming that your controller is ItemList.

Related

Jmeter - CSV Data Config file name - Modify at RunTime

How can I change the filename of the CSV DataConfig at run time in the jmx file.
We have a logic in a java class which would create a dynamic file name and this
needs to be configured as the filename in the CSV DataConfig.
I am using Jmeter 4.0
Regards
You could use a variable / property name in the CSV data set config
here filename could be the name of the file or complete path of the file itself could be used as a variable.
Remember that CSV Data set config element gets initialized first - so filename should be a User defined variable / could be a property passed to JMeter. I would prefer a property.
Do note that You can not keep on changing the CSV data set config element filename in a test once it started. That means one CSV Data set config element can be used for 1 CSV file only. We can not modify!!
You cannot as CSV Data Set Config is a Configuration Element therefore it's executed before anything else. If you need to read the data from different files as the test goes by consider using JMeter Functions instead, the most suitable ones would be:
__StringFromFile() - returns the next string from the given file each time it's called
__CSVRead() - reads a value from CSV file. The function not only supports using dynamic file names, moreover, you can provide even multiple input files as well.

How to hit parameterized url in Apache Jmeter?

This is my test URL " http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id={Email} "
I want to hit the url 1500 times per second , and want to change the "{Email}" with real value in each iteration.
How it's possible please give me a step by step guide.
Considering that you need to pass the emails from the external file, the most efficient way that we are using in software testing companies is to pass the variable from .csv or .txt files using 'CSV Data Set Config' element of the JMeter.
Please find the steps that you need to follow:
Add a 'CSV Data Set Config' element from 'Config Element' by right-clicking the thread group
Set Filename field with complete path to your .csv or .txt file that contains your emails
Set Variable field as 'Email' [This variable name should be same as you set in your url request]
Ignore first line to False
Set other fields as per your requirement
Now add HTTP Sampler in your Thread Group and set the Protocol, Server Name, Method & Path as instructed in the screenshot:
Create .csv or .txt file and add all emails separated by new line:
Hope this answer is useful.
You can use the CSV Data Set Config. Put all your email credentials in the CSV file and make sure you have put this CSV file in your JMeter /bin directory.
Add a CSV dataset config in your test plan. Your CSV dataset config should be like:
Now in your thread group, define the number of threads you want to execute and then in your sampler put the path as follows:
http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id=${Email}
Depending on where do your emails live there are following options:
If they are in a text file, each email on a new line you can use __StringFromFile() function like:
If they are in a database you can use JDBC PreProcessor to fetch the data from the database table column and put your request under ForEach Controller
If you need to provide just some random characters you can use __RandomString() function.
More information: JMeter Parameterization - The Complete Guide

Uploading files to a web service into multiple folders using Jmeter

Just wanted to know if there is a better way to do this.
I am uploading multiple files to different folders in a web service.
Currently, I have got all the paths for the files being uploaded written in a CSV with their location to where they need to be uploaded to. (This currently works)
The files being uploaded do have a similar name to the location to which it will be sent to e.g. File A to Folder A, File B to Folder B.
Is there a better way in which I can achieve the same thing but in a more file name to match similar folder name without giving the location in a CSV file?
If your filename has a pattern to decide to which server it should upload to,use beanshell preprocessor to finalise the folder name.
For example - File A to be uploaded to Folder A,your preprocessor sample code can be like
String file=vars.get("fileName");//filename variable holds file names
if(file.charAt(file.length()-1)=='A')//checks the whether last char is A
{
vars.put("foldertobeUploaded","Folder A");
}
else
{
vars.put("foldertobeUploaded","Folder B");
}
and use ${foldertobeUploaded} wherever you want to use in sampler.
JMeter comes with If Controller where you can define a condition. If condition is true, If Controller's child(ren) sample(rs) will be executed.
Something like:
If Controller: condition "${someJMeterVariable}".endsWith("A")
HTTP Request to put file into Folder A
If Controller: condition "${someJMeterVariable}".endsWith("B")
HTTP Request to put file into Folder B
etc.
References:
JavaScript String endsWith() Method
How to Use JMeter's 'IF' Controller

How to determine the file type when a document is pulled from documentum

Which attribute can be used to pass the File Name while ingesting a document?
How to determine the file type when a document is pulled from Documentum using DFC API
Once a file is uploaded to Documentum, it "loses" its filename. A document is linked to a content object, which is again linked to the file itself on a filestore.
There are ways to get hints about the original filename and/or file extensions:
Find the Content ID by looking at i_contents_id, and look at that object's set_file attribute. Normally, this string will contain the full path to path (including filename) of the original file, but there are no guarantees.
If storage extensions are on (yes, they're on by default), you could use the following API command to get the file extension: getpath,c,<doc_id>
The document's a_content_type links to the name attribute of a dm_format object. Look at that object's dos_extension attribute to see the registered file extension for that given format (there is no guarantee that this was the original file extension, however).
As for which attribute should contain the filename, there is no clear answer. It's all up to the client. Normally, using object_nameshould suffice, or you could create a custom type with a custom attribute if the original filename is very important to you.
File in Documentum repository don't need to have document names that is originating from file that was uploaded from file system.
When you export document via export action with WDK application, i.e. Documentum Administrator or Webtop exported file will have name based on the value that was place in object_name property of that specific object.
File type of the content that is related to sepecific document object in repository is written in attribute a_content_type. Values in this attribute are internal Documetnum notation but names are intuitive. Check this question for more info or google.

ASP.NET MVC 3 Returning .csv file from controller

I want to return a .csv file from an ASP.NET MVC 3 ActionResult in the controller. I've found other examples of people doing this out on the web, but it seems like they have an ASP data structure that they are converting to csv.
My situation is a little different. I actually have a file on the local drive called myfile.csv. I want to return the file so the user can download it as a .csv.
Here is my code:
public ActionResult GetCSVFile()
{
return File(service.initiateCsvGeneration(1), "text/csv");
}
initiateCsvGeneration returns a string with a path to the filename. My filename already has the .csv extension and it is already in a comma delimited format. For some reason it is chopping of the .csv extension in my filename. Instead of allowing the user to download it as myfile.csv, it makes them download it as myfile although the actual disk file has the .csv extension and it is also present in the string that is in initiateCsvGeneration.
What else could be wrong here?
You should explicitly specify the desired file name - then your users will be able to see it in download dialog:
return File(service.initiateCsvGeneration(1), "text/csv", "myfile.csv");

Resources