Skip to content

Commit

Permalink
Document Delete APIs and add TLV Command Statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Apr 16, 2024
1 parent 936212f commit 5953d22
Show file tree
Hide file tree
Showing 59 changed files with 665 additions and 393 deletions.
2 changes: 1 addition & 1 deletion demos/python/sdk_wireless_camera_control/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def tests(session) -> None:
"coverage[toml]",
"requests-mock",
)
session.run("pytest", "tests", "--cov-fail-under=65")
session.run("pytest", "tests/unit", "--cov-fail-under=70")


@session(python=SUPPORTED_VERSIONS[-1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,37 @@ class HttpCommands(HttpMessages[HttpMessage]):
To be used as a delegate for a GoProHttp to build commands
"""

@http_get_json_command(endpoint="/gp/gpControl/command/storage/delete/all")
async def delete_all(self) -> GoProResp[None]:
"""Delete all files on the SD card.
Returns:
GoProResp[None]: command status
"""

@http_get_json_command(endpoint="gopro/media/delete/file", arguments=["path"])
async def delete_file(self, *, path: str) -> GoProResp[None]:
"""Delete a single file including single files that are part of a group.
Args:
path (str): path to file to delete
Returns:
GoProResp[None]: command status
"""

@http_get_json_command(endpoint="/gp/gpControl/command/storage/delete/group", arguments=["p"])
async def delete_group(self, *, path: str) -> GoProResp[None]:
"""Delete all contents of a group. Should not be used on non-group files.
Args:
path (str): path to first file in the group.
Returns:
GoProResp[None]: command status
"""
return {"p": path} # type: ignore

@http_get_json_command(
endpoint="gopro/media/last_captured",
parser=Parser(json_parser=JsonParsers.PydanticAdapter(MediaPath)),
Expand Down
4 changes: 2 additions & 2 deletions demos/python/sdk_wireless_camera_control/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ isort = "*"
types-protobuf = "^4"

[tool.poe.tasks.tests]
cmd = "pytest tests --cov-fail-under=70"
cmd = "pytest tests/unit --cov-fail-under=70"
help = "Run unit tests"

[tool.poe.tasks._types]
Expand Down Expand Up @@ -121,7 +121,7 @@ help = "validate docstrings"

[tool.poe.tasks.docstrings]
sequence = ["_pydocstyle", "_darglint"]
help = "Format, check types, lint, check docstrings, and run unit tests"
help = "Analyze docstrings for consistency and errors"

[tool.poe.tasks.sphinx]
cmd = "sphinx-build -W --keep-going -a -E -b html docs docs/build"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# test_delete_media.py/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro).
# This copyright was auto-generated on Tue Apr 16 20:07:53 UTC 2024

import asyncio
from typing import AsyncGenerator

import pytest

from open_gopro import Params, proto
from open_gopro.gopro_wired import WiredGoPro
from open_gopro.models import MediaPath


@pytest.fixture(scope="function")
async def gopro() -> AsyncGenerator[WiredGoPro, None]:
async with WiredGoPro() as gopro:
assert (await gopro.http_command.delete_all()).ok
yield gopro


async def create_single_photo(gopro: WiredGoPro) -> MediaPath:
# Set a "single" photo preset
presets = (await gopro.http_command.get_preset_status()).data
photo_presets = next(group for group in presets["presetGroupArray"] if "photo" in group["id"].lower())
single_preset_id = next(preset for preset in photo_presets["presetArray"] if "single" in preset["mode"].lower())[
"id"
]
assert (await gopro.http_command.load_preset(preset=single_preset_id)).ok

assert (await gopro.http_command.set_shutter(shutter=Params.Toggle.ENABLE)).ok
photo = (await gopro.http_command.get_last_captured_media()).data
# Sanity check photo is in media list
assert photo in (await gopro.http_command.get_media_list()).data
return photo


async def create_burst_photo(gopro: WiredGoPro) -> MediaPath:
# Set a "burst" photo preset
presets = (await gopro.http_command.get_preset_status()).data
photo_presets = next(group for group in presets["presetGroupArray"] if "photo" in group["id"].lower())
burst_preset_id = next(preset for preset in photo_presets["presetArray"] if "burst" in preset["mode"].lower())["id"]
assert (await gopro.http_command.load_preset(preset=burst_preset_id)).ok

assert (await gopro.http_command.set_shutter(shutter=Params.Toggle.ENABLE)).ok
grouped_photo = (await gopro.http_command.get_last_captured_media()).data
# Sanity check photo is in media list
assert grouped_photo in (await gopro.http_command.get_media_list()).data
return grouped_photo


async def create_timelapse_photo(gopro: WiredGoPro) -> MediaPath:
# Set a "timelapse" photo preset
presets = (await gopro.http_command.get_preset_status()).data
timelapse_presets = next(group for group in presets["presetGroupArray"] if "timelapse" in group["id"].lower())
assert (await gopro.http_command.load_preset_group(group=proto.EnumPresetGroup.PRESET_GROUP_ID_TIMELAPSE)).ok
assert (await gopro.http_setting.media_format.set(Params.MediaFormat.TIME_LAPSE_PHOTO)).ok
lapse_id = next(preset for preset in timelapse_presets["presetArray"] if "lapse_photo" in preset["mode"].lower())[
"id"
]
assert (await gopro.http_command.load_preset(preset=lapse_id)).ok

# Take a timelapse
assert (await gopro.http_command.set_shutter(shutter=Params.Toggle.ENABLE)).ok
await asyncio.sleep(3)
assert (await gopro.http_command.set_shutter(shutter=Params.Toggle.DISABLE)).ok

grouped_photo = (await gopro.http_command.get_last_captured_media()).data
# Sanity check photo is in media list
assert grouped_photo in (await gopro.http_command.get_media_list()).data
return grouped_photo


@pytest.mark.timeout(60)
class TestOpenGoPro:
"""
Test already-existing but not yet documented open gopro endpoints.
Results:
- the delete group endpoint does not exist
- the delete file endpoint succeeds in deleting both single and grouped (burst) files.
"""

@pytest.mark.asyncio
async def test_delete_file_deletes_single_file(self, gopro: WiredGoPro):
# GIVEN
photo = await create_single_photo(gopro)

# WHEN
assert (await gopro.http_command.delete_file(path=photo.as_path)).ok

# THEN
media_list = (await gopro.http_command.get_media_list()).data.files
assert not media_list # Media list should be empty

@pytest.mark.asyncio
async def test_delete_file_partially_deletes_burst_group(self, gopro: WiredGoPro):
# GIVEN
burst_group = await create_burst_photo(gopro)

# WHEN
assert (await gopro.http_command.delete_file(path=burst_group.as_path)).ok

# THEN
media_list = (await gopro.http_command.get_media_list()).data.files
assert media_list
assert burst_group not in media_list

@pytest.mark.asyncio
async def test_delete_file_partially_deletes_timelapse_group(self, gopro: WiredGoPro):
# GIVEN
timelapse_group = await create_timelapse_photo(gopro)

# WHEN
assert (await gopro.http_command.delete_file(path=timelapse_group.as_path)).ok

# THEN
media_list = (await gopro.http_command.get_media_list()).data.files
assert media_list
assert timelapse_group not in media_list

@pytest.mark.asyncio
async def test_delete_group_deletes_burst_group(self, gopro: WiredGoPro):
# GIVEN
burst_group = await create_burst_photo(gopro)

# WHEN
assert (await gopro.http_command.delete_group(path=burst_group.as_path)).ok

# THEN
media_list = (await gopro.http_command.get_media_list()).data.files
assert not media_list

@pytest.mark.asyncio
async def test_delete_group_deletes_timelapse_group(self, gopro: WiredGoPro):
# GIVEN
timelapse_group = await create_timelapse_photo(gopro)

# WHEN
assert (await gopro.http_command.delete_group(path=timelapse_group.as_path)).ok

# THEN
media_list = (await gopro.http_command.get_media_list()).data.files
assert not media_list
2 changes: 1 addition & 1 deletion docs/ble/_static/css/badge_only.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/ble/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* documentation_options.js/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro). */
/* This copyright was auto-generated on Fri Apr 12 21:59:45 UTC 2024 */
/* This copyright was auto-generated on Tue Apr 16 20:07:58 UTC 2024 */

const DOCUMENTATION_OPTIONS = {
VERSION: '0.0.1',
Expand Down
2 changes: 1 addition & 1 deletion docs/ble/_static/jquery.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/ble/_static/js/badge_only.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/ble/_static/js/html5shiv-printshiv.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/ble/_static/js/html5shiv.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/ble/_static/js/theme.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/ble/_static/language_data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* language_data.js/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro). */
/* This copyright was auto-generated on Fri Apr 12 21:59:45 UTC 2024 */
/* This copyright was auto-generated on Tue Apr 16 20:07:58 UTC 2024 */

/*
* language_data.js
Expand Down
2 changes: 1 addition & 1 deletion docs/ble/_static/pygments.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* pygments.css/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro). */
/* This copyright was auto-generated on Fri Apr 12 21:59:45 UTC 2024 */
/* This copyright was auto-generated on Tue Apr 16 20:07:58 UTC 2024 */

pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
Expand Down
2 changes: 1 addition & 1 deletion docs/ble/_static/sphinx_highlight.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* sphinx_highlight.js/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro). */
/* This copyright was auto-generated on Fri Apr 12 21:59:45 UTC 2024 */
/* This copyright was auto-generated on Tue Apr 16 20:07:58 UTC 2024 */

/* Highlighting utilities for Sphinx HTML documentation. */
"use strict";
Expand Down
Loading

0 comments on commit 5953d22

Please sign in to comment.