using send to validate my data from populate_page with - watir

I'm trying to use a hash of data that obtain from data_magic to set values on page, do a refresh and then use that same set of data to validate that the page loaded back with that which was set.
getting an error when trying to use the send
any pointers?
visit MyPage do |page|
my_data = page.data_for :address_set
page.populate_page_with my_data
page.refresh
#
# verify page loads with data set
keys = my_data.keys
keys.each do |key|
expect(send("page.#{key}")).to eq my_data[:key]
end
end

figured it out so sharing in case anyone finds of value. Found it helpful to build in some test of the page-objects being created.
my_data = page.data_for :address_set
page.populate_page my_data
page.refresh
# match the input with the screen refresh to ensure that save works
#
my_data.keys.each do |key|
expect(page.send("#{key}")).to eq my_data["#{key}"]
end

Related

Why do I fail to submit data to textarea with python requests.post()

I want to use the requests.post tool to automatically query domain name attribution on this websitea website,But the return value is always empty, I guess it is because the post method failed to transfer the data to the textarea
url = 'http://icp.chinaz.com/searchs'
data = {
'hosts':'qq.com',
'btn_search':'%E6%9F%A5%E8%AF%A2', '__RequestVerificationToken=':'CfDJ8KmGV0zny1FLtrcRZkGCczG2owvCRigVmimqp33mw5t861kI7zU2VfQBri65hIwu_4VXbmtqImMmTeZzqxE7NwwvAtwWcZSMnk6UDuzP3Ymzh9YrHPJkj_cy8vSLXvUYXrFO0HnCb0pSweHIL9pkReY',
}
requests.post(url=url,data=data,headers=headers).content.decode('utf-8')
I'd be very grateful if you could point out where I'm going wrong
I have tried to replace headers and so on.

Active Admin create additional URL on unique field

I have an object Foo which has fields id and token (both are unique, both have db indexes). I want to be able to get to Foo 1 by going to url "/admin/foos/token-of-foo-1" in addition to being able to use the url "/admin/foos/1". I know that I will need to do something like the below in my routes.rb, but I'm having trouble. Help?
ActiveAdmin.routes(self) # keep this
get 'admin/???', to: 'admin/???' # add ...something
Hmm, some thoughts:
#admin/foo.rb
controller do
def find_resource
if params[:id].length == 16 # it's a token
end_of_association_chain.find_by_token(params[:id])
else
end_of_association_chain.find(params[:id])
end
end
end
For this kind of purposes I use this gem called FriendlyID. You can select which fields should form the URL slug, in your case the field token:
class Foo < ApplicationRecord
extend FriendlyId
friendly_id :token, use: :slugged
end
Let me know if you have more doubts on how to configure. It has a great integration with Active Admin.

Filtering Haystack (SOLR) results by django_id

With Django/Haystack/SOLR, I'd like to be able to restrict the result of a search to those records within a particular range of django_ids. Getting these IDs is not a problem, but trying to filter by them produces some unexpected effects. The code looks like this (extraneous code trimmed for clarity):
def view_results(request,arg):
# django_ids list is first calculated using arg...
sqs = SearchQuerySet().facet('example_facet') # STEP_1
sqs = sqs.filter(django_id__in=django_ids) # STEP_2
view = search_view_factory(
view_class=SearchView,
template='search/search-results.html',
searchqueryset=sqs,
form_class=FacetedSearchForm
)
return view(request)
At the point marked STEP_1 I get all the database records. At STEP_2 the records are successfully narrowed down to the number I'd expect for that list of django_ids. The problem comes when the search results are displayed in cases where the user has specified a search term in the form. Rather than returning all records from STEP_2 which match the term, I get all records from STEP_2 plus all from STEP_1 which match the term.
Presumably, therefore, I need to override one/some of the methods in for SearchView in haystack/views.py, but what? Can anyone suggest a means of achieving what is required here?
After a bit more thought, I found a way around this. In the code above, the problem was occurring in the view = search_view_factory... line, so I needed to create my own SearchView class and override the get_results(self) method in order to apply the filtering after the search has been run with the user's search terms. The result is code along these lines:
class MySearchView(SearchView):
def get_results(self):
search = self.form.search()
# The ID I need for the database search is at the end of the URL,
# but this may have some search parameters on and need cleaning up.
view_id = self.request.path.split("/")[-1]
view_query = MyView.objects.filter(id=view_id.split("&")[0])
# At this point the django_ids of the required objects can be found.
if len(view_query) > 0:
view_item = view_query.__getitem__(0)
django_ids = []
for thing in view_item.things.all():
django_ids.append(thing.id)
search = search.filter_and(django_id__in=django_ids)
return search
Using search.filter_and rather than search.filter at the end was another thing which turned out to be essential, but which didn't do what I needed when the filtering was being performed before getting to the SearchView.

