Advertisement
asweigart

appstore test

May 5th, 2017
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 KB | None | 0 0
  1. -- Automated test for `appstore`
  2.  
  3. --local TAS_HOST = 'https://turtleappstore.com'
  4. local TAS_HOST = 'http://localhost:8000'
  5.  
  6. local USERNAME = 'AlSweigart'
  7. local APPNAME = 'haldo'
  8. local PERMALINK = 'KdS3dZ'
  9. local OTP = '123456' -- see DEBUG_MASTER_OTP in settings/local.py
  10. local FILENAME = 'localhaldo'
  11.  
  12. local BAD_PERMALINK = 'xxxxxx'
  13. local BAD_APPNAME = 'doesnotexist'
  14. local BAD_USERNAME = 'nosuchuser'
  15. local BAD_FILENAME = 'filedoesnotexist'
  16. local BAD_OTP = '999999'
  17.  
  18. local APPHEADER = '-- https://turtleappstore.com/u/' .. USERNAME .. '/a/' .. APPNAME
  19. local result
  20.  
  21. -- wipe existing appstore program and redownload
  22. shell.run('delete appstore')
  23. shell.run('delete .appstoreusername')
  24. shell.run('pastebin get iXRkjNsG appstore')
  25.  
  26. function delAppAndCache()
  27. shell.run('delete ' .. APPNAME)
  28. shell.run('delete .appstoreusername')
  29. shell.run('delete ' .. FILENAME)
  30. end
  31.  
  32. function cacheExists()
  33. if not fs.exists('.appstoreusername') then
  34. return false
  35. end
  36.  
  37. fo = fs.open('.appstoreusername', 'r')
  38. username = fo.readAll()
  39. fo.close()
  40.  
  41. return username == USERNAME
  42. end
  43.  
  44. function createCache()
  45. fo = fs.open('.appstoreusername', 'w')
  46. fo.write(USERNAME)
  47. fo.close()
  48. end
  49.  
  50. function createBlankApp()
  51. -- creates a file with the name APPNAME but with no content
  52. fo = fs.open(APPNAME, 'w')
  53. fo.write(APPHEADER)
  54. fo.close()
  55. end
  56.  
  57. function createFilename()
  58. -- creates the local file app
  59. fo = fs.open(FILENAME, 'w')
  60. fo.write(APPHEADER)
  61. fo.write('\nprint("local haldo!")')
  62. fo.close()
  63. end
  64.  
  65. function checkFiles(testNum)
  66. assert(fs.exists(APPNAME), 'T' .. testNum .. ' failed, no app')
  67. assert(cacheExists(), 'T' .. testNum .. ' failed, no cache')
  68. end
  69.  
  70. function checkAppNotBlank(testNum)
  71. fo = fs.open(APPNAME, 'r')
  72. content = fo.readAll()
  73. fo.close()
  74. assert(content ~= APPHEADER, 'T' .. testNum .. ' failed, app is blank')
  75. end
  76.  
  77.  
  78.  
  79. -- Test 0: Make sure you can connect
  80. assert(http.get(TAS_HOST) ~= nil, 'Cannot connect to ' .. TAS_HOST)
  81.  
  82.  
  83. -- Test 1: `appstore <permalink>`
  84. delAppAndCache()
  85. success = shell.run('appstore ' .. PERMALINK)
  86. checkFiles(1)
  87.  
  88. -- Test 2: `appstore <OVERWRITEpermalink>`
  89. delAppAndCache()
  90. createBlankApp()
  91. success = shell.run('appstore ' .. PERMALINK)
  92. checkFiles(2)
  93. checkAppNotBlank(2)
  94.  
  95.  
  96. -- Test 3: `appstore <404permalink>`
  97. delAppAndCache()
  98. success = shell.run('appstore ' .. BAD_PERMALINK)
  99. assert(not success, 'T3 failed')
  100.  
  101.  
  102. -- Test 4: `appstore get <NOCACHEappname>`
  103. delAppAndCache()
  104. success = shell.run('appstore get ' .. APPNAME)
  105. assert(not success, 'T4 failed')
  106.  
  107.  
  108. -- Test 5: `appstore get <404appname>`
  109. delAppAndCache()
  110. success = shell.run('appstore get ' .. BAD_APPNAME)
  111. assert(not success, 'T5 failed')
  112.  
  113.  
  114. -- Test 6: `appstore get <appname>`
  115. delAppAndCache()
  116. createCache()
  117. success = shell.run('appstore get ' .. APPNAME)
  118. assert(success, 'T6 failed')
  119. checkFiles(6)
  120.  
  121.  
  122. -- Test 7: `appstore get <username> <appname>`
  123. delAppAndCache()
  124. success = shell.run('appstore get ' .. USERNAME .. ' ' .. APPNAME)
  125. assert(success, 'T7 failed')
  126. checkFiles(7)
  127.  
  128.  
  129. -- Test 8: `appstore get <username> <404appname>`
  130. delAppAndCache()
  131. success = shell.run('appstore get ' .. USERNAME .. ' ' .. BAD_APPNAME)
  132. assert(not success, 'T8 failed')
  133.  
  134.  
  135. -- Test 9: `appstore get <username> <OVERWRITEappname>`
  136. delAppAndCache()
  137. createBlankApp()
  138. success = shell.run('appstore get ' .. USERNAME .. ' ' .. APPNAME)
  139. assert(success, 'T9 failed')
  140. checkFiles(9)
  141. checkAppNotBlank(9)
  142.  
  143.  
  144. -- Test 10: `appstore get <404username> <appname>`
  145. delAppAndCache()
  146. success = shell.run('appstore get ' .. BAD_USERNAME .. ' ' .. APPNAME)
  147. assert(not success, 'T10 failed')
  148.  
  149.  
  150. -- Test 11: `appstore run <appname>`
  151. delAppAndCache()
  152. createCache()
  153. success = shell.run('appstore run ' .. APPNAME)
  154. assert(success, 'T11 failed')
  155. checkFiles(11)
  156.  
  157.  
  158. -- Test 12: `appstore run <NOCACHEappname>`
  159. delAppAndCache()
  160. success = shell.run('appstore run ' .. APPNAME)
  161. assert(not success, 'T12 failed')
  162.  
  163.  
  164. -- Test 13: `appstore run <OVERWRITEappname>`
  165. delAppAndCache()
  166. createCache()
  167. createBlankApp()
  168. success = shell.run('appstore run ' .. APPNAME)
  169. assert(success, 'T13 failed')
  170. checkFiles(13)
  171. checkAppNotBlank(13)
  172.  
  173.  
  174. -- Test 14: `appstore run <permalink>`
  175. --[[
  176. -- canceled this test, removing this feature
  177. delAppAndCache()
  178. success = shell.run('appstore run ' .. PERMALINK)
  179. assert(success, 'T14 failed')
  180. checkFiles(14)
  181. ]]
  182.  
  183. -- Test 15: `appstore run <404permalink>`
  184. --[[
  185. -- canceled this test, removing this feature
  186. delAppAndCache()
  187. success = shell.run('appstore run ' .. BAD_PERMALINK)
  188. assert(not success, 'T15 failed')
  189. ]]
  190.  
  191. -- Test 16: `appstore run <username> <appname>`
  192. delAppAndCache()
  193. success = shell.run('appstore run ' .. USERNAME .. ' ' .. APPNAME)
  194. assert(success, 'T16 failed')
  195. checkFiles(16)
  196.  
  197.  
  198. -- Test 17: `appstore run <404username> <appname>`
  199. delAppAndCache()
  200. success = shell.run('appstore run ' .. BAD_USERNAME .. ' ' .. APPNAME)
  201. assert(not success, 'T17 failed')
  202.  
  203.  
  204. -- Test 18: `appstore run <username> <404appname>`
  205. delAppAndCache()
  206. success = shell.run('appstore run ' .. USERNAME .. ' ' .. BAD_APPNAME)
  207. assert(not success, 'T18 failed')
  208.  
  209.  
  210. -- Test 19: `appstore put <filename> <otp>`
  211. delAppAndCache()
  212. createCache()
  213. createFilename()
  214. success = shell.run('appstore put ' .. FILENAME .. ' ' .. OTP)
  215. assert(success, 'T19 failed')
  216.  
  217.  
  218. -- Test 20: `appstore put <NOCACHEfilename> <otp>`
  219. delAppAndCache()
  220. createFilename()
  221. success = shell.run('appstore put ' .. FILENAME .. ' ' .. OTP)
  222. assert(not success, 'T20 failed')
  223.  
  224.  
  225. -- Test 21: `appstore put <404filename> <otp>`
  226. delAppAndCache()
  227. createFilename()
  228. createCache()
  229. success = shell.run('appstore put ' .. BAD_FILENAME .. ' ' .. OTP)
  230. assert(not success, 'T21 failed')
  231.  
  232.  
  233. -- Test 22: `appstore put <filename> <BADotp>`
  234. delAppAndCache()
  235. createFilename()
  236. createCache()
  237. success = shell.run('appstore put ' .. FILENAME .. ' ' .. BAD_OTP)
  238. assert(not success, 'T22 failed')
  239.  
  240.  
  241. -- Test 23: `appstore update <filename>`
  242. delAppAndCache()
  243. createBlankApp()
  244. createCache()
  245. success = shell.run('appstore update ' .. FILENAME)
  246. assert(not success, 'T23 failed')
  247. -- TODO check the new file to make sure it was updated
  248.  
  249.  
  250. -- Test 24: `appstore update <404filename>`
  251. delAppAndCache()
  252. createBlankApp()
  253. createCache()
  254. success = shell.run('appstore update ' .. BAD_FILENAME)
  255. assert(not success, 'T24 failed')
  256.  
  257.  
  258. -- Test 25: `appstore update <NO_HEADERfilename>`
  259. delAppAndCache()
  260. fo = fs.open(APPNAME, 'w')
  261. fo.close()
  262. createCache()
  263. success = shell.run('appstore update ' .. FILENAME)
  264. assert(not success, 'T25 failed')
  265.  
  266.  
  267. -- Test 26: `appstore updateall`
  268. delAppAndCache()
  269. fo = fs.open(APPNAME .. '1', 'w')
  270. fo.write('-- https://turtleappstore.com/u/' .. USERNAME .. '/a/' .. APPNAME .. '1')
  271. fo.close()
  272. fo = fs.open(APPNAME .. '2', 'w')
  273. fo.write('-- https://turtleappstore.com/u/' .. USERNAME .. '/a/' .. APPNAME .. '2')
  274. fo.close()
  275. createCache()
  276. success = shell.run('appstore updateall')
  277. shell.run('delete ' .. APPNAME .. '1')
  278. shell.run('delete ' .. APPNAME .. '2')
  279. assert(not success, 'T26 failed')
  280. -- TODO check the new file to make sure it was updated
  281. -- TODO check multiple files
  282.  
  283.  
  284. -- Test 27: `appstore boguscommand`
  285. delAppAndCache()
  286. success = shell.run('appstore boguscommand')
  287. assert(not success, 'T27 failed')
  288.  
  289.  
  290. -- Test : `appstore diff <filename>` when
  291. -- TODO - implement this
  292.  
  293.  
  294. -- Test : `appstore diff <404filename>` when
  295. -- TODO - implement this
  296.  
  297.  
  298. -- Test : `appstore diff <NO_HEADERfilename>` when
  299. -- TODO - implement this
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement