PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/test/flix_cloud/notification_test.rb

https://github.com/micahalles/flix_cloud-gem
Ruby | 223 lines | 203 code | 20 blank | 0 comment | 0 complexity | f31573d8fb104dbac08321d3d7c31a2a MD5 | raw file
  1. require 'test_helper'
  2. class FlixCloud::NotificationTest < Test::Unit::TestCase
  3. context "When initializing with a string containing xml" do
  4. setup do
  5. @notification = FlixCloud::Notification.new(
  6. %{<?xml version="1.0" encoding="UTF-8"?>
  7. <job>
  8. <finished-job-at type="datetime">2009-04-10T20:13:02Z</finished-job-at>
  9. <id type="integer">1</id>
  10. <initialized-job-at type="datetime">2009-04-10T20:05:28Z</initialized-job-at>
  11. <recipe-name>testerrrr</recipe-name>
  12. <recipe-id type="integer">172</recipe-id>
  13. <state>successful_job</state>
  14. <error-message>error message</error-message>
  15. <input-media-file>
  16. <url>s3://flixcloud-test/small.mov</url>
  17. <width>1280</width>
  18. <height>720</height>
  19. <size>1732204</size>
  20. <duration>900</duration>
  21. <cost>0</cost>
  22. </input-media-file>
  23. <output-media-file>
  24. <url>s3://flixcloud-test/fsdfasdf.mov</url>
  25. <width>320</width>
  26. <height>176</height>
  27. <size>44126</size>
  28. <duration>700</duration>
  29. <cost>123</cost>
  30. </output-media-file>
  31. <watermark-file>
  32. <url>http://dl.getdropbox.com/u/378873/zencoder_test.mov</url>
  33. <size>1234</size>
  34. <cost>321</cost>
  35. </watermark-file>
  36. <thumbnail-media-file>
  37. <url>http://dl.getdropbox.com/u/378873/zencoder_test.mov</url>
  38. <total-size>123</total-size>
  39. <cost>32</cost>
  40. <number_of_thumbnails>3</number_of_thumbnails>
  41. </thumbnail-media-file>
  42. </job>})
  43. end
  44. should "assign to all the attributes" do
  45. assert_not_nil @notification.xml
  46. assert_not_nil @notification.id
  47. assert_not_nil @notification.finished_job_at
  48. assert_not_nil @notification.initialized_job_at
  49. assert_not_nil @notification.recipe_name
  50. assert_not_nil @notification.recipe_id
  51. assert_not_nil @notification.state
  52. assert_not_nil @notification.error_message
  53. assert_not_nil @notification.input_media_file
  54. assert_not_nil @notification.input_media_file.size
  55. assert_not_nil @notification.input_media_file.url
  56. assert_not_nil @notification.input_media_file.height
  57. assert_not_nil @notification.input_media_file.width
  58. assert_not_nil @notification.input_media_file.cost
  59. assert_not_nil @notification.output_media_file
  60. assert_not_nil @notification.output_media_file.size
  61. assert_not_nil @notification.output_media_file.url
  62. assert_not_nil @notification.output_media_file.height
  63. assert_not_nil @notification.output_media_file.width
  64. assert_not_nil @notification.output_media_file.cost
  65. assert_not_nil @notification.watermark_file
  66. assert_not_nil @notification.watermark_file.size
  67. assert_not_nil @notification.watermark_file.url
  68. assert_not_nil @notification.watermark_file.cost
  69. assert_not_nil @notification.thumbnail_media_file.url
  70. assert_not_nil @notification.thumbnail_media_file.total_size
  71. assert_not_nil @notification.thumbnail_media_file.cost
  72. assert_not_nil @notification.thumbnail_media_file.number_of_thumbnails
  73. end
  74. end
  75. context "When initializing with a hash" do
  76. setup do
  77. @notification = FlixCloud::Notification.new({"job" => {"initialized_job_at" => "something",
  78. "input_media_file" => {"size" => "1732204",
  79. "url" => "s3://flixcloud-test/small.mov",
  80. "height" => "720",
  81. "duration" => "900",
  82. "width" => "1280",
  83. "cost" => "321"},
  84. "watermark_file" => {"size" => "1234",
  85. "url" => "http://dl.getdropbox.com/u/378873/zencoder_test.mov",
  86. "cost" => "0"},
  87. "output_media_file" => {"size" => "44126",
  88. "url" => "s3://flixcloud-test/fsdfasdf.mov",
  89. "height" => "176",
  90. "duration" => "700",
  91. "width" => "320",
  92. "cost" => "123"},
  93. "id" => 1,
  94. "recipe_id" => 172,
  95. "error_message" => 'error message',
  96. "finished_job_at" => 'something else',
  97. "recipe_name"=>"testerrrr",
  98. "state"=>"successful_job"}})
  99. end
  100. should "assign to all the attributes except the xml attribute" do
  101. assert_nil @notification.xml
  102. assert_not_nil @notification.id
  103. assert_not_nil @notification.finished_job_at
  104. assert_not_nil @notification.initialized_job_at
  105. assert_not_nil @notification.recipe_name
  106. assert_not_nil @notification.recipe_id
  107. assert_not_nil @notification.state
  108. assert_not_nil @notification.error_message
  109. assert_not_nil @notification.input_media_file
  110. assert_not_nil @notification.input_media_file.size
  111. assert_not_nil @notification.input_media_file.url
  112. assert_not_nil @notification.input_media_file.height
  113. assert_not_nil @notification.input_media_file.width
  114. assert_not_nil @notification.input_media_file.cost
  115. assert_not_nil @notification.output_media_file
  116. assert_not_nil @notification.output_media_file.size
  117. assert_not_nil @notification.output_media_file.url
  118. assert_not_nil @notification.output_media_file.height
  119. assert_not_nil @notification.output_media_file.width
  120. assert_not_nil @notification.output_media_file.cost
  121. assert_not_nil @notification.watermark_file
  122. assert_not_nil @notification.watermark_file.size
  123. assert_not_nil @notification.watermark_file.url
  124. assert_not_nil @notification.watermark_file.cost
  125. end
  126. end
  127. context "When initializing with a hash and the parameters are not nested beneath 'job'" do
  128. setup do
  129. @notification = FlixCloud::Notification.new({"initialized_job_at" => "something",
  130. "input_media_file" => {"size" => "1732204",
  131. "url" => "s3://flixcloud-test/small.mov",
  132. "height" => "720",
  133. "duration" => "900",
  134. "width" => "1280",
  135. "cost" => "321"},
  136. "watermark_file" => {"size" => "1234",
  137. "url" => "http://dl.getdropbox.com/u/378873/zencoder_test.mov",
  138. "cost" => "321"},
  139. "output_media_file" => {"size" => "44126",
  140. "url" => "s3://flixcloud-test/fsdfasdf.mov",
  141. "height" => "176",
  142. "duration" => "700",
  143. "width" => "320",
  144. "cost" => "321"},
  145. "id" => 1,
  146. "recipe_id" => 172,
  147. "error_message" => 'error message',
  148. "finished_job_at" => 'something else',
  149. "recipe_name"=>"testerrrr",
  150. "state"=>"successful_job"})
  151. end
  152. should "assign to all the attributes except the xml attribute" do
  153. assert_nil @notification.xml
  154. assert_not_nil @notification.id
  155. assert_not_nil @notification.finished_job_at
  156. assert_not_nil @notification.initialized_job_at
  157. assert_not_nil @notification.recipe_name
  158. assert_not_nil @notification.recipe_id
  159. assert_not_nil @notification.state
  160. assert_not_nil @notification.error_message
  161. assert_not_nil @notification.input_media_file
  162. assert_not_nil @notification.input_media_file.size
  163. assert_not_nil @notification.input_media_file.url
  164. assert_not_nil @notification.input_media_file.height
  165. assert_not_nil @notification.input_media_file.width
  166. assert_not_nil @notification.input_media_file.cost
  167. assert_not_nil @notification.output_media_file
  168. assert_not_nil @notification.output_media_file.size
  169. assert_not_nil @notification.output_media_file.url
  170. assert_not_nil @notification.output_media_file.height
  171. assert_not_nil @notification.output_media_file.width
  172. assert_not_nil @notification.output_media_file.cost
  173. assert_not_nil @notification.watermark_file
  174. assert_not_nil @notification.watermark_file.size
  175. assert_not_nil @notification.watermark_file.url
  176. assert_not_nil @notification.watermark_file.cost
  177. end
  178. end
  179. context "With a notification where the state is 'successful_job'" do
  180. setup do
  181. @notification = FlixCloud::Notification.new("state" => "successful_job")
  182. end
  183. should "be successful" do
  184. assert @notification.successful?
  185. end
  186. end
  187. context "With a notification where the state is 'failed_job'" do
  188. setup do
  189. @notification = FlixCloud::Notification.new("state" => "failed_job")
  190. end
  191. should "be failed" do
  192. assert @notification.failed?
  193. end
  194. end
  195. context "With a notification where the state is 'cancelled_job'" do
  196. setup do
  197. @notification = FlixCloud::Notification.new("state" => "cancelled_job")
  198. end
  199. should "be cancelled" do
  200. assert @notification.cancelled?
  201. end
  202. end
  203. end