Create a collection of item ids Revit API in Python

So I am trying to use a list of input strings to isolate them in a view using Revit API. I got this far, but I am getting stuck where I am trying to create a set that takes all elements in a view and removes ones that are created from input IDs. I am doing this to end up with a set of all elements except ones that i want to isolate.
dataEnteringNode = IN0
view = IN0
str_ids = IN1
doc = __doc__
collector = FilteredElementCollector(doc, view.Id)
for i in str_ids:
int_id = int(i)
id = ElementId(int_id)
element = doc.GetElement(id)
element_set = ElementSet()
element_set.Insert(element)
elements_to_hide = collector.WhereElementIsNotElementType().Excluding(element_set).ToElements()
#Assign your output to the OUT variable
OUT = elements_to_hide
I would greatly appreciate a help in solving this error. I am getting that "expected ICollection[ElementId], got set". I am guessing the problem lies in a Excluding filter where i need to create a collection of Ids to exclude but I dont know how. Thank you in advance. Thank you for help in advance!
The reason your code doesn't work is that ElementSet in the Revit API does not implement the ICollection<T> interface - just the IEnumerable<T>. So, to get your code working, you will need to create an ICollection<T> object from your set.
Try something like this:
# ...
from System.Collections.Generic import List
element_collection = List[ElementId](element_set)
elements_to_hide = collector.WhereElementIsNotElementType().Excluding(element_collection).ToElements()

Downloading all records of a paginated resource in ActiveAdmin

I am trying to use the collection action "download_csv" already present in Active Admin to download all the records of a resource. However, the action only downloads the contents of the present page. As I have paginated the resource, the data needs to be downloaded from all the pages. Any suggestions on how I can approach this problem ?
Just for future googlers. My fix (working for the current Master 1.0.0pre) is to add the following to config/initializers/active_admin.rb:
module ActiveAdmin
class ResourceController
module DataAccess
# needed for current active admin master
def max_per_page
30_000
end
def per_page
return 30_000 if %w(text/csv application/xml application/json).include?(request.format)
return max_per_page if active_admin_config.paginate == false
#per_page || active_admin_config.per_page
end
end
end
end
Replace the max as needed. This works for csv, xml and json downloads.
This answer might be a little late but hopefully it can help somebody.
Here is how I have this working in my current app:
csv do
ModelName::ATTR_ADMIN_EXPORT.each do |sym|
column sym
end
end
And in the model I have ATTR_ADMIN_EXPORT defined like this:
ATTR_ADMIN_EXPORT = [:name, :created_at]
Let me know if this works for you!
You could try this
before_filter :only => :index do
#per_page = 10 unless request.format == 'text/csv'
end
This code will also make the pagination dynamic.
before_filter :only => :index do
if params[:pag].blank?
#per_page = AdminSetting.where(:name => 'JobPagination').first.value.to_i unless request.format == 'text/csv'
else
#per_page = 10
end
end

Resources