Skip to content

Commit

Permalink
Merge pull request #337 from pcattori/tc-sessions
Browse files Browse the repository at this point in the history
Tc sessions
  • Loading branch information
pcattori committed Feb 13, 2020
2 parents fc6b163 + 9e9397e commit 9687173
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 22 deletions.
3 changes: 2 additions & 1 deletion tamr_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import tamr_client.response as response
from tamr_client.auth import UsernamePasswordAuth
from tamr_client.session import session
from tamr_client.session import Session
import tamr_client.session as session

# datasets
from tamr_client.datasets.dataset import Dataset
Expand Down
16 changes: 7 additions & 9 deletions tamr_client/attributes/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from dataclasses import dataclass, field, replace
from typing import Optional

from requests import Session

import tamr_client as tc
from tamr_client.json_dict import JsonDict
from tamr_client.types import JsonDict

_RESERVED_NAMES = frozenset(
[
Expand Down Expand Up @@ -67,7 +65,7 @@ class Attribute:
description: Optional[str] = None


def from_resource_id(session: Session, dataset: tc.Dataset, id: str) -> Attribute:
def from_resource_id(session: tc.Session, dataset: tc.Dataset, id: str) -> Attribute:
"""Get attribute by resource ID
Fetches attribute from Tamr server
Expand All @@ -85,7 +83,7 @@ def from_resource_id(session: Session, dataset: tc.Dataset, id: str) -> Attribut
return _from_url(session, url)


def _from_url(session: Session, url: tc.URL) -> Attribute:
def _from_url(session: tc.Session, url: tc.URL) -> Attribute:
"""Get attribute by URL
Fetches attribute from Tamr server
Expand Down Expand Up @@ -143,7 +141,7 @@ def to_json(attr: Attribute) -> JsonDict:


def create(
session: Session,
session: tc.Session,
dataset: tc.dataset.Dataset,
*,
name: str,
Expand Down Expand Up @@ -186,7 +184,7 @@ def create(


def _create(
session: Session,
session: tc.Session,
dataset: tc.dataset.Dataset,
*,
name: str,
Expand Down Expand Up @@ -217,7 +215,7 @@ def _create(


def update(
session: Session, attribute: Attribute, *, description: Optional[str] = None
session: tc.Session, attribute: Attribute, *, description: Optional[str] = None
) -> Attribute:
"""Update an existing attribute
Expand All @@ -243,7 +241,7 @@ def update(
return _from_json(attribute.url, data)


def delete(session: Session, attribute: Attribute):
def delete(session: tc.Session, attribute: Attribute):
"""Deletes an existing attribute
Sends a deletion request to the Tamr server
Expand Down
2 changes: 1 addition & 1 deletion tamr_client/attributes/attribute_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import ClassVar, Tuple, Union

import tamr_client as tc
from tamr_client.json_dict import JsonDict
from tamr_client.types import JsonDict

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion tamr_client/attributes/subattribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Optional

import tamr_client as tc
from tamr_client.json_dict import JsonDict
from tamr_client.types import JsonDict


@dataclass(frozen=True)
Expand Down
4 changes: 1 addition & 3 deletions tamr_client/datasets/dataset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from dataclasses import dataclass, replace
from typing import Tuple

from requests import Session

import tamr_client as tc


Expand All @@ -12,7 +10,7 @@ class Dataset:
key_attribute_names: Tuple[str, ...]


def attributes(session: Session, dataset: Dataset) -> Tuple["tc.Attribute", ...]:
def attributes(session: tc.Session, dataset: Dataset) -> Tuple["tc.Attribute", ...]:
"""Get attributes for this dataset
Args:
Expand Down
4 changes: 3 additions & 1 deletion tamr_client/session.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import requests

Session = requests.Session

def session(auth: requests.auth.HTTPBasicAuth, **kwargs) -> requests.Session:

def from_auth(auth: requests.auth.HTTPBasicAuth, **kwargs) -> Session:
"""Create a new authenticated session
Args:
Expand Down
2 changes: 1 addition & 1 deletion tamr_client/json_dict.py → tamr_client/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# taken from https://github.com/python/typing/issues/182
from typing import Any, Dict

# taken from https://github.com/python/typing/issues/182
JsonDict = Dict[str, Any]
6 changes: 2 additions & 4 deletions tests/attributes/test_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def test_create():

@responses.activate
def test_update():
auth = tc.UsernamePasswordAuth("admin", "dt")
s = tc.session(auth)
s = utils.session()

url = tc.URL(path="datasets/1/attributes/RowNum")
attr_json = utils.load_json("attributes.json")[0]
Expand All @@ -81,8 +80,7 @@ def test_update():

@responses.activate
def test_delete():
auth = tc.UsernamePasswordAuth("admin", "dt")
s = tc.session(auth)
s = utils.session()

url = tc.URL(path="datasets/1/attributes/RowNum")
attr_json = utils.load_json("attributes.json")[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def load_json(path: Union[str, Path]):

def session():
auth = tc.UsernamePasswordAuth("admin", "dt")
s = tc.session(auth)
s = tc.session.from_auth(auth)
return s


Expand Down

0 comments on commit 9687173

Please sign in to comment.