Skip to content

Commit

Permalink
Update category (#72)
Browse files Browse the repository at this point in the history
- API support
- Documented example

Co-authored-by: Steve Chaloner <steve@seats.io>
  • Loading branch information
schaloner and Steve Chaloner committed Apr 30, 2024
1 parent 4966386 commit 388c9b3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -106,6 +106,14 @@ for category in category_list:
print(category.label)
```

### Updating a category

```python
import seatsio
client = seatsio.Client(seatsio.Region.EU(), secret_key="my-workspace-secret-key")
client.charts.update_category(chart_key=chart.key, category_key=1, label="Updated label", color="#bbbbbb", accessible=True)
```

### Listing all charts

```python
Expand Down
15 changes: 15 additions & 0 deletions seatsio/charts/chartsClient.py
Expand Up @@ -97,6 +97,12 @@ def list_categories(self, chart_key):
.get()
return Category.create_list(response["categories"])

def update_category(self, chart_key, category_key, label, color, accessible):
self.http_client.url("/charts/{chart_key}/categories/{category_key}",
chart_key=chart_key,
category_key=category_key) \
.post(UpdateCategoryRequest(label, color, accessible))

def move_to_archive(self, chart_key):
self.http_client.url("/charts/{key}/actions/move-to-archive", key=chart_key).post()

Expand Down Expand Up @@ -133,3 +139,12 @@ def validate_published_version(self, key):
def validate_draft_version(self, key):
response = self.http_client.url("/charts/{key}/version/draft/actions/validate", key=key).post()
return ChartValidation(json.loads(response.text))

class UpdateCategoryRequest:
def __init__(self, label, color, accessible):
if label:
self.label = label
if color:
self.color = color
if accessible:
self.accessible = accessible
11 changes: 11 additions & 0 deletions tests/charts/manageCategoriesTest.py
Expand Up @@ -35,3 +35,14 @@ def test_list_categories(self):
category_list = self.client.charts.list_categories(chart.key)
assert_that(category_list[0].key).is_equal_to(category1["key"])
assert_that(category_list[1].key).is_equal_to(category2["key"])

def test_update_category(self):
category1 = {"key": 1, "label": "Category 1", "color": "#aaaaaa", "accessible": False}
chart = self.client.charts.create(name="aChart", categories=[category1])

self.client.charts.update_category(chart_key=chart.key, category_key=1, label="Updated label", color="#bbbbbb", accessible=True)

category_list = self.client.charts.list_categories(chart.key)
assert_that(category_list[0].label).is_equal_to("Updated label")
assert_that(category_list[0].color).is_equal_to("#bbbbbb")
assert_that(category_list[0].accessible).is_true()

0 comments on commit 388c9b3

Please sign in to comment.