api_mini_tester 0.1.8 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef4e57833b153a87f182b19386eff11bece566d1
4
- data.tar.gz: 5917cd74ed03cc1f52fa505f245de80fecdb5fed
3
+ metadata.gz: 6e25a821823b34ec31d6415b034a1d1abbf6d0fa
4
+ data.tar.gz: 56c5ded54e8eb4f4f5741fbe7068697668f4b8a6
5
5
  SHA512:
6
- metadata.gz: fb624ba3f8e97ecb8d56cceab4b2bddab5fa7cf2a9ce4a454ffc7c1b17e4f908c726b28e7b0a9593fb1c0db1df92aa813c57f51c4f21423937dd2b3311d99cf4
7
- data.tar.gz: b565f8d8cfcf2bb5dbe3d987e5a3b189ac6b8719750eba2e2ac5b59d4c592c593d88b62f0590b13923e31f13f82a86198727aac16bc7ce57a4288e9ca57b2499
6
+ metadata.gz: cdc8c543be0449543b3678ab4ba2486f675625427b94a456d5697ef73623f14032f75ab4511a3c250bab22535fba31011f2b5b8b667a66df22d08377d8671740
7
+ data.tar.gz: 1522724e3cba1ac9a7e1bcd24aa4e336b05aee210a6f6c7f784e34a26d1966c0aa8cec3e44d27ab8f0c0d327b8a3e61ddd789de66c280c730f18c59372cdaa7c
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'api_mini_tester/import'
4
+
5
+ begin
6
+ puts "usage: api_mini_tester [input_file.json] [output_file.yaml]"
7
+ exit 1
8
+ end if ARGV.count != 2
9
+
10
+ input_file = ARGV[0]
11
+ output_file = ARGV[1]
12
+
13
+ postman_json = File.read(input_file)
14
+ importer = ApiMiniTester::Import::Postman.new postman_json
15
+ File.open(output_file, "w+").write(importer.to_yaml)
@@ -0,0 +1,6 @@
1
+ module ApiMiniTester
2
+ module Import
3
+ end
4
+ end
5
+
6
+ require 'api_mini_tester/import/postman'
@@ -0,0 +1,98 @@
1
+ require 'json'
2
+ require 'yaml'
3
+
4
+ module ApiMiniTester
5
+ module Import
6
+ class Postman
7
+ attr_reader :collection
8
+
9
+ def initialize(json_collection)
10
+ @collection = JSON.parse json_collection
11
+ end
12
+
13
+ def to_yaml
14
+ suite = suite_base
15
+ suite['tests'][0]['steps'] = steps
16
+ suite.to_yaml
17
+ end
18
+
19
+ def suite_base
20
+ @suite_base ||= {
21
+ 'name' => name,
22
+ 'desc' => "Imported from postman collection: #{name}",
23
+ 'settings' => {
24
+ 'baseurl' => baseurl
25
+ },
26
+ 'tests' => [
27
+ {
28
+ 'name' => "Test scenario based on postman collection #{name}",
29
+ 'steps' => []
30
+ }
31
+ ]
32
+ }
33
+ end
34
+
35
+ def name
36
+ collection['info']['name']
37
+ end
38
+
39
+ def baseurl
40
+ @base ||= begin
41
+ base = collection['item'][0]['request']['url']['raw']
42
+ collection['item'].each do |item|
43
+ item_url = item['request']['url']['raw']
44
+ index = 0
45
+ index += 1 while base[index] && item_url[index] && base[index] == item_url[index]
46
+ base = base[0..(index - 1)][0..(base.rindex('/') - 1)]
47
+ end
48
+ base
49
+ end
50
+ @base
51
+ end
52
+
53
+ def steps
54
+ res = []
55
+ index = 0
56
+ collection['item'].each do |item|
57
+ res << step(item, index)
58
+ index += 1
59
+ end
60
+ res
61
+ end
62
+
63
+ def step_uri(uri)
64
+ uri.gsub("#{@base}/", "")
65
+ end
66
+
67
+ def step_header(header)
68
+ res = {}
69
+ header.each do |h|
70
+ res[h['key']] = h['value']
71
+ end
72
+ res
73
+ end
74
+
75
+ def step_body(body)
76
+ body ? JSON.parse(body) : {}
77
+ end
78
+
79
+ def step(item, index)
80
+ res = {
81
+ 'step' => index,
82
+ 'name' => item['name'],
83
+ 'method' => item['request']['method'],
84
+ 'uri' => step_uri(item['request']['url']['raw']),
85
+ 'input' => {
86
+ 'header' => step_header(item['request']['header']),
87
+ 'body' => step_body(item['request']['body']['raw'])
88
+ },
89
+ 'output' => {
90
+ 'header' => {},
91
+ 'body' => {}
92
+ }
93
+ }
94
+ res
95
+ end
96
+ end
97
+ end
98
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_mini_tester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jindrich Skupa (@eMan)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-12 00:00:00.000000000 Z
11
+ date: 2018-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -270,15 +270,21 @@ dependencies:
270
270
  - - ">="
271
271
  - !ruby/object:Gem::Version
272
272
  version: 3.4.2
273
- description: Runs automated REST API based on YAML definition
273
+ description: Runs automated REST API based on YAML definition. Uses templates for
274
+ API requests, mock data with faker and cz_faker and context data. Supports Postman
275
+ collection export for conversion.
274
276
  email: jindrich.skupa@gmail.com
275
277
  executables:
276
278
  - api_mini_tester
279
+ - postman2minitester
277
280
  extensions: []
278
281
  extra_rdoc_files: []
279
282
  files:
280
283
  - bin/api_mini_tester
284
+ - bin/postman2minitester
281
285
  - lib/api_mini_tester.rb
286
+ - lib/api_mini_tester/import.rb
287
+ - lib/api_mini_tester/import/postman.rb
282
288
  - lib/api_mini_tester/test_faker_filter.rb
283
289
  - lib/api_mini_tester/test_formatter.rb
284
290
  - lib/api_mini_tester/test_scenario.rb