Skip to content

Commit

Permalink
Merge pull request #7 from loadimpact/feature/apiv3-test-support
Browse files Browse the repository at this point in the history
v3 API SDK improvements
  • Loading branch information
robingustafsson committed Oct 1, 2017
2 parents dd3e141 + d09ff6b commit 700beb7
Show file tree
Hide file tree
Showing 6 changed files with 535 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ python:
- "3.5"
install:
- python setup.py -q install
- pip install -r requirements.txt --use-mirrors
- pip install -r requirements.txt
- pip install coverage==3.7.1
- pip install coveralls
script:
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ It has one dependency, the [requests](http://www.python-requests.org/) library.
Install using `pip`:

```sh
pip install loadimpact
pip install loadimpact-v3
```
[![PyPI](https://img.shields.io/pypi/v/loadimpact.svg)]() [![PyPI](https://img.shields.io/pypi/dm/loadimpact.svg)]()

Expand All @@ -27,8 +27,8 @@ your [loadimpact.com account page](https://loadimpact.com/account/).
You either enter your API token as an argument when creating the client:

```python
import loadimpact
client = loadimpact.ApiTokenClient(api_token='YOUR_API_TOKEN_GOES_HERE')
import loadimpact3
client = loadimpact3.ApiTokenClient(api_token='YOUR_API_TOKEN_GOES_HERE')
```

or using environment variables:
Expand All @@ -37,8 +37,8 @@ or using environment variables:
export LOADIMPACT_API_TOKEN=YOUR_API_TOKEN_GOES_HERE
```
```python
import loadimpact
client = loadimpact.ApiTokenClient()
import loadimpact3
client = loadimpact3.ApiTokenClient()
```

## Using an API client
Expand Down Expand Up @@ -78,6 +78,7 @@ for result in validation_results:
print("[{0}] {1}".format(result.timestamp, result.message))

print("Validation completed with status: {0}".format(validation.status_text))
```

### Uploading a data store (CSV file with parameterization data)
For more information regarding parameterized data have a look at [this
Expand Down
23 changes: 21 additions & 2 deletions loadimpact3/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
MissingApiTokenError, NotFoundError, RateLimitError, ServerError,
TimeoutError, UnauthorizedError)
from .resources import (
DataStore, UserScenario, UserScenarioValidation,
UserScenarioValidationResult, Organization, OrganizationProject)
DataStore, Test, TestRun, TestRunResultsIds, UserScenario,
UserScenarioValidation, UserScenarioValidationResult,
Organization, OrganizationProject, TestRunResults)

try:
from urlparse import urljoin
Expand Down Expand Up @@ -123,6 +124,24 @@ def list_organizations(self):
def list_organization_projects(self, org_id):
return OrganizationProject.list(self, org_id)

def list_tests(self, project_id):
return Test.list(self, project_id=project_id)

def get_test(self, resource_id):
return Test.get(self, resource_id)

def get_test_run(self, resource_id):
return TestRun.get(self, resource_id)

def create_test_run(self, data):
return TestRun.create(self, data)

def list_test_run_result_ids(self, resource_id, data):
return TestRunResultsIds.list(self, resource_id, data)

def list_test_run_results(self, resource_id, data):
return TestRunResults.list(self, resource_id, data)

@requests_exceptions_handling
def delete(self, path, headers=None, params=None):
"""Make a DELETE request to the API.
Expand Down
17 changes: 17 additions & 0 deletions loadimpact3/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ def default(cls):
return datetime.utcnow().replace(tzinfo=UTC())


class TimeStampField(DateTimeField):
"""
Specific Field that is created by a JSON Unix epoch timestamp format.
"""
field_type = datetime

@classmethod
def coerce(cls, value):
if not isinstance(value, cls.field_type):
try:
return datetime.fromtimestamp(value/10**6).replace(tzinfo=UTC())

except ValueError as e:
raise CoercionError(e)
return value


class DictField(Field):
field_type = dict

Expand Down
Loading

0 comments on commit 700beb7

Please sign in to comment.