nowtv-test-utils 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/nowtv-test-utils.rb +136 -0
- data/lib/nowtv-test-utils/rest_helper.rb +31 -0
- data/lib/nowtv-test-utils/test.rb +7 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3b1b4bbedc8fd9d81e245b14f5664c9b84878e1a82cf7ea7f4da8dc5f66062d1
|
4
|
+
data.tar.gz: 617fbaf389e522605ae7332c0febeedcee072dab4f01c2d8bd0590ec723ae79e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b22c96cc00aaad20f7ee1b9d0b0bc4fe8288ce40f93e386d3ed80f458254509f55be2ed98b335876de28fdb3e7eab323c50d9dd8d0be19928037ea3bd99df8a6
|
7
|
+
data.tar.gz: aeba0bea4ac439327f31f33e1c4c3b47113f90f83e7afc144ddf3987bcbed26ea7bafc0f895fa0a1b80443c7adbc7d2e4b65a4f817dde314e6e217c834d848f8
|
@@ -0,0 +1,136 @@
|
|
1
|
+
module NowtvTestUtils
|
2
|
+
class Menu
|
3
|
+
def initialize(configurator, config_params)
|
4
|
+
|
5
|
+
@configurator = configurator
|
6
|
+
@env = config_params[:env]
|
7
|
+
@device = config_params[:device]
|
8
|
+
@platform = config_params[:platform]
|
9
|
+
@language = config_params[:language]
|
10
|
+
@territory = config_params[:territory]
|
11
|
+
@base_pcms_url = configurator['hosts'][@env]
|
12
|
+
@root_menu_url = @base_pcms_url + configurator['seamlessUrl']
|
13
|
+
|
14
|
+
puts "Env: #{@env} Device: #{@device} Platform: #{@platform } Lang: #{@language} Territory: #{@territory}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def json_headers
|
18
|
+
headers = { 'X-SkyOTT-Proposition' => 'NOWTV',
|
19
|
+
'X-SkyOTT-Language' => @language,
|
20
|
+
'X-SkyOTT-Territory' => @territory,
|
21
|
+
'X-SkyOTT-Platform' => @platform,
|
22
|
+
'X-SkyOTT-Device' => @device }
|
23
|
+
headers
|
24
|
+
end
|
25
|
+
|
26
|
+
def root_menu_collection
|
27
|
+
RestHelper.get_from_api(@root_menu_url)
|
28
|
+
end
|
29
|
+
|
30
|
+
def root_menu_json
|
31
|
+
api_response(@root_menu_url)
|
32
|
+
end
|
33
|
+
|
34
|
+
def menu_json
|
35
|
+
root_menu_json['relationships']['items']['data']
|
36
|
+
end
|
37
|
+
|
38
|
+
def menu_titles
|
39
|
+
menu_json.map { |menu| menu['attributes']['title'] }
|
40
|
+
end
|
41
|
+
|
42
|
+
def sub_menu_titles(menu)
|
43
|
+
menu_item_json(menu)['relationships']['items']['data'].map { |menu| menu['attributes']['title'] }
|
44
|
+
end
|
45
|
+
|
46
|
+
def menu_item_json(menu)
|
47
|
+
menu_item_json = nil
|
48
|
+
menu_json.each do |collection|
|
49
|
+
if collection['attributes']['title'].casecmp(menu)==0
|
50
|
+
if collection['relationships'] && collection['relationships']['items']
|
51
|
+
menu_item_json = collection
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
menu_item_json
|
57
|
+
end
|
58
|
+
|
59
|
+
def catalogue_collections(link)
|
60
|
+
sub_catalogue_titles_collection = []
|
61
|
+
sub_collection_json = api_response(@base_pcms_url
|
62
|
+
.+ link + '?represent=(items)')
|
63
|
+
if sub_collection_json['type']=='CATALOGUE/GROUP'
|
64
|
+
# puts "Collection:==> #{sub_collection_json['attributes']['title']} is a GROUP"
|
65
|
+
sub_collection_json['relationships']['items']['data'].each do |sub_group|
|
66
|
+
sub_catalogue_titles_collection.concat(catalogue_collections(sub_group['links']['self']))
|
67
|
+
end
|
68
|
+
else
|
69
|
+
if sub_collection_json['relationships'] && sub_collection_json['relationships']['items']
|
70
|
+
sub_catalogue_titles_collection.concat(sub_collection_json['relationships']['items']['data'])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
return sub_catalogue_titles_collection
|
74
|
+
end
|
75
|
+
|
76
|
+
def catalogue_group_json(menu)
|
77
|
+
menu_item_json = menu_item_json(menu)
|
78
|
+
puts "Getting all asset details for #{menu} menu...."
|
79
|
+
catalogue_collections(menu_item_json['links']['self'])
|
80
|
+
end
|
81
|
+
|
82
|
+
def catalogue_collection(menu)
|
83
|
+
menu_titles.each do |menu_title|
|
84
|
+
if menu_title.casecmp(menu) == 0
|
85
|
+
unless instance_variable_get("@catalogue_#{menu}_collection")
|
86
|
+
instance_variable_set("@catalogue_#{menu}_collection", catalogue_group_json(menu))
|
87
|
+
end
|
88
|
+
return instance_variable_get("@catalogue_#{menu}_collection")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def api_response(url)
|
94
|
+
RestHelper.get_from_api(url, json_headers)
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_asset_details_using_title(menu, asset_title)
|
98
|
+
assets_in_catalogue = catalogue_collection(menu)
|
99
|
+
# puts assets_in_catalogue
|
100
|
+
asset = assets_in_catalogue.find {|e| e['attributes']['title'].casecmp(asset_title)==0}
|
101
|
+
if asset
|
102
|
+
return get_asset_details_from_nodeid(asset['id'])
|
103
|
+
else
|
104
|
+
return "No asset matched title #{asset_title}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_asset_details_from_nodeid(node_id)
|
109
|
+
node_url = @configurator['node_url']
|
110
|
+
asset_details_from_api = api_response(@base_pcms_url+ node_url + node_id)
|
111
|
+
asset_details_from_api
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.test_settings(config_type, config)
|
116
|
+
if config_type == "YML"
|
117
|
+
puts config
|
118
|
+
return (@test_settings ||= YAML.load_file(NowtvTestUtils.get_file_path(config)))
|
119
|
+
else
|
120
|
+
return (@test_settings ||= JSON.parse(File.read(NowtvTestUtils.get_file_path(config))))
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.get_file_path(filename)
|
125
|
+
File.join(Dir.pwd, filename)
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.menu_api_helper(config_type, config, config_params)
|
129
|
+
configurator = NowtvTestUtils.test_settings(config_type, config)
|
130
|
+
@menu_api_helper ||= NowtvTestUtils::Menu.new(configurator, config_params)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
require 'nowtv-test-utils/rest_helper.rb'
|
135
|
+
require 'nowtv-test-utils/test'
|
136
|
+
require 'yaml'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'rspec'
|
4
|
+
require 'rspec/expectations'
|
5
|
+
|
6
|
+
class RestHelper
|
7
|
+
def self.get_from_api(url, json_headers, additional_headers = {})
|
8
|
+
headers = json_headers
|
9
|
+
headers.merge!(additional_headers)
|
10
|
+
begin
|
11
|
+
tries ||= 3
|
12
|
+
api_response = RestClient.get(url, headers) { |response, _request| response }
|
13
|
+
if api_response.code != 200
|
14
|
+
puts "ERROR in get_from_api: response code #{api_response.code}"
|
15
|
+
end
|
16
|
+
respo = JSON.parse(api_response)
|
17
|
+
rescue => e
|
18
|
+
puts 'RESCUE in get_from_api@'
|
19
|
+
puts e.message
|
20
|
+
puts "======="
|
21
|
+
if (tries -= 1) > 0
|
22
|
+
puts'RETRY REQUEST'
|
23
|
+
retry
|
24
|
+
else
|
25
|
+
puts'REQUEST FAILED 3 TIMES'
|
26
|
+
raise 'REST HELPER - get_from_api error'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
respo
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nowtv-test-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sripriya Raghunatha
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: sripriya.raghunatha@sky.uk
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/nowtv-test-utils.rb
|
20
|
+
- lib/nowtv-test-utils/rest_helper.rb
|
21
|
+
- lib/nowtv-test-utils/test.rb
|
22
|
+
homepage:
|
23
|
+
licenses: []
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.7.7
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: nowtv-test-utils for sharing test code
|
45
|
+
test_files: []
|