-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds base class definition for resources (#83)
- Loading branch information
Showing
4 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Generic, List, Optional, TypeVar | ||
|
||
|
||
T = TypeVar("T") | ||
|
||
|
||
class Resources(ABC, Generic[T]): | ||
@abstractmethod | ||
def create(self, *args, **kwargs) -> T: | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def delete(self, *args, **kwargs) -> None: | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def find(self, *args, **kwargs) -> List[T]: | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def find_one(self, *args, **kwargs) -> Optional[T]: | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def get(self, *args, **kwargs) -> T: | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def update(self, *args, **kwargs) -> T: | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pytest | ||
|
||
from typing import Any, List, Optional | ||
|
||
from posit.connect.resources import Resources | ||
|
||
|
||
class TestResources(Resources[Any]): | ||
def create(self) -> Any: | ||
return super().create() # type: ignore [safe-super] | ||
|
||
def delete(self) -> None: | ||
return super().delete() # type: ignore [safe-super] | ||
|
||
def find(self) -> List[Any]: | ||
return super().find() # type: ignore [safe-super] | ||
|
||
def find_one(self) -> Optional[Any]: | ||
return super().find_one() # type: ignore [safe-super] | ||
|
||
def get(self) -> Any: | ||
return super().get() # type: ignore [safe-super] | ||
|
||
def update(self) -> Any: | ||
return super().update() # type: ignore [safe-super] | ||
|
||
def test_create(self): | ||
with pytest.raises(NotImplementedError): | ||
self.create() | ||
|
||
def test_delete(self): | ||
with pytest.raises(NotImplementedError): | ||
self.delete() | ||
|
||
def test_find(self): | ||
with pytest.raises(NotImplementedError): | ||
self.find() | ||
|
||
def test_find_one(self): | ||
with pytest.raises(NotImplementedError): | ||
self.find_one() | ||
|
||
def test_get(self): | ||
with pytest.raises(NotImplementedError): | ||
self.get() | ||
|
||
def test_update(self): | ||
with pytest.raises(NotImplementedError): | ||
self.update() |