1
- require 'test/unit '
1
+ require 'minitest/autorun '
2
2
require 'tempfile'
3
3
require 'filepicker_client'
4
4
5
- class TestFilepickerClient < Test :: Unit :: TestCase
5
+ class TestFilepickerClient < Minitest :: Test
6
6
def setup
7
7
@api_key = ENV [ 'FPAPIKEY' ]
8
8
@api_secret = ENV [ 'FPAPISECRET' ]
@@ -16,7 +16,7 @@ def test_file_uri
16
16
17
17
def test_client_file_client_required
18
18
begin
19
- client_file = FilepickerClientFile . new ( { } , nil )
19
+ FilepickerClientFile . new ( { } , nil )
20
20
rescue FilepickerClientError => e
21
21
assert_equal "FilepickerClientFile client required" , e . message
22
22
error_fired = true
@@ -25,6 +25,78 @@ def test_client_file_client_required
25
25
assert error_fired , "FilepickerClientFile did not require a client as it should"
26
26
end
27
27
28
+ def test_store_string_text_file
29
+ assert @api_key , "Must set FPAPIKEY for this test"
30
+ assert @api_secret , "Must set FPAPISECRET for this test"
31
+
32
+ client = FilepickerClient . new @api_key , @api_secret
33
+ content = "test file content\n " * 10
34
+
35
+ begin
36
+ # store
37
+ file = client . store_content ( content , 'filename.txt' , 'test' )
38
+
39
+ # file attributes
40
+ assert_match ( /^filename\. txt/ , file . filename )
41
+
42
+ #file_uri
43
+ file_uri = file . file_uri
44
+ assert_equal "https://www.filepicker.io/api/file/#{ file . handle } " , file_uri . to_s
45
+
46
+ # stat
47
+ stats = file . stat
48
+ assert_equal content . length , stats [ :size ]
49
+ assert_equal 'text/plain' , stats [ :mimetype ]
50
+
51
+ # read
52
+ downloaded_content = file . read
53
+ assert_equal content , downloaded_content
54
+
55
+ #remove test file
56
+ assert file . remove
57
+ rescue Exception => e
58
+ raise e # reraise to have error reported
59
+ end
60
+ end
61
+
62
+ def test_store_string_image_file
63
+ assert @api_key , "Must set FPAPIKEY for this test"
64
+ assert @api_secret , "Must set FPAPISECRET for this test"
65
+
66
+ client = FilepickerClient . new @api_key , @api_secret
67
+
68
+ image_file = File . open ( 'test/image.jpeg' )
69
+ content = image_file . read
70
+
71
+ begin
72
+ # store
73
+ file = client . store_content ( content , 'filename.jpeg' , 'test' )
74
+
75
+ # file attributes
76
+ assert_match ( /^filename\. jpeg/ , file . filename )
77
+
78
+ #file_uri
79
+ file_uri = file . file_uri
80
+ assert_equal "https://www.filepicker.io/api/file/#{ file . handle } " , file_uri . to_s
81
+
82
+ # stat
83
+ stats = file . stat
84
+ assert_equal image_file . size , stats [ :size ]
85
+ assert_equal 'text/plain' , stats [ :mimetype ]
86
+
87
+ # read
88
+ downloaded_content = file . read
89
+ assert_equal content , downloaded_content
90
+
91
+ #remove test file
92
+ assert file . remove
93
+ rescue Exception => e
94
+ raise e # reraise to have error reported
95
+ end
96
+ end
97
+
98
+
99
+
28
100
def test_file
29
101
assert @api_key , "Must set FPAPIKEY for this test"
30
102
assert @api_secret , "Must set FPAPISECRET for this test"
@@ -48,7 +120,7 @@ def test_file
48
120
file = client . store ( store_file , 'test' )
49
121
50
122
# file attributes
51
- assert_match /^test\. txt/ , file . filename
123
+ assert_match ( /^test\. txt/ , file . filename )
52
124
53
125
#file_uri
54
126
file_uri = file . file_uri
@@ -65,7 +137,7 @@ def test_file
65
137
66
138
# store_url
67
139
second_file = client . store_url file . file_read_uri_and_expiry [ :uri ] , 'test'
68
- assert_not_equal second_file . handle , file . handle
140
+ assert ( second_file . handle != file . handle )
69
141
assert_equal second_file . read , content
70
142
71
143
# write
0 commit comments