Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cd test #295

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/build-upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: build-and-upload
on:
push:
tags:
- "*"
# TODO: remove pull request hook
pull_request:
jobs:
build-upload:
name: Build and upload to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install build dependencies
run: pip install --no-cache-dir -U pip .['build']
- name: Build package
run: rm -rf build/ dist/ && python -m build --sdist --wheel
- name: Upload to PyPI
# if: ${{ github.ref == 'refs/heads/main' }}
run: twine upload dist/*
env:
TWINE_REPOSITORY_URL: https://upload.pypi.org/legacy/
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
26 changes: 0 additions & 26 deletions .github/workflows/ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "thehive4py"
name = "pymatic"
description = "Python client for TheHive5"
version = "2.0.0b4"
requires-python = ">=3.8"
Expand Down
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from thehive4py.types.custom_field import OutputCustomField
from thehive4py.types.observable import InputObservable, OutputObservable
from thehive4py.types.observable_type import OutputObservableType
from thehive4py.types.page import OutputCasePage
from thehive4py.types.procedure import OutputProcedure
from thehive4py.types.profile import OutputProfile
from thehive4py.types.task import InputTask, OutputTask
Expand Down Expand Up @@ -202,6 +203,18 @@ def test_procedure(thehive: TheHiveApi, test_case: OutputCase) -> OutputProcedur
)


@pytest.fixture
def test_case_page(thehive: TheHiveApi, test_case: OutputCase) -> OutputCasePage:
return thehive.case.create_page(
case_id=test_case["_id"],
page={
"title": "my case page",
"category": "testing",
"content": "...",
},
)


@pytest.fixture
def test_timeline_event(
thehive: TheHiveApi, test_case: OutputCase
Expand Down
32 changes: 32 additions & 0 deletions tests/test_case_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
OutputCase,
)
from thehive4py.types.observable import InputObservable
from thehive4py.types.page import InputUpdateCasePage, OutputCasePage
from thehive4py.types.share import InputShare


Expand Down Expand Up @@ -338,3 +339,34 @@ def test_create_and_find_procedure(
)
case_procedures = thehive.case.find_procedures(case_id=test_case["_id"])
assert [created_procedure] == case_procedures

def test_create_and_find_page(self, thehive: TheHiveApi, test_case: OutputCase):
created_page = thehive.case.create_page(
case_id=test_case["_id"],
page={"title": "my case page", "category": "testing", "content": "..."},
)

case_pages = thehive.case.find_pages(case_id=test_case["_id"])
assert [created_page] == case_pages

def test_update_and_delete_page(
self, thehive: TheHiveApi, test_case: OutputCase, test_case_page: OutputCasePage
):
update_page: InputUpdateCasePage = {"title": "my updated case page"}
thehive.case.update_page(
case_id=test_case["_id"],
page_id=test_case_page["_id"],
page=update_page,
)

updated_case_page = thehive.case.find_pages(
case_id=test_case["_id"], filters=Eq("_id", test_case_page["_id"])
)[0]

for key, value in update_page.items():
assert updated_case_page.get(key) == value

thehive.case.delete_page(
case_id=test_case["_id"], page_id=test_case_page["_id"]
)
assert len(thehive.case.find_pages(case_id=test_case["_id"])) == 0
38 changes: 38 additions & 0 deletions thehive4py/endpoints/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)
from thehive4py.types.comment import OutputComment
from thehive4py.types.observable import InputObservable, OutputObservable
from thehive4py.types.page import InputCasePage, InputUpdateCasePage, OutputCasePage
from thehive4py.types.procedure import InputProcedure, OutputProcedure
from thehive4py.types.share import InputShare, OutputShare
from thehive4py.types.task import InputTask, OutputTask
Expand Down Expand Up @@ -266,6 +267,43 @@ def find_procedures(
json={"query": query},
)

def create_page(self, case_id: str, page: InputCasePage) -> OutputCasePage:
return self._session.make_request(
"POST", path=f"/api/v1/case/{case_id}/page", json=page
)

def delete_page(self, case_id: str, page_id: str) -> None:
return self._session.make_request(
"DELETE", path=f"/api/v1/case/{case_id}/page/{page_id}"
)

def update_page(
self, case_id: str, page_id: str, page: InputUpdateCasePage
) -> None:
return self._session.make_request(
"PATCH", path=f"/api/v1/case/{case_id}/page/{page_id}", json=page
)

def find_pages(
self,
case_id: str,
filters: Optional[FilterExpr] = None,
sortby: Optional[SortExpr] = None,
paginate: Optional[Paginate] = None,
) -> List[OutputProcedure]:
query: QueryExpr = [
{"_name": "getCase", "idOrName": case_id},
{"_name": "pages"},
*self._build_subquery(filters=filters, sortby=sortby, paginate=paginate),
]

return self._session.make_request(
"POST",
path="/api/v1/query",
params={"name": "case-pages"},
json={"query": query},
)

def find_attachments(
self,
case_id: CaseId,
Expand Down
2 changes: 2 additions & 0 deletions thehive4py/types/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from thehive4py.types.custom_field import InputCustomFieldValue, OutputCustomFieldValue
from thehive4py.types.observable import InputObservable
from thehive4py.types.procedure import InputProcedure
from thehive4py.types.share import InputShare
from thehive4py.types.task import InputTask

Expand All @@ -27,6 +28,7 @@ class InputAlert(InputAlertRequired, total=False):
status: str
caseTemplate: str
observables: List[InputObservable]
procedures: List[InputProcedure]


class OutputAlertRequired(TypedDict):
Expand Down
36 changes: 36 additions & 0 deletions thehive4py/types/page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import TypedDict


class InputCasePageRequired(TypedDict):
title: str
content: str
category: str


class InputCasePage(InputCasePageRequired, total=False):
order: int


class OutputCasePageRequired(TypedDict):
_id: str
id: str
createdBy: str
createdAt: int
title: str
content: str
_type: str
slug: str
order: int
category: str


class OutputCasePage(OutputCasePageRequired, total=False):
updatedBy: str
updatedAt: int


class InputUpdateCasePage(TypedDict, total=False):
title: str
content: str
category: str
order: int
2 changes: 1 addition & 1 deletion thehive4py/types/procedure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

class InputProcedureRequired(TypedDict):
occurDate: int
tactic: str
patternId: str


class InputProcedure(InputProcedureRequired, total=False):
tactic: str
description: str


Expand Down