pdc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +27 -0
  3. data/.gitignore +10 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +21 -0
  7. data/CODE_OF_CONDUCT.md +49 -0
  8. data/Gemfile +32 -0
  9. data/Guardfile +36 -0
  10. data/LICENSE +21 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +41 -0
  13. data/Rakefile +11 -0
  14. data/bin/console +11 -0
  15. data/bin/setup +11 -0
  16. data/docs/.gitignore +3 -0
  17. data/docs/LICENSE_sphinx_deployment +27 -0
  18. data/docs/Makefile +179 -0
  19. data/docs/source/conf.py +257 -0
  20. data/docs/source/example.rst +10 -0
  21. data/docs/source/index.rst +23 -0
  22. data/docs/sphinx_deployment.mk +117 -0
  23. data/examples/active_attr.rb +33 -0
  24. data/examples/http_failures.rb +18 -0
  25. data/examples/local_pdc_dev.rb +15 -0
  26. data/examples/logger.rb +50 -0
  27. data/examples/pdc_curb_access_token.rb +36 -0
  28. data/examples/pdc_resource_tests.rb +173 -0
  29. data/examples/pdc_test_cache.rb +48 -0
  30. data/examples/prod_failures.rb +26 -0
  31. data/examples/prod_pdc.rb +14 -0
  32. data/lib/pdc/base.rb +14 -0
  33. data/lib/pdc/config.rb +157 -0
  34. data/lib/pdc/errors.rb +8 -0
  35. data/lib/pdc/http/errors.rb +43 -0
  36. data/lib/pdc/http/request/append_slash.rb +19 -0
  37. data/lib/pdc/http/request.rb +12 -0
  38. data/lib/pdc/http/response/pagination.rb +43 -0
  39. data/lib/pdc/http/response/parser.rb +62 -0
  40. data/lib/pdc/http/response/raise_error.rb +13 -0
  41. data/lib/pdc/http/response.rb +3 -0
  42. data/lib/pdc/http/result.rb +28 -0
  43. data/lib/pdc/http.rb +12 -0
  44. data/lib/pdc/logger.rb +19 -0
  45. data/lib/pdc/resource/attribute_modifier.rb +43 -0
  46. data/lib/pdc/resource/attribute_store.rb +22 -0
  47. data/lib/pdc/resource/attributes.rb +144 -0
  48. data/lib/pdc/resource/errors.rb +3 -0
  49. data/lib/pdc/resource/identity.rb +75 -0
  50. data/lib/pdc/resource/path.rb +63 -0
  51. data/lib/pdc/resource/per_thread_registry.rb +54 -0
  52. data/lib/pdc/resource/relation/finder.rb +24 -0
  53. data/lib/pdc/resource/relation/pagination.rb +33 -0
  54. data/lib/pdc/resource/relation/query.rb +14 -0
  55. data/lib/pdc/resource/relation.rb +81 -0
  56. data/lib/pdc/resource/rest_api.rb +34 -0
  57. data/lib/pdc/resource/scope_registry.rb +19 -0
  58. data/lib/pdc/resource/scopes.rb +29 -0
  59. data/lib/pdc/resource/value_parser.rb +31 -0
  60. data/lib/pdc/resource/wip.rb +0 -0
  61. data/lib/pdc/resource.rb +12 -0
  62. data/lib/pdc/v1/arch.rb +6 -0
  63. data/lib/pdc/v1/product.rb +5 -0
  64. data/lib/pdc/v1/release.rb +18 -0
  65. data/lib/pdc/v1/release_variant.rb +17 -0
  66. data/lib/pdc/v1.rb +8 -0
  67. data/lib/pdc/version.rb +3 -0
  68. data/lib/pdc.rb +25 -0
  69. data/pdc.gemspec +38 -0
  70. data/spec/fixtures/vcr/_page_count_returns_total_count.yml +141 -0
  71. data/spec/fixtures/vcr/brew_can_be_nil.yml +61 -0
  72. data/spec/fixtures/vcr/brew_may_be_present.yml +50 -0
  73. data/spec/fixtures/vcr/caches_multiple_response.yml +173 -0
  74. data/spec/fixtures/vcr/caches_response_with_a_query.yml +64 -0
  75. data/spec/fixtures/vcr/caches_response_with_multiple_query.yml +64 -0
  76. data/spec/fixtures/vcr/caches_response_without_query.yml +61 -0
  77. data/spec/fixtures/vcr/can_iterate_using_each.yml +187 -0
  78. data/spec/fixtures/vcr/fetches_variants_of_a_release.yml +663 -0
  79. data/spec/fixtures/vcr/must_return_number_of_resources.yml +61 -0
  80. data/spec/fixtures/vcr/preserves_the_filters.yml +49 -0
  81. data/spec/fixtures/vcr/returns_resources_on_that_page.yml +49 -0
  82. data/spec/fixtures/vcr/returns_the_total_count_and_not_items_in_page.yml +135 -0
  83. data/spec/fixtures/vcr/should_not_be_in_the_list_of_attributes.yml +95 -0
  84. data/spec/fixtures/vcr/works_with_where.yml +49 -0
  85. data/spec/pdc/config_spec.rb +115 -0
  86. data/spec/pdc/http/errors_spec.rb +58 -0
  87. data/spec/pdc/resource/attributes_spec.rb +231 -0
  88. data/spec/pdc/resource/cache_spec.rb +88 -0
  89. data/spec/pdc/resource/count_spec.rb +45 -0
  90. data/spec/pdc/resource/identity_spec.rb +96 -0
  91. data/spec/pdc/resource/pagination_spec.rb +51 -0
  92. data/spec/pdc/resource/path_spec.rb +30 -0
  93. data/spec/pdc/resource/relation_spec.rb +94 -0
  94. data/spec/pdc/resource/rest_api_spec.rb +23 -0
  95. data/spec/pdc/resource/value_parser_spec.rb +15 -0
  96. data/spec/pdc/resource/wip_spec.rb +0 -0
  97. data/spec/pdc/v1/arch_spec.rb +34 -0
  98. data/spec/pdc/v1/release_spec.rb +54 -0
  99. data/spec/pdc/version_spec.rb +5 -0
  100. data/spec/spec_helper.rb +39 -0
  101. data/spec/support/fixtures.rb +116 -0
  102. data/spec/support/vcr.rb +10 -0
  103. data/spec/support/webmock.rb +34 -0
  104. metadata +295 -0
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/releases/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.9.2
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ date:
22
+ - Wed, 27 Jul 2016 06:01:13 GMT
23
+ server:
24
+ - Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_auth_kerb/5.4
25
+ mod_wsgi/3.4 Python/2.7.5
26
+ expires:
27
+ - Wed, 27 Jul 2016 06:01:44 GMT
28
+ vary:
29
+ - Accept,Cookie
30
+ last-modified:
31
+ - Thu, 21 Jul 2016 12:24:12 GMT
32
+ allow:
33
+ - GET, POST, PUT, PATCH, HEAD, OPTIONS
34
+ cache-control:
35
+ - max-age=30
36
+ x-frame-options:
37
+ - SAMEORIGIN
38
+ connection:
39
+ - close
40
+ transfer-encoding:
41
+ - chunked
42
+ content-type:
43
+ - application/json
44
+ body:
45
+ encoding: UTF-8
46
+ string: '{"count":54,"next":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/releases/?page=2","previous":null,"results":[{"release_id":"atomicopenshift-3.2","short":"atomicopenshift","version":"3.2","name":"AtomicOpenShift","base_product":null,"active":true,"product_version":"atomicopenshift-3","release_type":"ga","compose_set":["AtomicOpenShift-3.2-20160519.4","AtomicOpenShift-3.2-20160519.6","AtomicOpenShift-3.2-20160520.3","AtomicOpenShift-3.2-20160520.4","AtomicOpenShift-3.2-20160520.6","AtomicOpenShift-3.2-20160520.7","AtomicOpenShift-3.2-20160530.2"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"cloudforms-4.1","short":"cloudforms","version":"4.1","name":"CloudForms","base_product":null,"active":true,"product_version":"cloudforms-4","release_type":"ga","compose_set":["CloudForms-4.1-20160520.8","CloudForms-4.1-20160520.9","CloudForms-4.1-20160530.1","CloudForms-4.1-20160530.2"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"dotnet-1.0@rhel-7","short":"dotnet","version":"1.0","name":"dotNET
47
+ on RHEL","base_product":"rhel-7","active":true,"product_version":"dotnet-1","release_type":"ga","compose_set":["dotNET-1.0-RHEL-7-20160601.0"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"dp-1.0","short":"dp","version":"1.0","name":"Dummy
48
+ Product","base_product":null,"active":true,"product_version":null,"release_type":"ga","compose_set":[],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"f-20","short":"f","version":"20","name":"Red
49
+ Hat Enterprise Linux","base_product":null,"active":true,"product_version":null,"release_type":"ga","compose_set":["RHEL-7.0-20140507.1"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"f-25","short":"f","version":"25","name":"Fedora","base_product":null,"active":true,"product_version":null,"release_type":"ga","compose_set":[],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":{"product_version":"production_version_1"}},{"release_id":"f-26","short":"f","version":"26","name":"Fedora","base_product":null,"active":true,"product_version":null,"release_type":"ga","compose_set":[],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":{"product_version":"production_version_1"}},{"release_id":"f-27","short":"f","version":"27","name":"Fedora","base_product":null,"active":true,"product_version":null,"release_type":"ga","compose_set":[],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":{"product_version":"production_version_1"}},{"release_id":"myproduct-2.1","short":"myproduct","version":"2.1","name":"MyProduct","base_product":null,"active":true,"product_version":"myproduct-2","release_type":"ga","compose_set":["MyProduct-2.1-20160519.9","MyProduct-2.1-20160519.10"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"openstack-9.0@rhel-7","short":"openstack","version":"9.0","name":"OpenStack","base_product":"rhel-7","active":true,"product_version":"openstack-9","release_type":"ga","compose_set":["OpenStack-9.0-RHEL-7-20160530.5"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhel-7.0","short":"rhel","version":"7.0","name":"Red
50
+ Hat Enterprise Linux","base_product":null,"active":true,"product_version":"rhel-7","release_type":"ga","compose_set":["RHEL-7.0-20140507.0"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhel-7.0-updates","short":"rhel","version":"7.0","name":"Red
51
+ Hat Enterprise Linux","base_product":null,"active":true,"product_version":"rhel-7","release_type":"updates","compose_set":["RHEL-7.0-20140507.0"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhel-7.1","short":"rhel","version":"7.1","name":"Red
52
+ Hat Enterprise Linux","base_product":null,"active":true,"product_version":"rhel-7","release_type":"ga","compose_set":["RHEL-7.1-20140507.2","RHEL-7.1-20140708.n.0","RHEL-7.1-20150219.1"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhel-7.1-updates","short":"rhel","version":"7.1","name":"Red
53
+ Hat Enterprise Linux","base_product":null,"active":true,"product_version":"rhel-7","release_type":"updates","compose_set":["RHEL-7.1-20150219.1"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhel-7.1-eus","short":"rhel","version":"7.1","name":"Red
54
+ Hat Enterprise Linux","base_product":null,"active":true,"product_version":"rhel-7","release_type":"eus","compose_set":["RHEL-7.1-20150219.1"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhel-7.2","short":"rhel","version":"7.2","name":"rhel7.2","base_product":null,"active":true,"product_version":null,"release_type":"ga","compose_set":[],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhel-le-7.1","short":"rhel-le","version":"7.1","name":"Red
55
+ Hat Enterprise Linux - LE","base_product":null,"active":true,"product_version":"rhel-le-7","release_type":"ga","compose_set":["RHEL-LE-7.1-20150219.1"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhscl-1.2@rhel-6","short":"rhscl","version":"1.2","name":"Red
56
+ Hat Software Collections","base_product":"rhel-6","active":true,"product_version":"rhscl-1","release_type":"ga","compose_set":["RHSCL-1.2-RHEL-6-20140814.0"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhscl-1.2@rhel-7","short":"rhscl","version":"1.2","name":"Red
57
+ Hat Software Collections","base_product":"rhel-7","active":true,"product_version":"rhscl-1","release_type":"ga","compose_set":["RHSCL-1.2-RHEL-7-20140814.0"],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null},{"release_id":"rhscl-2.2@rhel-6.6-eus","short":"rhscl","version":"2.2","name":"Red
58
+ Hat Software Collections","base_product":"rhel-6.6-eus","active":true,"product_version":"rhscl-2","release_type":"ga","compose_set":[],"integrated_with":null,"bugzilla":null,"dist_git":null,"brew":null,"product_pages":null,"errata":null}]}'
59
+ http_version:
60
+ recorded_at: Thu, 31 Dec 2015 14:00:00 GMT
61
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/release%2Dvariants/?name=rh-common&type=variant
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.9.2
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ date:
22
+ - Wed, 27 Jul 2016 06:01:11 GMT
23
+ server:
24
+ - Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_auth_kerb/5.4
25
+ mod_wsgi/3.4 Python/2.7.5
26
+ expires:
27
+ - Wed, 27 Jul 2016 06:01:41 GMT
28
+ vary:
29
+ - Accept,Cookie
30
+ last-modified:
31
+ - Thu, 21 Jul 2016 12:24:12 GMT
32
+ allow:
33
+ - GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
34
+ cache-control:
35
+ - max-age=30
36
+ x-frame-options:
37
+ - SAMEORIGIN
38
+ connection:
39
+ - close
40
+ transfer-encoding:
41
+ - chunked
42
+ content-type:
43
+ - application/json
44
+ body:
45
+ encoding: UTF-8
46
+ string: '{"count":3,"next":null,"previous":null,"results":[{"release":"satellite-6.0.4@rhel-5","id":"rhcommon","uid":"rhcommon","name":"rh-common","type":"variant","arches":["i386","ia64","ppc","s390x","x86_64"]},{"release":"satellite-6.0.4@rhel-6","id":"rhcommon","uid":"rhcommon","name":"rh-common","type":"variant","arches":["i386","ppc64","s390x","x86_64"]},{"release":"satellite-6.0.4@rhel-7","id":"rhcommon","uid":"rhcommon","name":"rh-common","type":"variant","arches":["ppc64","s390x","x86_64"]}]}'
47
+ http_version:
48
+ recorded_at: Thu, 31 Dec 2015 14:00:00 GMT
49
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=2
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.9.2
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ date:
22
+ - Wed, 27 Jul 2016 06:01:36 GMT
23
+ server:
24
+ - Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_auth_kerb/5.4
25
+ mod_wsgi/3.4 Python/2.7.5
26
+ expires:
27
+ - Wed, 27 Jul 2016 06:02:06 GMT
28
+ vary:
29
+ - Accept,Cookie
30
+ last-modified:
31
+ - Thu, 30 Jun 2016 10:00:15 GMT
32
+ allow:
33
+ - GET, POST, HEAD, OPTIONS
34
+ cache-control:
35
+ - max-age=30
36
+ x-frame-options:
37
+ - SAMEORIGIN
38
+ connection:
39
+ - close
40
+ transfer-encoding:
41
+ - chunked
42
+ content-type:
43
+ - application/json
44
+ body:
45
+ encoding: UTF-8
46
+ string: '{"count":50,"next":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=3","previous":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/","results":[{"name":"i386"},{"name":"i486"},{"name":"i586"},{"name":"i686"},{"name":"ia32e"},{"name":"ia64"},{"name":"noarch"},{"name":"nosrc"},{"name":"ppc"},{"name":"ppc64"},{"name":"ppc64iseries"},{"name":"ppc64le"},{"name":"ppc64p7"},{"name":"ppc64pseries"},{"name":"s390"},{"name":"s390x"},{"name":"sh3"},{"name":"sh4"},{"name":"sh4a"},{"name":"sparc"}]}'
47
+ http_version:
48
+ recorded_at: Thu, 31 Dec 2015 14:00:00 GMT
49
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,135 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.9.2
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ date:
22
+ - Wed, 27 Jul 2016 06:46:05 GMT
23
+ server:
24
+ - Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_auth_kerb/5.4
25
+ mod_wsgi/3.4 Python/2.7.5
26
+ expires:
27
+ - Wed, 27 Jul 2016 06:46:38 GMT
28
+ vary:
29
+ - Accept,Cookie
30
+ last-modified:
31
+ - Thu, 30 Jun 2016 10:00:15 GMT
32
+ allow:
33
+ - GET, POST, HEAD, OPTIONS
34
+ cache-control:
35
+ - max-age=30
36
+ x-frame-options:
37
+ - SAMEORIGIN
38
+ transfer-encoding:
39
+ - chunked
40
+ content-type:
41
+ - application/json
42
+ body:
43
+ encoding: UTF-8
44
+ string: '{"count":50,"next":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=2","previous":null,"results":[{"name":"alpha"},{"name":"alphaev4"},{"name":"alphaev45"},{"name":"alphaev5"},{"name":"alphaev56"},{"name":"alphaev6"},{"name":"alphaev67"},{"name":"alphaev68"},{"name":"alphaev7"},{"name":"alphapca56"},{"name":"amd64"},{"name":"arm64"},{"name":"armv5tejl"},{"name":"armv5tel"},{"name":"armv6l"},{"name":"armv7hl"},{"name":"armv7hnl"},{"name":"armv7l"},{"name":"athlon"},{"name":"geode"}]}'
45
+ http_version:
46
+ recorded_at: Wed, 27 Jul 2016 06:46:08 GMT
47
+ - request:
48
+ method: get
49
+ uri: https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=2
50
+ body:
51
+ encoding: US-ASCII
52
+ string: ''
53
+ headers:
54
+ Accept:
55
+ - application/json
56
+ Content-Type:
57
+ - application/json
58
+ User-Agent:
59
+ - Faraday v0.9.2
60
+ response:
61
+ status:
62
+ code: 200
63
+ message:
64
+ headers:
65
+ date:
66
+ - Wed, 27 Jul 2016 06:46:09 GMT
67
+ server:
68
+ - Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_auth_kerb/5.4
69
+ mod_wsgi/3.4 Python/2.7.5
70
+ expires:
71
+ - Wed, 27 Jul 2016 06:46:42 GMT
72
+ vary:
73
+ - Accept,Cookie
74
+ last-modified:
75
+ - Thu, 30 Jun 2016 10:00:15 GMT
76
+ allow:
77
+ - GET, POST, HEAD, OPTIONS
78
+ cache-control:
79
+ - max-age=30
80
+ x-frame-options:
81
+ - SAMEORIGIN
82
+ transfer-encoding:
83
+ - chunked
84
+ content-type:
85
+ - application/json
86
+ body:
87
+ encoding: UTF-8
88
+ string: '{"count":50,"next":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=3","previous":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/","results":[{"name":"i386"},{"name":"i486"},{"name":"i586"},{"name":"i686"},{"name":"ia32e"},{"name":"ia64"},{"name":"noarch"},{"name":"nosrc"},{"name":"ppc"},{"name":"ppc64"},{"name":"ppc64iseries"},{"name":"ppc64le"},{"name":"ppc64p7"},{"name":"ppc64pseries"},{"name":"s390"},{"name":"s390x"},{"name":"sh3"},{"name":"sh4"},{"name":"sh4a"},{"name":"sparc"}]}'
89
+ http_version:
90
+ recorded_at: Wed, 27 Jul 2016 06:46:12 GMT
91
+ - request:
92
+ method: get
93
+ uri: https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=2
94
+ body:
95
+ encoding: US-ASCII
96
+ string: ''
97
+ headers:
98
+ Accept:
99
+ - application/json
100
+ Content-Type:
101
+ - application/json
102
+ User-Agent:
103
+ - Faraday v0.9.2
104
+ response:
105
+ status:
106
+ code: 200
107
+ message:
108
+ headers:
109
+ date:
110
+ - Wed, 27 Jul 2016 06:46:13 GMT
111
+ server:
112
+ - Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_auth_kerb/5.4
113
+ mod_wsgi/3.4 Python/2.7.5
114
+ expires:
115
+ - Wed, 27 Jul 2016 06:46:45 GMT
116
+ vary:
117
+ - Accept,Cookie
118
+ last-modified:
119
+ - Thu, 30 Jun 2016 10:00:15 GMT
120
+ allow:
121
+ - GET, POST, HEAD, OPTIONS
122
+ cache-control:
123
+ - max-age=30
124
+ x-frame-options:
125
+ - SAMEORIGIN
126
+ transfer-encoding:
127
+ - chunked
128
+ content-type:
129
+ - application/json
130
+ body:
131
+ encoding: UTF-8
132
+ string: '{"count":50,"next":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=3","previous":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/","results":[{"name":"i386"},{"name":"i486"},{"name":"i586"},{"name":"i686"},{"name":"ia32e"},{"name":"ia64"},{"name":"noarch"},{"name":"nosrc"},{"name":"ppc"},{"name":"ppc64"},{"name":"ppc64iseries"},{"name":"ppc64le"},{"name":"ppc64p7"},{"name":"ppc64pseries"},{"name":"s390"},{"name":"s390x"},{"name":"sh3"},{"name":"sh4"},{"name":"sh4a"},{"name":"sparc"}]}'
133
+ http_version:
134
+ recorded_at: Wed, 27 Jul 2016 06:46:16 GMT
135
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,95 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=2
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.9.2
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ date:
22
+ - Wed, 27 Jul 2016 06:01:39 GMT
23
+ server:
24
+ - Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_auth_kerb/5.4
25
+ mod_wsgi/3.4 Python/2.7.5
26
+ expires:
27
+ - Wed, 27 Jul 2016 06:02:09 GMT
28
+ vary:
29
+ - Accept,Cookie
30
+ last-modified:
31
+ - Thu, 30 Jun 2016 10:00:15 GMT
32
+ allow:
33
+ - GET, POST, HEAD, OPTIONS
34
+ cache-control:
35
+ - max-age=30
36
+ x-frame-options:
37
+ - SAMEORIGIN
38
+ connection:
39
+ - close
40
+ transfer-encoding:
41
+ - chunked
42
+ content-type:
43
+ - application/json
44
+ body:
45
+ encoding: UTF-8
46
+ string: '{"count":50,"next":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=3","previous":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/","results":[{"name":"i386"},{"name":"i486"},{"name":"i586"},{"name":"i686"},{"name":"ia32e"},{"name":"ia64"},{"name":"noarch"},{"name":"nosrc"},{"name":"ppc"},{"name":"ppc64"},{"name":"ppc64iseries"},{"name":"ppc64le"},{"name":"ppc64p7"},{"name":"ppc64pseries"},{"name":"s390"},{"name":"s390x"},{"name":"sh3"},{"name":"sh4"},{"name":"sh4a"},{"name":"sparc"}]}'
47
+ http_version:
48
+ recorded_at: Thu, 31 Dec 2015 14:00:00 GMT
49
+ - request:
50
+ method: get
51
+ uri: https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=3
52
+ body:
53
+ encoding: US-ASCII
54
+ string: ''
55
+ headers:
56
+ Accept:
57
+ - application/json
58
+ Content-Type:
59
+ - application/json
60
+ User-Agent:
61
+ - Faraday v0.9.2
62
+ response:
63
+ status:
64
+ code: 200
65
+ message:
66
+ headers:
67
+ date:
68
+ - Wed, 27 Jul 2016 06:01:42 GMT
69
+ server:
70
+ - Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_auth_kerb/5.4
71
+ mod_wsgi/3.4 Python/2.7.5
72
+ expires:
73
+ - Wed, 27 Jul 2016 06:02:12 GMT
74
+ vary:
75
+ - Accept,Cookie
76
+ last-modified:
77
+ - Thu, 30 Jun 2016 10:00:15 GMT
78
+ allow:
79
+ - GET, POST, HEAD, OPTIONS
80
+ cache-control:
81
+ - max-age=30
82
+ x-frame-options:
83
+ - SAMEORIGIN
84
+ connection:
85
+ - close
86
+ transfer-encoding:
87
+ - chunked
88
+ content-type:
89
+ - application/json
90
+ body:
91
+ encoding: UTF-8
92
+ string: '{"count":50,"next":null,"previous":"https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/arches/?page=2","results":[{"name":"sparc64"},{"name":"sparc64v"},{"name":"sparcv8"},{"name":"sparcv9"},{"name":"sparcv9v"},{"name":"src"},{"name":"x86_64"},{"name":"aarch64"},{"name":"asdfwfsf"},{"name":"asdfdswe"}]}'
93
+ http_version:
94
+ recorded_at: Thu, 31 Dec 2015 14:00:00 GMT
95
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://pdc.host.dev.eng.pek2.redhat.com/rest_api/v1/releases/?active=false
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Content-Type:
13
+ - application/json
14
+ User-Agent:
15
+ - Faraday v0.9.2
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ date:
22
+ - Wed, 27 Jul 2016 06:01:15 GMT
23
+ server:
24
+ - Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips mod_auth_kerb/5.4
25
+ mod_wsgi/3.4 Python/2.7.5
26
+ expires:
27
+ - Wed, 27 Jul 2016 06:01:45 GMT
28
+ vary:
29
+ - Accept,Cookie
30
+ last-modified:
31
+ - Thu, 21 Jul 2016 12:24:12 GMT
32
+ allow:
33
+ - GET, POST, PUT, PATCH, HEAD, OPTIONS
34
+ cache-control:
35
+ - max-age=30
36
+ x-frame-options:
37
+ - SAMEORIGIN
38
+ connection:
39
+ - close
40
+ transfer-encoding:
41
+ - chunked
42
+ content-type:
43
+ - application/json
44
+ body:
45
+ encoding: UTF-8
46
+ string: '{"count":0,"next":null,"previous":null,"results":[]}'
47
+ http_version:
48
+ recorded_at: Thu, 31 Dec 2015 14:00:00 GMT
49
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe PDC do
4
+ before do
5
+ @old_config = PDC.config
6
+ end
7
+ after do
8
+ PDC.config = @old_config
9
+ end
10
+
11
+ describe '##configure' do
12
+ let(:site) { 'https://pdc.production.site.org' }
13
+ let(:token_url) do
14
+ pdc = PDC.config
15
+ URI.join(site, pdc.api_root, pdc.token_obtain_path)
16
+ end
17
+
18
+ it 'wont accept invalid config' do
19
+ assert_raises PDC::ConfigError do
20
+ PDC.configure do |config|
21
+ config.invalid_option = 'foobar'
22
+ end
23
+ end
24
+ end
25
+
26
+ it 'returns Faraday' do
27
+ ret = PDC.configure do |config|
28
+ config.site = 'http://foobar'
29
+ config.token = 'foo'
30
+ end
31
+ ret.must_be_instance_of Faraday::Connection
32
+ end
33
+
34
+ it 'fetches token by default' do
35
+ endpoint = stub_request(:get, token_url).to_return_json(token: 'foobar')
36
+ PDC.configure { |pdc| pdc.site = site }
37
+
38
+ assert_requested endpoint
39
+ PDC.token.must_equal 'foobar'
40
+ end
41
+
42
+ it 'raises TokenFetchFailed when fails' do
43
+ endpoint = stub_request(:get, token_url).to_return_json(
44
+ { detail: 'Not found' },
45
+ status: [404, 'NOT FOUND']
46
+ )
47
+
48
+ assert_raises PDC::TokenFetchFailed do
49
+ PDC.configure { |pdc| pdc.site = site }
50
+ end
51
+ assert_requested endpoint
52
+ end
53
+ end
54
+
55
+ describe '#config' do
56
+ before do
57
+ @config = PDC.config
58
+ @config.requires_token = false
59
+ end
60
+
61
+ after do
62
+ PDC.config = @config
63
+ end
64
+
65
+ it 'allows default site to be overridden ' do
66
+ PDC.configure do |config|
67
+ config.site = 'http://localhost:8888'
68
+ config.token = :foo
69
+ end
70
+ PDC.config.site.must_equal 'http://localhost:8888'
71
+ end
72
+
73
+ it 'preserves default values of items not overridden ' do
74
+ default_api_root = PDC.config.api_root
75
+ site = PDC.config.site
76
+ token = PDC.config.token
77
+
78
+ new_site = 'http://localhost:8888'
79
+ new_token = :foobar
80
+ PDC.configure do |config|
81
+ config.site = new_site
82
+ config.token = new_token
83
+ end
84
+ PDC.config.site.must_equal new_site
85
+ PDC.config.token.must_equal new_token
86
+
87
+ PDC.config.api_root.must_equal default_api_root
88
+ PDC.config.site.wont_equal site
89
+ PDC.config.token.wont_equal token
90
+ end
91
+
92
+ it 'creates a new Config' do
93
+ old_config = PDC.config
94
+ PDC.configure do |config|
95
+ config.site = 'https://foobar'
96
+ config.token = :foobar
97
+ end
98
+ PDC.config.wont_equal old_config
99
+ PDC.config.must_equal PDC.config
100
+ end
101
+
102
+ it 'resets connection when changed' do
103
+ old_connection = PDC::Base.connection
104
+ # assert that calling it again returns the same
105
+ PDC::Base.connection.must_equal old_connection
106
+
107
+ new_connection = PDC.configure do |config|
108
+ config.site = 'http://localhost:8888'
109
+ config.token = :foobar
110
+ end
111
+ PDC::Base.connection.must_equal new_connection
112
+ new_connection.wont_equal old_connection
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ FakeResponse = Struct.new(:status, :body)
4
+ FakeRequest = Struct.new(:url, :headers)
5
+
6
+ describe PDC::ResponseError do
7
+ describe '#response' do
8
+ it 'must be passed and can be retrieved' do
9
+ response = FakeResponse.new
10
+ error = PDC::ResponseError.new(response: response)
11
+ error.response.must_equal response
12
+ end
13
+ end
14
+
15
+ describe '#status' do
16
+ it 'has an error status' do
17
+ response = FakeResponse.new(200)
18
+ error = PDC::ResponseError.new(response: response)
19
+ error.status.must_equal response.status
20
+ end
21
+ end
22
+ end
23
+
24
+ describe PDC::JsonError do
25
+ describe '#message' do
26
+ describe 'response.body is json' do
27
+ let(:detail) { 'No Authentication token' }
28
+ let(:body_with_detail) { { 'detail' => detail } }
29
+ let(:body_without_detail) { { 'foo' => 'bar', 'bar' => 'baz' } }
30
+
31
+ it 'must return detail if present' do
32
+ status = 404
33
+ response = FakeResponse.new(status, body_with_detail.to_json)
34
+ error = PDC::JsonError.new(response: response)
35
+ error.message.must_equal "Error: #{status} - #{detail}"
36
+ end
37
+
38
+ it 'must return body if detail is absent' do
39
+ status = 404
40
+ response = FakeResponse.new(status, body_without_detail.to_json)
41
+ error = PDC::JsonError.new(response: response)
42
+
43
+ error.message.must_equal "Error: #{status} - #{body_without_detail.to_json}"
44
+ end
45
+ end
46
+
47
+ describe 'response.body is not json parsable' do
48
+ let(:invalid_json) { '<html><head></head><body></body></html>' }
49
+ let(:status) { 404 }
50
+ let(:response) { FakeResponse.new(status, '<html><head></head><body></body></html>') }
51
+
52
+ it 'must return body' do
53
+ error = PDC::JsonError.new(response: response)
54
+ error.message.must_equal "Error: #{status} - #{response.body}"
55
+ end
56
+ end
57
+ end
58
+ end