test_models.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. # test_media_list.py/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro).
  2. # This copyright was auto-generated on Mon Jun 26 18:26:05 UTC 2023
  3. from typing import Final
  4. from open_gopro.models import (
  5. GroupedMediaItem,
  6. HttpInvalidSettingResponse,
  7. MediaItem,
  8. MediaList,
  9. MediaMetadata,
  10. PhotoMetadata,
  11. ScheduledCapture,
  12. VideoMetadata,
  13. streaming,
  14. )
  15. from open_gopro.models.streaming import WebcamResponse
  16. from open_gopro.parsers import ScheduledCaptureParser
  17. SINGLE_MEDIA_ITEM: Final = {
  18. "n": "GX010001.MP4",
  19. "cre": "1656931398",
  20. "mod": "1656931398",
  21. "glrv": "1366268",
  22. "ls": "-1",
  23. "s": "27469309",
  24. }
  25. GROUPED_MEDIA_ITEM: Final = {
  26. "n": "G0010010.JPG",
  27. "g": "1",
  28. "b": "10",
  29. "l": "39",
  30. "cre": "1657016833",
  31. "mod": "1657016833",
  32. "s": "170696972",
  33. "t": "b",
  34. "m": [],
  35. }
  36. MEDIA_LIST: Final = {
  37. "id": "23544241138403583",
  38. "media": [
  39. {
  40. "d": "100GOPRO",
  41. "fs": [
  42. {
  43. "n": "GX010001.MP4",
  44. "cre": "1656931398",
  45. "mod": "1656931398",
  46. "glrv": "1366268",
  47. "ls": "-1",
  48. "s": "27469309",
  49. },
  50. {"n": "GOPR0002.JPG", "cre": "1656931409", "mod": "1656931409", "s": "5518647"},
  51. {"n": "GOPR0003.JPG", "cre": "1656931440", "mod": "1656931440", "s": "4672440"},
  52. {
  53. "n": "GX010004.MP4",
  54. "cre": "1657013120",
  55. "mod": "1657013120",
  56. "glrv": "2489198",
  57. "ls": "-1",
  58. "s": "47939086",
  59. },
  60. {"n": "GOPR0005.JPG", "cre": "1657013127", "mod": "1657013127", "s": "7010699"},
  61. {"n": "GOPR0006.JPG", "cre": "1657013129", "mod": "1657013129", "s": "8596771"},
  62. {
  63. "n": "GX010007.MP4",
  64. "cre": "1657013162",
  65. "mod": "1657013162",
  66. "glrv": "1800635",
  67. "ls": "-1",
  68. "s": "33849822",
  69. },
  70. {
  71. "n": "GX010008.MP4",
  72. "cre": "1657013166",
  73. "mod": "1657013166",
  74. "glrv": "2400680",
  75. "ls": "-1",
  76. "s": "45571078",
  77. },
  78. {
  79. "n": "GX010009.MP4",
  80. "cre": "1657013171",
  81. "mod": "1657013171",
  82. "glrv": "2121971",
  83. "ls": "-1",
  84. "s": "41702381",
  85. },
  86. {
  87. "n": "G0010010.JPG",
  88. "g": "1",
  89. "b": "10",
  90. "l": "39",
  91. "cre": "1657016833",
  92. "mod": "1657016833",
  93. "s": "170696972",
  94. "t": "b",
  95. "m": [],
  96. },
  97. {
  98. "n": "G0020041.JPG",
  99. "g": "2",
  100. "b": "41",
  101. "l": "70",
  102. "cre": "1657018747",
  103. "mod": "1657018747",
  104. "s": "166729035",
  105. "t": "b",
  106. "m": [],
  107. },
  108. {
  109. "n": "GX010040.MP4",
  110. "cre": "1657018743",
  111. "mod": "1657018743",
  112. "glrv": "1167331",
  113. "ls": "-1",
  114. "s": "25086075",
  115. },
  116. {"n": "GOPR0039.JPG", "cre": "1724339068", "mod": "1724339068", "raw": "1", "s": "783927"},
  117. ],
  118. }
  119. ],
  120. }
  121. def test_single_media_item():
  122. assert MediaItem(**SINGLE_MEDIA_ITEM)
  123. def test_grouped_media_item():
  124. assert GroupedMediaItem(**GROUPED_MEDIA_ITEM)
  125. def test_media_list():
  126. media_list = MediaList(**MEDIA_LIST)
  127. assert media_list
  128. items = media_list.files
  129. assert len(items) == 13
  130. assert len([item for item in items if isinstance(item, GroupedMediaItem)]) == 2
  131. assert media_list.files[0].filename == "100GOPRO/GX010001.MP4"
  132. assert media_list.files[-1].raw == "1"
  133. VIDEO_METADATA: Final = {
  134. "cre": "1656927817",
  135. "s": "27469309",
  136. "mahs": "0",
  137. "us": "0",
  138. "mos": [],
  139. "eis": "0",
  140. "pta": "1",
  141. "ao": "stereo",
  142. "tr": "0",
  143. "mp": "0",
  144. "ct": "0",
  145. "rot": "0",
  146. "fov": "0",
  147. "lc": "0",
  148. "prjn": "9",
  149. "gumi": "1fd0ef36481b8ce8fdcb21e8f4ca2637",
  150. "ls": "1366268",
  151. "cl": "0",
  152. "avc_profile": "255",
  153. "profile": "255",
  154. "hc": "0",
  155. "hi": [],
  156. "dur": "4",
  157. "w": "5312",
  158. "h": "2988",
  159. "fps": "1001",
  160. "fps_denom": "30000",
  161. "prog": "1",
  162. "subsample": "0",
  163. }
  164. PHOTO_METADATA: Final = {
  165. "cre": "1656931408",
  166. "s": "5518647",
  167. "hc": "0",
  168. "us": "0",
  169. "mos": [],
  170. "eis": "0",
  171. "hdr": "0",
  172. "wdr": "0",
  173. "raw": "0",
  174. "tr": "0",
  175. "mp": "0",
  176. "ct": "4",
  177. "rot": "0",
  178. "fov": "28",
  179. "lc": "0",
  180. "prjn": "9",
  181. "gumi": "7e39f1de649dfdf94a84ca12d99c4ce5",
  182. "w": "5568",
  183. "h": "4872",
  184. }
  185. def test_video():
  186. meta = MediaMetadata.from_json(VIDEO_METADATA)
  187. assert isinstance(meta, VideoMetadata)
  188. def test_photo():
  189. assert isinstance(MediaMetadata.from_json(PHOTO_METADATA), PhotoMetadata)
  190. WEBCAM_SUCCESS_RSP = {
  191. "status": "2",
  192. "error": "0",
  193. }
  194. def test_webcam_success_response():
  195. response = WebcamResponse(**WEBCAM_SUCCESS_RSP)
  196. assert response.status == streaming.WebcamStatus.HIGH_POWER_PREVIEW
  197. assert response.error == streaming.WebcamError.SUCCESS
  198. WEBCAM_FAILURE_RSP = {
  199. "error": "4",
  200. "option_id": "2",
  201. "setting_id": "135",
  202. "supported_options": [
  203. {
  204. "display_name": "Auto Boost",
  205. "id": "4",
  206. },
  207. {
  208. "display_name": "Boost",
  209. "id": "3",
  210. },
  211. {
  212. "display_name": "On",
  213. "id": "1",
  214. },
  215. {
  216. "display_name": "Off",
  217. "id": "0",
  218. },
  219. ],
  220. }
  221. def test_webcam_failure_response():
  222. response = WebcamResponse(**WEBCAM_FAILURE_RSP)
  223. assert response.error == streaming.WebcamError.SHUTTER
  224. # Test our scrubbing of null values
  225. assert "None" not in str(response)
  226. HTTP_INVALID_SETTING_RSP = {
  227. "error": "4",
  228. "option_id": "100",
  229. "setting_id": "135",
  230. "supported_options": [
  231. {
  232. "display_name": "Auto Boost",
  233. "id": "4",
  234. },
  235. {
  236. "display_name": "Boost",
  237. "id": "3",
  238. },
  239. {
  240. "display_name": "On",
  241. "id": "1",
  242. },
  243. {
  244. "display_name": "Off",
  245. "id": "0",
  246. },
  247. ],
  248. }
  249. def test_invalid_setting_http_response():
  250. response = HttpInvalidSettingResponse(**HTTP_INVALID_SETTING_RSP)
  251. assert response.error == 4
  252. assert len(response.supported_options) == 4
  253. test = {
  254. "error": 4,
  255. "option_id": 100,
  256. "setting_id": 135,
  257. "supported_options": [
  258. {"display_name": "Auto Boost", "id": 4},
  259. {"display_name": "Boost", "id": 3},
  260. {"display_name": "On", "id": 1},
  261. {"display_name": "Off", "id": 0},
  262. ],
  263. }
  264. def test_printing():
  265. response = HttpInvalidSettingResponse(**HTTP_INVALID_SETTING_RSP)
  266. str(response)
  267. assert True
  268. def test_parse_schedule_capture():
  269. # GIVEN
  270. raw_bytes = bytes([0x00, 0x00, 0x0C, 0x8B])
  271. # WHEN
  272. scheduled_capture = ScheduledCaptureParser().parse(raw_bytes)
  273. # THEN
  274. assert scheduled_capture.hour == 12
  275. assert scheduled_capture.minute == 34
  276. assert scheduled_capture.is_24_hour == True
  277. assert scheduled_capture.is_enabled == True
  278. def test_build_schedule_capture():
  279. # GIVEN
  280. scheduled_capture = ScheduledCapture(hour=12, minute=34, is_24_hour=True, is_enabled=True)
  281. # WHEN
  282. raw_bytes = ScheduledCaptureParser().build(scheduled_capture)
  283. # THEN
  284. assert raw_bytes == bytes([0x00, 0x00, 0x0C, 0x8B])