diff --git a/.gitignore b/.gitignore index a30e297..37d1de4 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ __pycache__/ build/ .tox/ +.coverage diff --git a/.travis.yml b/.travis.yml index a788da2..b91974d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,7 @@ matrix: - python: "3.7" env: TOXENV=py37 - # Linters - - - python: "3.7" + - python: "3.6" env: TOXENV=linting notifications: diff --git a/README.md b/README.md index 34cb0a1..87a2189 100755 --- a/README.md +++ b/README.md @@ -1,41 +1,26 @@ # ElectronBonder A client library for working with the Project Electron APIs. -## Credits -This code is basically stolen from [ArchivesSnake](https://github.com/archivesspace-labs/ArchivesSnake/). - -## Requirements -ElectronBonder has the following requirements. +## Getting started -- Python 3.4 or higher -- ability to install packages via pip ([Pipenv](https://docs.pipenv.org/) is recommended for development) - -## Installation -The easiest way to install ElectronBonder is via pip: +Make sure this library is installed: pip3 install ElectronBonder -You'll need an internet connection to fetch ElectronBonder's dependencies. -## Usage -To start, you must create a client with a baseurl: +Then create a client with a baseurl, a username and a password: ``` python from electronbonder.client import ElectronBond -client = ElectronBond(baseurl="http://my.aspace.backend.url.edu:4567") +client = ElectronBond( + baseurl="http://my.aspace.backend.url.edu:4567", + username="admin", + password="TopSecr3t") ``` - -## Configuration - -As per the example above, the client object should be configured by passing it arguments during creation. - -Allowed configuration values are: - -| **Setting** | **Description** | -|-------------|-------------------------------------------------------------------------------| -| baseurl | The location (including port if not on port 80) of the application's API root | +## Credits +This code is basically stolen from [ArchivesSnake](https://github.com/archivesspace-labs/ArchivesSnake/). ## License diff --git a/electronbonder/client.py b/electronbonder/client.py index ec535fa..5b520b2 100755 --- a/electronbonder/client.py +++ b/electronbonder/client.py @@ -73,15 +73,12 @@ def __init__(self, **config): self.session.headers.update({"Accept": "application/json", "User-Agent": "ElectronBond/0.1"}) - def authorize(self, username=None, password=None): + def authorize(self): """Authorizes the client against the configured microservice instance.""" - username = username or self.config["username"] - password = password or self.config["password"] - resp = self.session.post( "/".join([self.config["baseurl"].rstrip("/"), "get-token/"]), - data={"password": password, "username": username}) + data={"password": self.config["password"], "username": self.config["username"]}) if resp.status_code != 200: raise ElectronBondAuthError( diff --git a/tox.ini b/tox.ini index 8a2ce6c..5fbe51f 100644 --- a/tox.ini +++ b/tox.ini @@ -7,8 +7,11 @@ deps = pytest requests six + coverage skip_install = True -commands = pytest +commands = + coverage run -m --source=./electronbonder pytest -s + coverage report -m [testenv:linting] basepython = python3