bridge_blueprint 0.0.05 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +49 -5
- data/.rubocop.yml +24 -0
- data/.simplecov +7 -0
- data/Dockerfile +14 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +32 -8
- data/bin/jenkins +17 -0
- data/bridge_blueprint.gemspec +22 -18
- data/build.sh +5 -0
- data/docker-compose.yml +18 -0
- data/lib/bridge_blueprint/constants.rb +2 -0
- data/lib/bridge_blueprint/data_dump.rb +7 -9
- data/lib/bridge_blueprint/remote_data.rb +38 -22
- data/lib/bridge_blueprint/version.rb +3 -1
- data/lib/bridge_blueprint.rb +2 -0
- data/spec/bridge_blueprint/data_dump_spec.rb +8 -7
- data/spec/bridge_blueprint/remote_data_spec.rb +31 -10
- data/spec/fixtures/data_dumps_pending.json +9 -0
- data/spec/support/fake_bridge.rb +27 -8
- data/spec/test_helper.rb +5 -3
- metadata +76 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3795e4ec50a47d33f258d98bc0072f487b0ddf6f9f48f1f004b9b98bc2fc6f17
|
4
|
+
data.tar.gz: 9ab1b16ece7316d42ba44632321b6543cc88cc90435aca7eaa5e46668372a469
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cfa4b29592ef6f8491459e99c6e04bada18459d3dab31eee6259487ad3439716427d465364a8989f643f92c200120ecfa05eca1127d6c3e3f40e44a01aaf756
|
7
|
+
data.tar.gz: 714e2fc56c87cb4fd289e1a9c4161656a86d2a8a35000d8675f661f00ca3fc2151c84490fd5fe89773cc7f4147e7b86ad0dcb1fd788fa654b229c43e4f13302f
|
data/.gitignore
CHANGED
@@ -1,6 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
5
12
|
|
6
|
-
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'bin/**/*'
|
4
|
+
- 'node_modules/**/*'
|
5
|
+
- 'vendor/**/*'
|
6
|
+
Metrics/ClassLength:
|
7
|
+
Max: 150
|
8
|
+
Metrics/LineLength:
|
9
|
+
Max: 120
|
10
|
+
Style/Documentation:
|
11
|
+
Enabled: false
|
12
|
+
Metrics/BlockLength:
|
13
|
+
Exclude:
|
14
|
+
- 'bridge_blueprint.gemspec'
|
15
|
+
- 'spec/**/*'
|
16
|
+
Style/FrozenStringLiteralComment:
|
17
|
+
Enabled: false
|
18
|
+
Style/SymbolArray:
|
19
|
+
Enabled: false
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Exclude:
|
22
|
+
- spec/**/*
|
23
|
+
Naming/AccessorMethodName:
|
24
|
+
Enabled: false
|
data/.simplecov
ADDED
data/Dockerfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
FROM ruby:2.5.0
|
2
|
+
|
3
|
+
RUN apt-get update
|
4
|
+
|
5
|
+
RUN mkdir -p /usr/src/app
|
6
|
+
COPY Gemfile /usr/src/app/
|
7
|
+
COPY Gemfile.lock /usr/src/app/
|
8
|
+
COPY bridge_blueprint.gemspec /usr/src/app/
|
9
|
+
COPY /lib/bridge_blueprint/version.rb /usr/src/app/lib/bridge_blueprint/
|
10
|
+
|
11
|
+
WORKDIR /usr/src/app
|
12
|
+
RUN bundle install --system
|
13
|
+
|
14
|
+
COPY . /usr/src/app/
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bridge_blueprint (0.0.
|
4
|
+
bridge_blueprint (0.0.7)
|
5
5
|
bridge_api (~> 0.1.16)
|
6
6
|
open_uri_redirections (~> 0.2.1)
|
7
7
|
rubyzip (~> 1.2.1)
|
@@ -9,14 +9,15 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (5.
|
12
|
+
activesupport (5.2.0)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (
|
14
|
+
i18n (>= 0.7, < 2)
|
15
15
|
minitest (~> 5.1)
|
16
16
|
tzinfo (~> 1.1)
|
17
17
|
addressable (2.5.1)
|
18
18
|
public_suffix (~> 2.0, >= 2.0.2)
|
19
|
-
|
19
|
+
ast (2.4.0)
|
20
|
+
bridge_api (0.1.19)
|
20
21
|
faraday (~> 0.9.0)
|
21
22
|
faraday_middleware (~> 0.9.0)
|
22
23
|
footrest (>= 0.5.1)
|
@@ -26,6 +27,7 @@ GEM
|
|
26
27
|
crack (0.4.3)
|
27
28
|
safe_yaml (~> 1.0.0)
|
28
29
|
diff-lcs (1.3)
|
30
|
+
docile (1.3.0)
|
29
31
|
faraday (0.9.2)
|
30
32
|
multipart-post (>= 1.2, < 3)
|
31
33
|
faraday_middleware (0.9.2)
|
@@ -35,13 +37,18 @@ GEM
|
|
35
37
|
faraday (~> 0.9.0)
|
36
38
|
link_header (>= 0.0.7)
|
37
39
|
hashdiff (0.3.4)
|
38
|
-
i18n (0.
|
40
|
+
i18n (1.0.0)
|
39
41
|
concurrent-ruby (~> 1.0)
|
42
|
+
json (2.1.0)
|
40
43
|
link_header (0.0.8)
|
41
44
|
method_source (0.8.2)
|
42
|
-
minitest (5.11.
|
45
|
+
minitest (5.11.3)
|
43
46
|
multipart-post (2.0.0)
|
44
47
|
open_uri_redirections (0.2.1)
|
48
|
+
parallel (1.12.1)
|
49
|
+
parser (2.5.1.0)
|
50
|
+
ast (~> 2.4.0)
|
51
|
+
powerpack (0.1.1)
|
45
52
|
pry (0.10.4)
|
46
53
|
coderay (~> 1.1.0)
|
47
54
|
method_source (~> 0.8.1)
|
@@ -50,6 +57,7 @@ GEM
|
|
50
57
|
rack (1.6.5)
|
51
58
|
rack-protection (1.5.3)
|
52
59
|
rack
|
60
|
+
rainbow (3.0.0)
|
53
61
|
rake (0.9.6)
|
54
62
|
rspec (2.99.0)
|
55
63
|
rspec-core (~> 2.99.0)
|
@@ -59,8 +67,21 @@ GEM
|
|
59
67
|
rspec-expectations (2.99.2)
|
60
68
|
diff-lcs (>= 1.1.3, < 2.0)
|
61
69
|
rspec-mocks (2.99.4)
|
70
|
+
rubocop (0.54.0)
|
71
|
+
parallel (~> 1.10)
|
72
|
+
parser (>= 2.5)
|
73
|
+
powerpack (~> 0.1)
|
74
|
+
rainbow (>= 2.2.2, < 4.0)
|
75
|
+
ruby-progressbar (~> 1.7)
|
76
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
77
|
+
ruby-progressbar (1.9.0)
|
62
78
|
rubyzip (1.2.1)
|
63
79
|
safe_yaml (1.0.4)
|
80
|
+
simplecov (0.16.1)
|
81
|
+
docile (~> 1.1)
|
82
|
+
json (>= 1.8, < 3)
|
83
|
+
simplecov-html (~> 0.10.0)
|
84
|
+
simplecov-html (0.10.2)
|
64
85
|
sinatra (1.4.8)
|
65
86
|
rack (~> 1.5)
|
66
87
|
rack-protection (~> 1.4)
|
@@ -68,8 +89,9 @@ GEM
|
|
68
89
|
slop (3.6.0)
|
69
90
|
thread_safe (0.3.6)
|
70
91
|
tilt (1.4.1)
|
71
|
-
tzinfo (1.2.
|
92
|
+
tzinfo (1.2.5)
|
72
93
|
thread_safe (~> 0.1)
|
94
|
+
unicode-display_width (1.3.2)
|
73
95
|
webmock (2.3.2)
|
74
96
|
addressable (>= 2.3.6)
|
75
97
|
crack (>= 0.3.2)
|
@@ -85,9 +107,11 @@ DEPENDENCIES
|
|
85
107
|
pry (~> 0)
|
86
108
|
rake (~> 0)
|
87
109
|
rspec (~> 2.6)
|
110
|
+
rubocop (~> 0.54.0)
|
111
|
+
simplecov (~> 0.16.1)
|
88
112
|
sinatra (~> 1.0)
|
89
113
|
tilt (~> 1.3, >= 1.3.4)
|
90
114
|
webmock (~> 2.3.1)
|
91
115
|
|
92
116
|
BUNDLED WITH
|
93
|
-
1.
|
117
|
+
1.16.1
|
data/bin/jenkins
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set +e
|
4
|
+
EXIT_CODES=0
|
5
|
+
|
6
|
+
#Skip this for now until we can fix all the cop issues
|
7
|
+
|
8
|
+
#echo "Analyzing ruby code with rubocop"
|
9
|
+
#bundle exec gergich capture rubocop "bundle exec rubocop --fail-level autocorrect"
|
10
|
+
#EXIT_CODES=$(($EXIT_CODES + $?))
|
11
|
+
|
12
|
+
echo 'Running ruby specs'
|
13
|
+
bundle exec rspec
|
14
|
+
EXIT_CODES=$(($EXIT_CODES + $?))
|
15
|
+
|
16
|
+
bundle exec gergich publish
|
17
|
+
exit $EXIT_CODES
|
data/bridge_blueprint.gemspec
CHANGED
@@ -1,33 +1,37 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
3
5
|
require 'bridge_blueprint/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |gem|
|
6
|
-
gem.authors = [
|
7
|
-
gem.email = [
|
8
|
-
gem.description =
|
9
|
-
gem.summary =
|
10
|
-
gem.homepage =
|
8
|
+
gem.authors = ['Jay Shaffer']
|
9
|
+
gem.email = ['jshaffer@instructure.com']
|
10
|
+
gem.description = 'Tools for consuming bridge data dumps'
|
11
|
+
gem.summary = 'Bridge Blueprint'
|
12
|
+
gem.homepage = 'https://getbridge.com'
|
11
13
|
gem.license = 'MIT'
|
12
14
|
|
13
15
|
gem.files = `git ls-files`.split("\n")
|
14
|
-
gem.files += Dir.glob(
|
15
|
-
gem.files += Dir.glob(
|
16
|
-
gem.test_files = Dir.glob(
|
17
|
-
gem.name =
|
18
|
-
gem.require_paths = [
|
16
|
+
gem.files += Dir.glob('lib/**/*.rb')
|
17
|
+
gem.files += Dir.glob('spec/**/*')
|
18
|
+
gem.test_files = Dir.glob('spec/**/*')
|
19
|
+
gem.name = 'bridge_blueprint'
|
20
|
+
gem.require_paths = ['lib']
|
19
21
|
gem.version = BridgeBlueprint::VERSION
|
20
22
|
|
21
|
-
gem.add_runtime_dependency 'bridge_api', '
|
23
|
+
gem.add_runtime_dependency 'bridge_api', '>= 0.1.16'
|
22
24
|
gem.add_runtime_dependency 'open_uri_redirections', '~> 0.2.1'
|
23
25
|
gem.add_runtime_dependency 'rubyzip', '~> 1.2.1'
|
24
26
|
|
25
|
-
gem.add_development_dependency 'rake', '~> 0'
|
26
27
|
gem.add_development_dependency 'bundler', '~> 1.0', '>= 1.0.0'
|
27
|
-
gem.add_development_dependency '
|
28
|
-
gem.add_development_dependency 'webmock', '~>2.3.1'
|
28
|
+
gem.add_development_dependency 'byebug', '~> 8.2.2'
|
29
29
|
gem.add_development_dependency 'pry', '~> 0'
|
30
|
-
gem.add_development_dependency '
|
30
|
+
gem.add_development_dependency 'rake', '~> 0'
|
31
|
+
gem.add_development_dependency 'rspec', '~> 2.6'
|
32
|
+
gem.add_development_dependency 'rubocop', '~> 0.54.0'
|
33
|
+
gem.add_development_dependency 'simplecov', '~> 0.16.1'
|
31
34
|
gem.add_development_dependency 'sinatra', '~> 1.0'
|
32
|
-
gem.add_development_dependency '
|
35
|
+
gem.add_development_dependency 'tilt', '>= 1.3.4', '~> 1.3'
|
36
|
+
gem.add_development_dependency 'webmock', '~>2.3.1'
|
33
37
|
end
|
data/build.sh
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
version: '2'
|
2
|
+
|
3
|
+
services:
|
4
|
+
web:
|
5
|
+
build:
|
6
|
+
context: .
|
7
|
+
dockerfile: ./Dockerfile
|
8
|
+
environment:
|
9
|
+
APP_DOMAIN: web
|
10
|
+
GERGICH_KEY: "${GERGICH_KEY}"
|
11
|
+
GERRIT_PROJECT: "${GERRIT_PROJECT}"
|
12
|
+
GERRIT_HOST: "${GERRIT_HOST}"
|
13
|
+
GERRIT_BRANCH: "${GERRIT_BRANCH}"
|
14
|
+
volumes:
|
15
|
+
- "coverage:/usr/src/app/coverage"
|
16
|
+
|
17
|
+
volumes:
|
18
|
+
coverage: {}
|
@@ -1,16 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'csv'
|
2
4
|
require 'zip'
|
3
5
|
|
4
6
|
module BridgeBlueprint
|
5
7
|
class DataDump
|
6
|
-
|
7
8
|
@path = nil
|
8
9
|
|
9
10
|
def initialize(path)
|
10
11
|
@path = path
|
11
|
-
unless File.
|
12
|
-
raise "File not found #{path}"
|
13
|
-
end
|
12
|
+
raise "File not found #{path}" unless File.exist?(path)
|
14
13
|
end
|
15
14
|
|
16
15
|
def each_row(name)
|
@@ -29,11 +28,10 @@ module BridgeBlueprint
|
|
29
28
|
file = nil
|
30
29
|
Zip::File.open(@path) do |zip_file|
|
31
30
|
zip_file.each do |entry|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
31
|
+
next unless name.to_s == entry.name
|
32
|
+
path = "#{dir}/#{entry.name}"
|
33
|
+
file = entry.extract(path)
|
34
|
+
break
|
37
35
|
end
|
38
36
|
end
|
39
37
|
if file
|
@@ -1,56 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'open-uri'
|
2
4
|
require 'open_uri_redirections'
|
3
5
|
require 'net/http'
|
4
6
|
require 'uri'
|
5
7
|
require 'base64'
|
6
|
-
require
|
8
|
+
require 'bridge_api'
|
7
9
|
|
8
10
|
module BridgeBlueprint
|
9
|
-
|
10
11
|
class RemoteData
|
11
|
-
|
12
12
|
USERS_CSV_NAME = 'users.csv'
|
13
13
|
CUSTOM_FIELD_CSV_NAME = 'custom_fields.csv'
|
14
14
|
GRANTS_CSV_NAME = 'grants.csv'
|
15
15
|
|
16
|
+
attr_accessor :client
|
17
|
+
|
16
18
|
@base_url = nil
|
17
19
|
@auth_header = nil
|
18
20
|
@file_url = nil
|
19
21
|
@file_path = nil
|
20
22
|
@is_complete = false
|
21
23
|
@client = nil
|
24
|
+
@models = nil
|
22
25
|
|
23
|
-
def initialize(base_url, key, secret)
|
26
|
+
def initialize(base_url, key, secret, models = nil)
|
24
27
|
@base_url = base_url
|
25
|
-
@auth_header = 'Basic ' +
|
28
|
+
@auth_header = 'Basic ' + Base64.strict_encode64("#{key}:#{secret}")
|
26
29
|
@client = BridgeAPI::Client.new(prefix: base_url, api_key: key, api_secret: secret)
|
30
|
+
@models = models
|
27
31
|
end
|
28
32
|
|
29
33
|
def start_data_report
|
30
|
-
|
34
|
+
raw_dumps = get_dumps
|
35
|
+
dumps = raw_dumps.members
|
36
|
+
unless dumps.empty?
|
37
|
+
dump = dumps.first
|
38
|
+
case dump['status']
|
39
|
+
when 'pending'
|
40
|
+
return
|
41
|
+
when 'complete'
|
42
|
+
return if Time.parse(dump['date']) > Time.now - 300
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@models.present? ? @client.create_data_dump({only: @models}) : @client.create_data_dump
|
31
46
|
end
|
32
47
|
|
33
48
|
def status
|
34
49
|
dumps = get_dumps
|
35
|
-
|
36
|
-
|
37
|
-
else
|
38
|
-
return BridgeBlueprint::Constants::STATUS_NOT_FOUND
|
39
|
-
end
|
50
|
+
return get_dumps.first['status'] unless dumps.members.empty?
|
51
|
+
BridgeBlueprint::Constants::STATUS_NOT_FOUND
|
40
52
|
end
|
41
53
|
|
42
|
-
def
|
43
|
-
@file_path = path
|
54
|
+
def remote_url
|
44
55
|
uri = URI.parse(@base_url)
|
45
56
|
http = Net::HTTP.new(uri.host, uri.port)
|
46
57
|
http.read_timeout = 300
|
47
|
-
http.use_ssl = (uri.scheme ==
|
58
|
+
http.use_ssl = (uri.scheme == 'https')
|
48
59
|
req = Net::HTTP::Get.new("#{@base_url}/api/admin/data_dumps/download")
|
49
|
-
req.add_field(
|
60
|
+
req.add_field('Authorization', @auth_header)
|
50
61
|
res = http.request(req)
|
51
|
-
|
52
|
-
|
53
|
-
|
62
|
+
res['location']
|
63
|
+
end
|
64
|
+
|
65
|
+
def store_file(path)
|
66
|
+
@file_path = path
|
67
|
+
url = remote_url
|
68
|
+
raise 'Missing location url from bridge data dump response' if url.blank?
|
69
|
+
File.open(@file_path, 'w') do |_file|
|
70
|
+
IO.copy_stream(open(url), @file_path)
|
54
71
|
end
|
55
72
|
end
|
56
73
|
|
@@ -62,11 +79,10 @@ module BridgeBlueprint
|
|
62
79
|
|
63
80
|
def get_headers
|
64
81
|
{
|
65
|
-
|
66
|
-
|
67
|
-
|
82
|
+
'Authorization' => @auth_header,
|
83
|
+
'Content-Type' => 'application/json',
|
84
|
+
'Accept' => 'application/json'
|
68
85
|
}
|
69
86
|
end
|
70
87
|
end
|
71
|
-
|
72
88
|
end
|
data/lib/bridge_blueprint.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
2
4
|
require 'zip'
|
3
5
|
|
4
6
|
describe BridgeBlueprint::DataDump do
|
5
|
-
|
6
7
|
before(:each) do
|
7
8
|
dir = Dir.mktmpdir
|
8
9
|
zip_folder_path = "#{File.dirname(__FILE__)}/../fixtures/bridge_zip"
|
9
10
|
input_filenames = [
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
'users.csv',
|
12
|
+
'custom_fields.csv'
|
13
|
+
]
|
13
14
|
|
14
15
|
@zipfile_name = "#{dir}/dump.zip"
|
15
16
|
|
@@ -24,11 +25,11 @@ describe BridgeBlueprint::DataDump do
|
|
24
25
|
it 'should parse a bridge data dump file' do
|
25
26
|
file = BridgeBlueprint::DataDump.new(@zipfile_name)
|
26
27
|
user_count = 0
|
27
|
-
file.each_row('users') do |
|
28
|
+
file.each_row('users') do |_user|
|
28
29
|
user_count += 1
|
29
30
|
end
|
30
31
|
custom_field_count = 0
|
31
|
-
file.each_row('custom_fields') do |
|
32
|
+
file.each_row('custom_fields') do |_custom_field|
|
32
33
|
custom_field_count += 1
|
33
34
|
end
|
34
35
|
expect(user_count).to(eq(2))
|
@@ -1,15 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
2
4
|
require 'zip'
|
3
5
|
|
4
6
|
describe BridgeBlueprint::RemoteData do
|
5
|
-
|
6
7
|
before(:each) do
|
7
8
|
@dir = Dir.mktmpdir
|
8
9
|
zip_folder_path = "#{File.dirname(__FILE__)}/../fixtures/bridge_zip"
|
9
10
|
input_filenames = [
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
'users.csv',
|
12
|
+
'custom_fields.csv'
|
13
|
+
]
|
13
14
|
|
14
15
|
@zipfile_name = "#{@dir}/dump.zip"
|
15
16
|
|
@@ -19,14 +20,35 @@ describe BridgeBlueprint::RemoteData do
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
|
-
stub_request(:get,
|
23
|
-
|
24
|
-
|
23
|
+
stub_request(:get, 'https://example.com/fake-file-url')
|
24
|
+
.with(headers: { 'Accept' => '*/*', 'User-Agent' => 'Ruby' })
|
25
|
+
.to_return(status: 200, body: ->(_request) { File.open(@zipfile_name) }, headers: {})
|
25
26
|
end
|
26
27
|
|
27
28
|
describe 'completed' do
|
28
29
|
it 'should start a data dump' do
|
29
30
|
data = BridgeBlueprint::RemoteData.new('https://example.com', 'key', 'secret')
|
31
|
+
expect(data.client).to receive(:create_data_dump)
|
32
|
+
data.start_data_report
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'completed' do
|
37
|
+
it 'should not start a data dump if already pending' do
|
38
|
+
data = BridgeBlueprint::RemoteData.new('https://pending.com', 'key', 'secret')
|
39
|
+
expect(data.client).not_to receive(:create_data_dump)
|
40
|
+
data.start_data_report
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should not start a data dump if one has already completed in the past 5 minutes' do
|
44
|
+
data = BridgeBlueprint::RemoteData.new('https://recent.com', 'key', 'secret')
|
45
|
+
expect(data.client).not_to receive(:create_data_dump)
|
46
|
+
data.start_data_report
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should start a data dump if one hasnt already completed in the past 5 minutes' do
|
50
|
+
data = BridgeBlueprint::RemoteData.new('https://notrecent.com', 'key', 'secret')
|
51
|
+
expect(data.client).to receive(:create_data_dump)
|
30
52
|
data.start_data_report
|
31
53
|
end
|
32
54
|
end
|
@@ -43,8 +65,7 @@ describe BridgeBlueprint::RemoteData do
|
|
43
65
|
data = BridgeBlueprint::RemoteData.new('https://example.com', 'key', 'secret')
|
44
66
|
dir = Dir.mktmpdir
|
45
67
|
data.store_file("#{@dir}/data_dump.csv")
|
46
|
-
expect(File.
|
68
|
+
expect(File.exist?("#{@dir}/data_dump.csv")).to(eq(true))
|
47
69
|
end
|
48
70
|
end
|
49
|
-
|
50
71
|
end
|
data/spec/support/fake_bridge.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'sinatra/base'
|
2
4
|
require 'tilt'
|
3
5
|
|
4
6
|
class FakeBridge < Sinatra::Base
|
5
|
-
|
6
7
|
## Course Templates
|
7
8
|
|
8
9
|
get %r{/api/author/course_templates$} do
|
@@ -84,7 +85,7 @@ class FakeBridge < Sinatra::Base
|
|
84
85
|
get_json_data 200, 'enrollment.json'
|
85
86
|
end
|
86
87
|
|
87
|
-
#Custom Fields
|
88
|
+
# Custom Fields
|
88
89
|
|
89
90
|
get %r{/api/author/custom_fields} do
|
90
91
|
get_json_data 200, 'custom_fields.json'
|
@@ -109,7 +110,20 @@ class FakeBridge < Sinatra::Base
|
|
109
110
|
# Data Dumps
|
110
111
|
|
111
112
|
get %r{/api/admin/data_dumps$} do
|
112
|
-
|
113
|
+
host = URI.parse(url).host
|
114
|
+
if host == 'pending.com'
|
115
|
+
get_json_data 200, 'data_dumps_pending.json'
|
116
|
+
elsif host == 'notrecent.com'
|
117
|
+
data = JSON.parse(fixture('data_dumps.json').read)
|
118
|
+
data['data_dumps'][0]['date'] = (Time.now - 310).to_s
|
119
|
+
custom_response(data.to_json)
|
120
|
+
elsif host == 'recent.com'
|
121
|
+
data = JSON.parse(fixture('data_dumps.json').read)
|
122
|
+
data['data_dumps'][0]['date'] = (Time.now - 290).to_s
|
123
|
+
custom_response(data.to_json)
|
124
|
+
else
|
125
|
+
get_json_data 200, 'data_dumps.json'
|
126
|
+
end
|
113
127
|
end
|
114
128
|
|
115
129
|
post %r{/api/admin/data_dumps$} do
|
@@ -119,19 +133,24 @@ class FakeBridge < Sinatra::Base
|
|
119
133
|
get %r{/api/admin/data_dumps/download.*} do
|
120
134
|
content_type :json
|
121
135
|
status 200
|
122
|
-
headers[:location] =
|
136
|
+
headers[:location] = 'https://example.com/fake-file-url'
|
123
137
|
end
|
124
138
|
|
125
139
|
private
|
126
140
|
|
141
|
+
def custom_response(data)
|
142
|
+
content_type :json
|
143
|
+
status 200
|
144
|
+
data
|
145
|
+
end
|
146
|
+
|
127
147
|
def get_json_data(response_code, file_name)
|
128
148
|
content_type :json
|
129
149
|
status response_code
|
130
|
-
|
131
|
-
File.open(File.dirname(__FILE__) + '/../fixtures/' + file_name).read
|
132
|
-
else
|
150
|
+
if file_name.nil?
|
133
151
|
{}
|
152
|
+
else
|
153
|
+
File.open(File.dirname(__FILE__) + '/../fixtures/' + file_name).read
|
134
154
|
end
|
135
155
|
end
|
136
|
-
|
137
156
|
end
|
data/spec/test_helper.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
1
4
|
require 'bridge_blueprint'
|
2
5
|
require 'rspec'
|
3
6
|
require 'webmock/rspec'
|
@@ -5,7 +8,7 @@ require 'json'
|
|
5
8
|
require 'pry'
|
6
9
|
|
7
10
|
RSpec.configure do |config|
|
8
|
-
Dir[
|
11
|
+
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
9
12
|
|
10
13
|
config.before(:each) do
|
11
14
|
WebMock.disable_net_connect!
|
@@ -13,7 +16,6 @@ RSpec.configure do |config|
|
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
|
17
19
|
def fixture(*file)
|
18
|
-
File.new(File.join(File.expand_path(
|
20
|
+
File.new(File.join(File.expand_path('fixtures', __dir__), *file))
|
19
21
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridge_blueprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Shaffer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bridge_api
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.1.16
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.1.16
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.2.1
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: bundler
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,35 +73,35 @@ dependencies:
|
|
87
73
|
- !ruby/object:Gem::Version
|
88
74
|
version: 1.0.0
|
89
75
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
76
|
+
name: byebug
|
91
77
|
requirement: !ruby/object:Gem::Requirement
|
92
78
|
requirements:
|
93
79
|
- - "~>"
|
94
80
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
81
|
+
version: 8.2.2
|
96
82
|
type: :development
|
97
83
|
prerelease: false
|
98
84
|
version_requirements: !ruby/object:Gem::Requirement
|
99
85
|
requirements:
|
100
86
|
- - "~>"
|
101
87
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
88
|
+
version: 8.2.2
|
103
89
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
90
|
+
name: pry
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|
106
92
|
requirements:
|
107
93
|
- - "~>"
|
108
94
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
95
|
+
version: '0'
|
110
96
|
type: :development
|
111
97
|
prerelease: false
|
112
98
|
version_requirements: !ruby/object:Gem::Requirement
|
113
99
|
requirements:
|
114
100
|
- - "~>"
|
115
101
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
102
|
+
version: '0'
|
117
103
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
104
|
+
name: rake
|
119
105
|
requirement: !ruby/object:Gem::Requirement
|
120
106
|
requirements:
|
121
107
|
- - "~>"
|
@@ -129,25 +115,47 @@ dependencies:
|
|
129
115
|
- !ruby/object:Gem::Version
|
130
116
|
version: '0'
|
131
117
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
118
|
+
name: rspec
|
133
119
|
requirement: !ruby/object:Gem::Requirement
|
134
120
|
requirements:
|
135
|
-
- - "
|
121
|
+
- - "~>"
|
136
122
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
123
|
+
version: '2.6'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
138
128
|
- - "~>"
|
139
129
|
- !ruby/object:Gem::Version
|
140
|
-
version: '
|
130
|
+
version: '2.6'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rubocop
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.54.0
|
141
138
|
type: :development
|
142
139
|
prerelease: false
|
143
140
|
version_requirements: !ruby/object:Gem::Requirement
|
144
141
|
requirements:
|
145
|
-
- - "
|
142
|
+
- - "~>"
|
146
143
|
- !ruby/object:Gem::Version
|
147
|
-
version:
|
144
|
+
version: 0.54.0
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: simplecov
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
148
149
|
- - "~>"
|
149
150
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
151
|
+
version: 0.16.1
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 0.16.1
|
151
159
|
- !ruby/object:Gem::Dependency
|
152
160
|
name: sinatra
|
153
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,19 +171,39 @@ dependencies:
|
|
163
171
|
- !ruby/object:Gem::Version
|
164
172
|
version: '1.0'
|
165
173
|
- !ruby/object:Gem::Dependency
|
166
|
-
name:
|
174
|
+
name: tilt
|
167
175
|
requirement: !ruby/object:Gem::Requirement
|
168
176
|
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: 1.3.4
|
169
180
|
- - "~>"
|
170
181
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
182
|
+
version: '1.3'
|
172
183
|
type: :development
|
173
184
|
prerelease: false
|
174
185
|
version_requirements: !ruby/object:Gem::Requirement
|
175
186
|
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 1.3.4
|
176
190
|
- - "~>"
|
177
191
|
- !ruby/object:Gem::Version
|
178
|
-
version:
|
192
|
+
version: '1.3'
|
193
|
+
- !ruby/object:Gem::Dependency
|
194
|
+
name: webmock
|
195
|
+
requirement: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - "~>"
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: 2.3.1
|
200
|
+
type: :development
|
201
|
+
prerelease: false
|
202
|
+
version_requirements: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - "~>"
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: 2.3.1
|
179
207
|
description: Tools for consuming bridge data dumps
|
180
208
|
email:
|
181
209
|
- jshaffer@instructure.com
|
@@ -184,11 +212,17 @@ extensions: []
|
|
184
212
|
extra_rdoc_files: []
|
185
213
|
files:
|
186
214
|
- ".gitignore"
|
215
|
+
- ".rubocop.yml"
|
187
216
|
- ".ruby-version"
|
217
|
+
- ".simplecov"
|
218
|
+
- Dockerfile
|
188
219
|
- Gemfile
|
189
220
|
- Gemfile.lock
|
190
221
|
- README.rdoc
|
222
|
+
- bin/jenkins
|
191
223
|
- bridge_blueprint.gemspec
|
224
|
+
- build.sh
|
225
|
+
- docker-compose.yml
|
192
226
|
- lib/bridge_blueprint.rb
|
193
227
|
- lib/bridge_blueprint/constants.rb
|
194
228
|
- lib/bridge_blueprint/data_dump.rb
|
@@ -199,13 +233,14 @@ files:
|
|
199
233
|
- spec/fixtures/bridge_zip/custom_fields.csv
|
200
234
|
- spec/fixtures/bridge_zip/users.csv
|
201
235
|
- spec/fixtures/data_dumps.json
|
236
|
+
- spec/fixtures/data_dumps_pending.json
|
202
237
|
- spec/support/fake_bridge.rb
|
203
238
|
- spec/test_helper.rb
|
204
239
|
homepage: https://getbridge.com
|
205
240
|
licenses:
|
206
241
|
- MIT
|
207
242
|
metadata: {}
|
208
|
-
post_install_message:
|
243
|
+
post_install_message:
|
209
244
|
rdoc_options: []
|
210
245
|
require_paths:
|
211
246
|
- lib
|
@@ -220,17 +255,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
255
|
- !ruby/object:Gem::Version
|
221
256
|
version: '0'
|
222
257
|
requirements: []
|
223
|
-
|
224
|
-
|
225
|
-
signing_key:
|
258
|
+
rubygems_version: 3.1.6
|
259
|
+
signing_key:
|
226
260
|
specification_version: 4
|
227
261
|
summary: Bridge Blueprint
|
228
262
|
test_files:
|
229
263
|
- spec/bridge_blueprint/data_dump_spec.rb
|
230
264
|
- spec/bridge_blueprint/remote_data_spec.rb
|
265
|
+
- spec/support/fake_bridge.rb
|
231
266
|
- spec/fixtures/bridge_zip/custom_fields.csv
|
232
267
|
- spec/fixtures/bridge_zip/users.csv
|
233
268
|
- spec/fixtures/data_dumps.json
|
234
|
-
- spec/
|
269
|
+
- spec/fixtures/data_dumps_pending.json
|
235
270
|
- spec/test_helper.rb
|
236
|
-
has_rdoc:
|