Skip to content

Commit

Permalink
Fix version & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VladaPetrovic committed Sep 25, 2017
1 parent e33300e commit 15b8041
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 58 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,3 @@ docs/_build/

# PyBuilder
target/

# Version file
databox/_version.py
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Following guidelines of http://keepachangelog.com/

## [Unreleased]

## [2.1.2] - Sep 25, 2017
- Release with fixed version

## [2.1.1] - July 28, 2017
- Use setuptools_scm to extract version from Git

Expand Down Expand Up @@ -40,7 +43,8 @@ Following guidelines of http://keepachangelog.com/
## [0.1] - May 20, 2015
- Initial release

[Unreleased]: https://github.com/databox/databox-go/compare/2.1.1...master
[Unreleased]: https://github.com/databox/databox-go/compare/2.1.2...master
[2.1.2]: https://github.com/databox/databox-python/compare/2.1.1...2.1.2
[2.1.1]: https://github.com/databox/databox-python/compare/2.1.0...2.1.1
[2.1.0]: https://github.com/databox/databox-python/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/databox/databox-python/compare/0.1.6...2.0.0
Expand Down
40 changes: 9 additions & 31 deletions databox test/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from pprint import pprint as pp
from os import getenv

RESPONSE_ID = '2837643'

def mock_push_json(data=None, path='/'):
return {'id': '2837643'}
return {'id': RESPONSE_ID}


class TestPush(unittest.TestCase):
Expand All @@ -16,19 +17,16 @@ def setUp(self):
self.original_push_json = self.client._push_json
self.client._push_json = mock_push_json


def test_push(self):
assert self.client.push("templj", 10.0) is True
assert self.client.push("templj", 12.0, date="2015-01-01 09:00:00") is True
assert self.client.push("templj", 10.0) is RESPONSE_ID
assert self.client.push("templj", 12.0, date="2015-01-01 09:00:00") is RESPONSE_ID

def test_push_with_attributes(self):
self.client._push_json = lambda data=None, path='/': data

push = self.client.push("meta", 100, attributes={
def test_push_with_attributes(self):
assert self.client.push("meta", 100, attributes={
'n': 100
})

assert self.client.last_push_content['data'][0]['$meta'] == 100
assert self.client.last_push_content['data'][0]['n'] == 100
}) is RESPONSE_ID


def test_push_validation(self):
Expand All @@ -43,7 +41,7 @@ def test_insert_all(self):
{'key': 'templj', 'value': 83.3},
{'key': 'templj', 'value': 83.3, 'date': "2015-01-01 09:00:00"},
{'key': 'templj', 'value': 12.3},
]) is True
]) is RESPONSE_ID

self.assertRaises(
Client.KPIValidationException,
Expand All @@ -67,23 +65,3 @@ def test_last_push(self):
def test_last_push_with_number(self):
self.client._get_json = lambda data=None, path='/': path
assert self.client.last_push(3) == '/lastpushes?limit=3'


def test_short(self):
Client._push_json = mock_push_json

assert push("templj", 22, token=self.databox_push_token) is True

assert insert_all([
{
'key': 'templj',
'value': 83.3
},
], token=self.databox_push_token) is True

Client._get_json = lambda number=None, path='/': {
'err': [],
'no_err': 0
}

assert last_push(token=self.databox_push_token)['err'] == []
17 changes: 7 additions & 10 deletions databox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import requests
import pkg_resources
from requests.auth import HTTPBasicAuth
from os import getenv
from json import dumps as json_dumps

_name = "databox"
_version = pkg_resources.get_distribution(_name).version

from .__version__ import __version__

class Client(object):
push_token = None
Expand Down Expand Up @@ -61,8 +58,8 @@ def _push_json(self, data=None, path="/"):
auth=HTTPBasicAuth(self.push_token, ''),
headers={
'Content-Type': 'application/json',
'User-Agent': 'databox-python/' + _version,
'Accept': 'application/vnd.databox.v' + _version.split('.')[0] + '+json'
'User-Agent': 'databox-python/' + __version__,
'Accept': 'application/vnd.databox.v' + __version__.split('.')[0] + '+json'
},
data=data
)
Expand All @@ -75,8 +72,8 @@ def _get_json(self, path):
auth=HTTPBasicAuth(self.push_token, ''),
headers={
'Content-Type': 'application/json',
'User-Agent': 'databox-python/' + _version,
'Accept': 'application/vnd.databox.v' + _version.split('.')[0] + '+json'
'User-Agent': 'databox-python/' + __version__,
'Accept': 'application/vnd.databox.v' + __version__.split('.')[0] + '+json'
}
)

Expand All @@ -88,8 +85,8 @@ def _delete_json(self, path):
auth=HTTPBasicAuth(self.push_token, ''),
headers={
'Content-Type': 'application/json',
'User-Agent': 'databox-python/' + _version,
'Accept': 'application/vnd.databox.v' + _version.split('.')[0] + '+json'
'User-Agent': 'databox-python/' + __version__,
'Accept': 'application/vnd.databox.v' + __version__.split('.')[0] + '+json'
}
)

Expand Down
7 changes: 7 additions & 0 deletions databox/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__title__ = 'databox'
__version__ = '2.1.2'
__description__ = 'Python wrapper for Databox - Mobile Executive Dashboard.'
__url__ = 'https://github.com/databox/databox-python'
__author__ = 'Databox'
__author_email__ = '[email protected]'
__license__ = 'MIT'
29 changes: 16 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# -*- coding: utf-8 -*-
import os

from setuptools import setup, find_packages
import pkg_resources
from codecs import open

here = os.path.abspath(os.path.dirname(__file__))

_name = "databox"
_version = pkg_resources.get_distribution(_name).version
about = {}
with open(os.path.join(here, 'databox', '__version__.py'), 'r', 'utf-8') as f:
exec(f.read(), about)

setup(
use_scm_version={'write_to': 'databox/_version.py'},
setup_requires=['setuptools_scm>1.5.4'],
name=_name,
version=_version,
author="Databox",
author_email="[email protected]",
description="Python wrapper for Databox - Mobile Executive Dashboard.",
url="https://github.com/databox/databox-python",
download_url="https://github.com/databox/databox-python/tarball/"+_version,
name=about['__title__'],
version=about['__version__'],
author=about['__author__'],
author_email=about['__author_email__'],
description=about['__description__'],
url=about['__url__'],
download_url=about['__url__'] + "/tarball/" + about['__version__'],
keywords=['databox', 'sdk', 'bi'],
license='MIT',
license=about['__license__'],
packages=find_packages(exclude=('databox test',)),
install_requires=[
'requests >= 2.13'
Expand Down

0 comments on commit 15b8041

Please sign in to comment.