95f9151e295d084a5897769708e9c6cd1c8145fb
[arvados.git] / apps / workbench / test / controllers / collections_controller_test.rb
1 require 'test_helper'
2
3 class CollectionsControllerTest < ActionController::TestCase
4   include PipelineInstancesHelper
5
6   class RequestDuck
7     def self.host
8       "localhost"
9     end
10
11     def self.port
12       8080
13     end
14
15     def self.protocol
16       "http"
17     end
18   end
19
20
21   test 'provenance graph' do
22     use_token 'admin'
23     obj = Collection.where(uuid: 'zzzzz-4zz18-uukreo9rbgwsujj').results.first
24
25     provenance = obj.provenance.stringify_keys
26
27     [obj[:portable_data_hash]].each do |k|
28       assert_not_nil provenance[k], "Expected key #{k} in provenance set"
29     end
30
31     prov_svg = ProvenanceHelper::create_provenance_graph(provenance, "provenance_svg",
32                                                          {:request => RequestDuck,
33                                                            :direction => :bottom_up,
34                                                            :combine_jobs => :script_only})
35
36     # hash -> baz file
37     assert /ea10d51bcf88862dbcc36eb292017dfd\+45&#45;&gt;hash_f866587e2de5291fbd38d616d6d33eab/.match(prov_svg)
38
39     # hash2 -> baz file
40     assert /ea10d51bcf88862dbcc36eb292017dfd\+45&#45;&gt;hash2_02a085407e751d00b5dc88f1bd5e8247/.match(prov_svg)
41
42     # owned_by_active -> hash
43     assert /hash_f866587e2de5291fbd38d616d6d33eab&#45;&gt;fa7aeb5140e2848d39b416daeef4ffc5\+45/.match(prov_svg)
44
45     # owned_by_active -> hash2
46     assert /hash2_02a085407e751d00b5dc88f1bd5e8247&#45;&gt;fa7aeb5140e2848d39b416daeef4ffc5\+45/.match(prov_svg)
47
48     # File::open "./tmp/stuff3.svg", "w" do |f|
49     #   f.write "<?xml version=\"1.0\" ?>\n"
50     #   f.write prov_svg
51     # end
52
53   end
54
55   test 'used_by graph' do
56     use_token 'admin'
57     obj = Collection.where(uuid: 'zzzzz-4zz18-bv31uwvy3neko22').results.first
58
59     used_by = obj.used_by.stringify_keys
60
61     used_by_svg = ProvenanceHelper::create_provenance_graph(used_by, "used_by_svg",
62                                                             {:request => RequestDuck,
63                                                               :direction => :top_down,
64                                                               :combine_jobs => :script_only,
65                                                               :pdata_only => true})
66
67     # bar_file -> hash2
68     assert /fa7aeb5140e2848d39b416daeef4ffc5\+45&#45;&gt;hash2_f866587e2de5291fbd38d616d6d33eab/.match(used_by_svg)
69
70     # hash -> baz file
71     assert /hash_f866587e2de5291fbd38d616d6d33eab&#45;&gt;ea10d51bcf88862dbcc36eb292017dfd\+45/.match(used_by_svg)
72
73     # hash2 -> baz file
74     assert /hash2_02a085407e751d00b5dc88f1bd5e8247&#45;&gt;ea10d51bcf88862dbcc36eb292017dfd\+45/.match(used_by_svg)
75
76
77     # File::open "./tmp/stuff4.svg", "w" do |f|
78     #   f.write "<?xml version=\"1.0\" ?>\n"
79     #   f.write used_by_svg
80     # end
81
82   end
83 end