Browse code

higher level functions, test from files

Blackbeard authored on 2018-09-15 20:45:29
Showing 2 changed files
... ...
@@ -39,10 +39,25 @@ function json_getValue {
39 39
 function json_getValueNested {
40 40
         local json_file="$1" 
41 41
         local outside_value="$2"
42
-	local nested_value="$3a"
42
+	local nested_value="$3"
43 43
 	
44 44
     echo "$json_file"   \
45
-	| jq ".results[] | .${outside_value}[] | .${nested_value}" 
45
+	| jq ".results[] | .${outside_value} | .${nested_value}" 
46
+}
47
+
48
+
49
+
50
+function json_TrackByNumber {
51
+        local json_file="$1" 
52
+	local track_number="$2"
53
+	echo "$(json_getValueNested "$json_file" tracks ["$track_number"])"
54
+}
55
+
56
+
57
+
58
+function json_TracksNames {
59
+        local json_file="$1" 
60
+	echo "$(json_getValueNested "$json_file" tracks[] name)"
46 61
 }
47 62
 
48 63
 
... ...
@@ -7,20 +7,22 @@
7 7
 
8 8
 
9 9
 test_json_downloadUrl() {
10
-     # If this test fails, might be related to wget vs curl vs ftp, make sure
11
-     # the file is correct
10
+    # apparently jamendo my answer two different urls    
12 11
     local expected_string="$(cat "../../files/json-tests/playlist-tracks.json")"
13 12
     local tested_url="https://api.jamendo.com/v3.0/playlists/tracks/?client_id=73efbf98&format=jsonpretty&id=500439691&limit=all"
14 13
     
15 14
     local function_string="$(_json_downloadUrl "$tested_url")"
15
+    echo "$function_string" > /tmp/tests_downloadURL.json
16
+    local tested_file="$(cat "/tmp/tests.json")"
16 17
     
17
-    assertEquals "$expected_string"  "$function_string"
18
+    assertEquals "$expected_string"  "$tested_file"
18 19
 }
19 20
 
20 21
 test_json_getValue() {
21 22
     local expected_string="$(cat "../../files/json-tests/name-user-playlists.test")"
22 23
     local playlists_url="https://api.jamendo.com/v3.0/playlists/?client_id=73efbf98&format=jsonpretty&user_id=6766768&limit=all"
23 24
     local tested_jsonFile="$(_json_downloadUrl "$playlists_url")"
25
+    
24 26
     local tested_value="name"
25 27
     
26 28
     local function_string="$(json_getValue "$tested_jsonFile" "$tested_value")"
... ...
@@ -34,7 +36,7 @@ test_json_getValueNested() {
34 36
     local testing_url="https://api.jamendo.com/v3.0/playlists/tracks/?client_id=73efbf98&format=jsonpretty&id=500439691&limit=all"
35 37
 
36 38
     local tested_jsonFile="$(_json_downloadUrl "$testing_url")"
37
-    local tested_outsideValue="tracks"
39
+    local tested_outsideValue="tracks[]"
38 40
     local tested_nestedValue="name"
39 41
     
40 42
     local function_string="$(json_getValueNested "$tested_jsonFile" "$tested_outsideValue" "$tested_nestedValue")"
... ...
@@ -43,6 +45,53 @@ test_json_getValueNested() {
43 45
 }
44 46
 
45 47
 
48
+test_json_getValueNested2() {
49
+    local expected_string="$(cat "../../files/json-tests/first-track.json"))"
50
+    local testing_url="https://api.jamendo.com/v3.0/playlists/tracks/?client_id=73efbf98&format=jsonpretty&id=500439691&limit=all"
51
+
52
+    local tested_jsonFile="$(_json_downloadUrl "$testing_url")"
53
+    local tested_outsideValue="tracks"
54
+    local tested_nestedValue="[1]"
55
+    
56
+    local function_string="$(json_getValueNested "$tested_jsonFile" "$tested_outsideValue" "$tested_nestedValue")"
57
+    echo "$function_string" > /tmp/tests_getValueNested2.json
58
+    local tested_file="$(cat "/tmp/tests_getValueNested2.json")"
59
+    
60
+    assertEquals "$expected_string"  "$tested_file"
61
+    
62
+
63
+}
64
+
65
+
66
+
67
+# test_json_TrackByNumber() {
68
+#     local expected_string="$(cat "../../files/json-tests/first-track.json"))"
69
+#     local testing_url="https://api.jamendo.com/v3.0/playlists/tracks/?client_id=73efbf98&format=jsonpretty&id=500439691&limit=all"
70
+
71
+#     local tested_jsonFile="$(_json_downloadUrl "$testing_url")"
72
+#     local tested_number="1"
73
+    
74
+#     local function_string="$(json_TrackByNumber "$tested_jsonFile" "$tested_number")"
75
+    
76
+#     assertSame "$expected_string"  "$function_string"
77
+# }
78
+
79
+
80
+# test_json_TracksNames() {
81
+#     local expected_string="$(cat "../../files/json-tests/name-tracks-playlist.test")"
82
+#     local testing_url="https://api.jamendo.com/v3.0/playlists/tracks/?client_id=73efbf98&format=jsonpretty&id=500439691&limit=all"
83
+
84
+#     local tested_jsonFile="$(_json_downloadUrl "$testing_url")"
85
+
86
+    
87
+#     local function_string="$(json_TracksNames "$tested_jsonFile")"
88
+    
89
+#     assertEquals "$expected_string"  "$function_string"
90
+# }
91
+
92
+
93
+
94
+
46 95
 
47 96
 #==============================
48 97
 #     PLAYLISTS URLS         #
... ...
@@ -56,5 +105,5 @@ oneTimeSetUp() {
56 105
     . ../../../lib/backend/jamendo/json.sh 
57 106
 }
58 107
 
59
-. ../../../lib/shunit2 
108
+. ../../shunit2 
60 109