diff --git a/.gitignore b/.gitignore index 865f577..56665d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.pyc .tox .coverage -withings.conf -withings.egg-info +nokia.conf +nokia.egg-info diff --git a/README.md b/README.md index e000fb7..8baebe9 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,32 @@ -# Python library for the Withings API +# Python library for the Nokia Health API -[![Build Status](https://travis-ci.org/orcasgit/python-withings.svg?branch=master)](https://travis-ci.org/orcasgit/python-withings) [![Coverage Status](https://coveralls.io/repos/orcasgit/python-withings/badge.png?branch=master)](https://coveralls.io/r/orcasgit/python-withings?branch=master) [![Requirements Status](https://requires.io/github/orcasgit/python-withings/requirements.svg?branch=requires-io-master)](https://requires.io/github/orcasgit/python-withings/requirements/?branch=requires-io-master) +[![Build Status](https://travis-ci.org/orcasgit/python-nokia.svg?branch=master)](https://travis-ci.org/orcasgit/python-nokia) [![Coverage Status](https://coveralls.io/repos/orcasgit/python-nokia/badge.png?branch=master)](https://coveralls.io/r/orcasgit/python-nokia?branch=master) [![Requirements Status](https://requires.io/github/orcasgit/python-nokia/requirements.svg?branch=requires-io-master)](https://requires.io/github/orcasgit/python-nokia/requirements/?branch=requires-io-master) -Withings Body metrics Services API - +Nokia Health API + Uses Oauth 1.0 to authentify. You need to obtain a consumer key -and consumer secret from Withings by creating an application -here: - -This is a maintained fork of the `python-withings` library, the origin version -is [here](https://github.com/maximebf/python-withings). +and consumer secret from Nokia by creating an application +here: Installation: - pip install pywithings + pip install nokia Usage: ``` python -from withings import WithingsAuth, WithingsApi +from nokia import NokiaAuth, NokiaApi from settings import CONSUMER_KEY, CONSUMER_SECRET -auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET) +auth = NokiaAuth(CONSUMER_KEY, CONSUMER_SECRET) authorize_url = auth.get_authorize_url() -print "Go to %s allow the app and copy your oauth_verifier" % authorize_url +print("Go to %s allow the app and copy your oauth_verifier" % authorize_url) oauth_verifier = raw_input('Please enter your oauth_verifier: ') creds = auth.get_credentials(oauth_verifier) -client = WithingsApi(creds) +client = NokiaApi(creds) measures = client.get_measures(limit=1) -print "Your last measured weight: %skg" % measures[0].weight +print("Your last measured weight: %skg" % measures[0].weight) ``` diff --git a/bin/withings b/bin/nokia similarity index 70% rename from bin/withings rename to bin/nokia index 90ef721..93d3092 100755 --- a/bin/withings +++ b/bin/nokia @@ -1,9 +1,10 @@ #!/usr/bin/env python -from withings import * from optparse import OptionParser import sys import os +import nokia + try: import configparser except ImportError: # Python 2.x fallback @@ -28,21 +29,21 @@ command = args.pop(0) if not options.config is None and os.path.exists(options.config): config = configparser.ConfigParser(vars(options)) config.read(options.config) - options.consumer_key = config.get('withings', 'consumer_key') - options.consumer_secret = config.get('withings', 'consumer_secret') - options.access_token = config.get('withings', 'access_token') - options.access_token_secret = config.get('withings', 'access_token_secret') - options.user_id = config.get('withings', 'user_id') + options.consumer_key = config.get('nokia', 'consumer_key') + options.consumer_secret = config.get('nokia', 'consumer_secret') + options.access_token = config.get('nokia', 'access_token') + options.access_token_secret = config.get('nokia', 'access_token_secret') + options.user_id = config.get('nokia', 'user_id') if options.consumer_key is None or options.consumer_secret is None: print("You must provide a consumer key and consumer secret") - print("Create an Oauth application here: https://oauth.withings.com/partner/add") + print("Create an Oauth application here: https://developer.health.nokia.com/en/partner/add") sys.exit(1) if options.access_token is None or options.access_token_secret is None or options.user_id is None: print("Missing authentification information!") print("Starting authentification process...") - auth = WithingsAuth(options.consumer_key, options.consumer_secret) + auth = nokia.NokiaAuth(options.consumer_key, options.consumer_secret) authorize_url = auth.get_authorize_url() print("Go to %s allow the app and copy your oauth_verifier") % authorize_url oauth_verifier = raw_input('Please enter your oauth_verifier: ') @@ -52,23 +53,23 @@ if options.access_token is None or options.access_token_secret is None or option options.user_id = creds.user_id print("") else: - creds = WithingsCredentials(options.access_token, options.access_token_secret, - options.consumer_key, options.consumer_secret, - options.user_id) + creds = nokia.NokiaCredentials(options.access_token, options.access_token_secret, + options.consumer_key, options.consumer_secret, + options.user_id) -client = WithingsApi(creds) +client = nokia.NokiaApi(creds) if command == 'saveconfig': if options.config is None: print("Missing config filename") sys.exit(1) config = configparser.ConfigParser() - config.add_section('withings') - config.set('withings', 'consumer_key', options.consumer_key) - config.set('withings', 'consumer_secret', options.consumer_secret) - config.set('withings', 'access_token', options.access_token) - config.set('withings', 'access_token_secret', options.access_token_secret) - config.set('withings', 'user_id', options.user_id) + config.add_section('nokia') + config.set('nokia', 'consumer_key', options.consumer_key) + config.set('nokia', 'consumer_secret', options.consumer_secret) + config.set('nokia', 'access_token', options.access_token) + config.set('nokia', 'access_token_secret', options.access_token_secret) + config.set('nokia', 'user_id', options.user_id) with open(options.config, 'wb') as f: config.write(f) print("Config file saved to %s" % options.config) @@ -83,11 +84,11 @@ if command == 'userinfo': if command == 'last': m = client.get_measures(limit=1)[0] if len(args) == 1: - for n, t in WithingsMeasureGroup.MEASURE_TYPES: + for n, t in nokia.NokiaMeasureGroup.MEASURE_TYPES: if n == args[0]: print(m.get_measure(t)) else: - for n, t in WithingsMeasureGroup.MEASURE_TYPES: + for n, t in nokia.NokiaMeasureGroup.MEASURE_TYPES: print("%s: %s" % (n.replace('_', ' ').capitalize(), m.get_measure(t))) sys.exit(0) diff --git a/withings/__init__.py b/nokia/__init__.py similarity index 80% rename from withings/__init__.py rename to nokia/__init__.py index fe4418b..219a8be 100644 --- a/withings/__init__.py +++ b/nokia/__init__.py @@ -1,40 +1,40 @@ # -*- coding: utf-8 -*- # """ -Python library for the Withings API +Python library for the Nokia Health API ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Withings Body metrics Services API - +Nokia Health API + Uses Oauth 1.0 to authentify. You need to obtain a consumer key -and consumer secret from Withings by creating an application -here: +and consumer secret from Nokia by creating an application +here: Usage: -auth = WithingsAuth(CONSUMER_KEY, CONSUMER_SECRET) +auth = NokiaAuth(CONSUMER_KEY, CONSUMER_SECRET) authorize_url = auth.get_authorize_url() -print "Go to %s allow the app and copy your oauth_verifier" % authorize_url +print("Go to %s allow the app and copy your oauth_verifier" % authorize_url) oauth_verifier = raw_input('Please enter your oauth_verifier: ') creds = auth.get_credentials(oauth_verifier) -client = WithingsApi(creds) +client = NokiaApi(creds) measures = client.get_measures(limit=1) -print "Your last measured weight: %skg" % measures[0].weight +print("Your last measured weight: %skg" % measures[0].weight) """ from __future__ import unicode_literals -__title__ = 'pywithings' +__title__ = 'nokia' __version__ = '0.4.0' __author__ = 'Maxime Bouroumeau-Fuseau, and ORCAS' __license__ = 'MIT' __copyright__ = 'Copyright 2012-2017 Maxime Bouroumeau-Fuseau, and ORCAS' -__all__ = [str('WithingsCredentials'), str('WithingsAuth'), str('WithingsApi'), - str('WithingsMeasures'), str('WithingsMeasureGroup')] +__all__ = [str('NokiaCredentials'), str('NokiaAuth'), str('NokiaApi'), + str('NokiaMeasures'), str('NokiaMeasureGroup')] import arrow import datetime @@ -45,7 +45,7 @@ from requests_oauthlib import OAuth1, OAuth1Session -class WithingsCredentials(object): +class NokiaCredentials(object): def __init__(self, access_token=None, access_token_secret=None, consumer_key=None, consumer_secret=None, user_id=None): self.access_token = access_token @@ -55,8 +55,8 @@ def __init__(self, access_token=None, access_token_secret=None, self.user_id = user_id -class WithingsAuth(object): - URL = 'https://oauth.withings.com/account' +class NokiaAuth(object): + URL = 'https://developer.health.nokia.com/account' def __init__(self, consumer_key, consumer_secret): self.consumer_key = consumer_key @@ -82,7 +82,7 @@ def get_credentials(self, oauth_verifier): resource_owner_secret=self.oauth_secret, verifier=oauth_verifier) tokens = oauth.fetch_access_token('%s/access_token' % self.URL) - return WithingsCredentials( + return NokiaCredentials( access_token=tokens['oauth_token'], access_token_secret=tokens['oauth_token_secret'], consumer_key=self.consumer_key, @@ -99,8 +99,8 @@ def is_date_class(val): return isinstance(val, (datetime.date, datetime.datetime, arrow.Arrow, )) -class WithingsApi(object): - URL = 'http://wbsapi.withings.net' +class NokiaApi(object): + URL = 'https://api.health.nokia.com' def __init__(self, credentials): self.credentials = credentials @@ -133,15 +133,15 @@ def get_user(self): def get_activities(self, **kwargs): r = self.request('measure', 'getactivity', params=kwargs, version='v2') activities = r['activities'] if 'activities' in r else [r] - return [WithingsActivity(act) for act in activities] + return [NokiaActivity(act) for act in activities] def get_measures(self, **kwargs): r = self.request('measure', 'getmeas', kwargs) - return WithingsMeasures(r) + return NokiaMeasures(r) def get_sleep(self, **kwargs): r = self.request('sleep', 'get', params=kwargs, version='v2') - return WithingsSleep(r) + return NokiaSleep(r) def subscribe(self, callback_url, comment, **kwargs): params = {'callbackurl': callback_url, 'comment': comment} @@ -166,7 +166,7 @@ def list_subscriptions(self, appli=1): return r['profiles'] -class WithingsObject(object): +class NokiaObject(object): def __init__(self, data): self.set_attributes(data) @@ -179,18 +179,18 @@ def set_attributes(self, data): setattr(self, key, val) -class WithingsActivity(WithingsObject): +class NokiaActivity(NokiaObject): pass -class WithingsMeasures(list, WithingsObject): +class NokiaMeasures(list, NokiaObject): def __init__(self, data): - super(WithingsMeasures, self).__init__( - [WithingsMeasureGroup(g) for g in data['measuregrps']]) + super(NokiaMeasures, self).__init__( + [NokiaMeasureGroup(g) for g in data['measuregrps']]) self.set_attributes(data) -class WithingsMeasureGroup(WithingsObject): +class NokiaMeasureGroup(NokiaObject): MEASURE_TYPES = ( ('weight', 1), ('height', 4), @@ -203,7 +203,7 @@ class WithingsMeasureGroup(WithingsObject): ) def __init__(self, data): - super(WithingsMeasureGroup, self).__init__(data) + super(NokiaMeasureGroup, self).__init__(data) for n, t in self.MEASURE_TYPES: self.__setattr__(n, self.get_measure(t)) @@ -223,13 +223,13 @@ def get_measure(self, measure_type): return None -class WithingsSleepSeries(WithingsObject): +class NokiaSleepSeries(NokiaObject): def __init__(self, data): - super(WithingsSleepSeries, self).__init__(data) + super(NokiaSleepSeries, self).__init__(data) self.timedelta = self.enddate - self.startdate -class WithingsSleep(WithingsObject): +class NokiaSleep(NokiaObject): def __init__(self, data): - super(WithingsSleep, self).__init__(data) - self.series = [WithingsSleepSeries(series) for series in self.series] + super(NokiaSleep, self).__init__(data) + self.series = [NokiaSleepSeries(series) for series in self.series] diff --git a/setup.py b/setup.py index 941329c..c6d61e1 100644 --- a/setup.py +++ b/setup.py @@ -4,18 +4,18 @@ required = [line for line in open('requirements/base.txt').read().split("\n")] setup( - name='pywithings', + name='nokia', version='0.4.0', - description="Library for the Withings API", + description="Library for the Nokia Health API", author='ORCAS', author_email='developer@orcasinc.com', - url="https://github.com/orcasgit/python-withings", + url="https://github.com/orcasgit/python-nokia", license = "MIT License", - packages = ['withings'], + packages = ['nokia'], install_requires = required, test_suite='tests.all_tests', - scripts=['bin/withings'], - keywords="withings", + scripts=['bin/nokia'], + keywords="withings nokia", zip_safe = True, classifiers=[ "Development Status :: 3 - Alpha", diff --git a/tests/__init__.py b/tests/__init__.py index 00241b7..9a23d19 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,25 +1,25 @@ import unittest -from .test_withings_activity import TestWithingsActivity -from .test_withings_api import TestWithingsApi -from .test_withings_auth import TestWithingsAuth -from .test_withings_credentials import TestWithingsCredentials -from .test_withings_measure_group import TestWithingsMeasureGroup -from .test_withings_measures import TestWithingsMeasures -from .test_withings_object import TestWithingsObject -from .test_withings_sleep import TestWithingsSleep -from .test_withings_sleep_series import TestWithingsSleepSeries +from .test_nokia_activity import TestNokiaActivity +from .test_nokia_api import TestNokiaApi +from .test_nokia_auth import TestNokiaAuth +from .test_nokia_credentials import TestNokiaCredentials +from .test_nokia_measure_group import TestNokiaMeasureGroup +from .test_nokia_measures import TestNokiaMeasures +from .test_nokia_object import TestNokiaObject +from .test_nokia_sleep import TestNokiaSleep +from .test_nokia_sleep_series import TestNokiaSleepSeries def all_tests(): suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestWithingsActivity)) - suite.addTest(unittest.makeSuite(TestWithingsApi)) - suite.addTest(unittest.makeSuite(TestWithingsAuth)) - suite.addTest(unittest.makeSuite(TestWithingsCredentials)) - suite.addTest(unittest.makeSuite(TestWithingsMeasureGroup)) - suite.addTest(unittest.makeSuite(TestWithingsMeasures)) - suite.addTest(unittest.makeSuite(TestWithingsObject)) - suite.addTest(unittest.makeSuite(TestWithingsSleep)) - suite.addTest(unittest.makeSuite(TestWithingsSleepSeries)) + suite.addTest(unittest.makeSuite(TestNokiaActivity)) + suite.addTest(unittest.makeSuite(TestNokiaApi)) + suite.addTest(unittest.makeSuite(TestNokiaAuth)) + suite.addTest(unittest.makeSuite(TestNokiaCredentials)) + suite.addTest(unittest.makeSuite(TestNokiaMeasureGroup)) + suite.addTest(unittest.makeSuite(TestNokiaMeasures)) + suite.addTest(unittest.makeSuite(TestNokiaObject)) + suite.addTest(unittest.makeSuite(TestNokiaSleep)) + suite.addTest(unittest.makeSuite(TestNokiaSleepSeries)) return suite diff --git a/tests/test_withings_activity.py b/tests/test_nokia_activity.py similarity index 88% rename from tests/test_withings_activity.py rename to tests/test_nokia_activity.py index 50e9ff5..5256860 100644 --- a/tests/test_withings_activity.py +++ b/tests/test_nokia_activity.py @@ -2,10 +2,10 @@ import unittest from datetime import datetime -from withings import WithingsActivity +from nokia import NokiaActivity -class TestWithingsActivity(unittest.TestCase): +class TestNokiaActivity(unittest.TestCase): def test_attributes(self): data = { "date": "2013-04-10", @@ -18,7 +18,7 @@ def test_attributes(self): "intense": 540, "timezone": "Europe/Berlin" } - act = WithingsActivity(data) + act = NokiaActivity(data) self.assertEqual(act.date.date().isoformat(), data['date']) self.assertEqual(act.steps, data['steps']) self.assertEqual(act.distance, data['distance']) diff --git a/tests/test_withings_api.py b/tests/test_nokia_api.py similarity index 80% rename from tests/test_withings_api.py rename to tests/test_nokia_api.py index e30a033..7d9cbd9 100644 --- a/tests/test_withings_api.py +++ b/tests/test_nokia_api.py @@ -4,14 +4,14 @@ import unittest from requests import Session -from withings import ( - WithingsActivity, - WithingsApi, - WithingsCredentials, - WithingsMeasureGroup, - WithingsMeasures, - WithingsSleep, - WithingsSleepSeries +from nokia import ( + NokiaActivity, + NokiaApi, + NokiaCredentials, + NokiaMeasureGroup, + NokiaMeasures, + NokiaSleep, + NokiaSleepSeries ) try: @@ -25,39 +25,39 @@ from mock import MagicMock -class TestWithingsApi(unittest.TestCase): +class TestNokiaApi(unittest.TestCase): def setUp(self): self.mock_api = True if self.mock_api: - self.creds = WithingsCredentials() + self.creds = NokiaCredentials() else: config = configparser.ConfigParser() - config.read('withings.conf') - self.creds = WithingsCredentials( - consumer_key=config.get('withings', 'consumer_key'), - consumer_secret=config.get('withings', 'consumer_secret'), - access_token=config.get('withings', 'access_token'), - access_token_secret=config.get('withings', + config.read('nokia.conf') + self.creds = NokiaCredentials( + consumer_key=config.get('nokia', 'consumer_key'), + consumer_secret=config.get('nokia', 'consumer_secret'), + access_token=config.get('nokia', 'access_token'), + access_token_secret=config.get('nokia', 'access_token_secret'), - user_id=config.get('withings', 'user_id')) - self.api = WithingsApi(self.creds) + user_id=config.get('nokia', 'user_id')) + self.api = NokiaApi(self.creds) def test_attributes(self): - """ Make sure the WithingsApi objects have the right attributes """ - assert hasattr(WithingsApi, 'URL') - creds = WithingsCredentials(user_id='FAKEID') - api = WithingsApi(creds) + """ Make sure the NokiaApi objects have the right attributes """ + assert hasattr(NokiaApi, 'URL') + creds = NokiaCredentials(user_id='FAKEID') + api = NokiaApi(creds) assert hasattr(api, 'credentials') assert hasattr(api, 'oauth') assert hasattr(api, 'client') def test_attribute_defaults(self): """ - Make sure WithingsApi object attributes have the correct defaults + Make sure NokiaApi object attributes have the correct defaults """ - self.assertEqual(WithingsApi.URL, 'http://wbsapi.withings.net') - creds = WithingsCredentials(user_id='FAKEID') - api = WithingsApi(creds) + self.assertEqual(NokiaApi.URL, 'https://api.health.nokia.com') + creds = NokiaCredentials(user_id='FAKEID') + api = NokiaApi(creds) self.assertEqual(api.credentials, creds) self.assertEqual(api.client.auth, api.oauth) self.assertEqual(api.client.params, {'userid': creds.user_id}) @@ -70,7 +70,7 @@ def test_request(self): self.mock_request({}) resp = self.api.request('fake_service', 'fake_action') Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/fake_service', + 'GET', 'https://api.health.nokia.com/fake_service', params={'action': 'fake_action'}) self.assertEqual(resp, {}) @@ -83,7 +83,7 @@ def test_request_params(self): resp = self.api.request('user', 'getbyuserid', params={'p2': 'p2'}, method='POST') Session.request.assert_called_once_with( - 'POST', 'http://wbsapi.withings.net/user', + 'POST', 'https://api.health.nokia.com/user', params={'p2': 'p2', 'action': 'getbyuserid'}) self.assertEqual(resp, {}) @@ -103,7 +103,7 @@ def test_get_user(self): }) resp = self.api.get_user() Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/user', + 'GET', 'https://api.health.nokia.com/user', params={'action': 'getbyuserid'}) self.assertEqual(type(resp), dict) assert 'users' in resp @@ -115,7 +115,7 @@ def test_get_user(self): def test_get_sleep(self): """ Check that get_sleep fetches the appropriate URL, the response looks - correct, and the return value is a WithingsSleep object with the + correct, and the return value is a NokiaSleep object with the correct attributes """ body = { @@ -133,13 +133,13 @@ def test_get_sleep(self): self.mock_request(body) resp = self.api.get_sleep() Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/v2/sleep', + 'GET', 'https://api.health.nokia.com/v2/sleep', params={'action': 'get'}) - self.assertEqual(type(resp), WithingsSleep) + self.assertEqual(type(resp), NokiaSleep) self.assertEqual(resp.model, body['model']) self.assertEqual(type(resp.series), list) self.assertEqual(len(resp.series), 2) - self.assertEqual(type(resp.series[0]), WithingsSleepSeries) + self.assertEqual(type(resp.series[0]), NokiaSleepSeries) self.assertEqual(resp.series[0].startdate.timestamp, body['series'][0]['startdate']) self.assertEqual(resp.series[0].enddate.timestamp, @@ -149,7 +149,7 @@ def test_get_sleep(self): def test_get_activities(self): """ Check that get_activities fetches the appropriate URL, the response - looks correct, and the return value is a list of WithingsActivity + looks correct, and the return value is a list of NokiaActivity objects """ body = { @@ -166,11 +166,11 @@ def test_get_activities(self): self.mock_request(body) resp = self.api.get_activities() Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/v2/measure', + 'GET', 'https://api.health.nokia.com/v2/measure', params={'action': 'getactivity'}) self.assertEqual(type(resp), list) self.assertEqual(len(resp), 1) - self.assertEqual(type(resp[0]), WithingsActivity) + self.assertEqual(type(resp[0]), NokiaActivity) # No need to assert all attributes, that happens elsewhere self.assertEqual(resp[0].data, body) @@ -193,19 +193,19 @@ def test_get_activities(self): self.mock_request(new_body) resp = self.api.get_activities() Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/v2/measure', + 'GET', 'https://api.health.nokia.com/v2/measure', params={'action': 'getactivity'}) self.assertEqual(type(resp), list) self.assertEqual(len(resp), 2) - self.assertEqual(type(resp[0]), WithingsActivity) - self.assertEqual(type(resp[1]), WithingsActivity) + self.assertEqual(type(resp[0]), NokiaActivity) + self.assertEqual(type(resp[1]), NokiaActivity) self.assertEqual(resp[0].data, new_body['activities'][0]) self.assertEqual(resp[1].data, new_body['activities'][1]) def test_get_measures(self): """ Check that get_measures fetches the appriate URL, the response looks - correct, and the return value is a WithingsMeasures object + correct, and the return value is a NokiaMeasures object """ body = { 'updatetime': 1409596058, @@ -221,11 +221,11 @@ def test_get_measures(self): self.mock_request(body) resp = self.api.get_measures() Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/measure', + 'GET', 'https://api.health.nokia.com/measure', params={'action': 'getmeas'}) - self.assertEqual(type(resp), WithingsMeasures) + self.assertEqual(type(resp), NokiaMeasures) self.assertEqual(len(resp), 2) - self.assertEqual(type(resp[0]), WithingsMeasureGroup) + self.assertEqual(type(resp[0]), NokiaMeasureGroup) self.assertEqual(resp[0].weight, 86.0) self.assertEqual(resp[1].height, 1.85) @@ -234,7 +234,7 @@ def test_get_measures(self): self.mock_request(body) resp = self.api.get_measures(limit=1) Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/measure', + 'GET', 'https://api.health.nokia.com/measure', params={'action': 'getmeas', 'limit': 1}) self.assertEqual(len(resp), 1) self.assertEqual(resp[0].weight, 86.0) @@ -246,7 +246,7 @@ def test_get_measures_lastupdate_date(self): self.api.get_measures(lastupdate=datetime.date(2014, 9, 1)) Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/measure', + 'GET', 'https://api.health.nokia.com/measure', params={'action': 'getmeas', 'lastupdate': 1409529600}) def test_get_measures_lastupdate_datetime(self): @@ -256,7 +256,7 @@ def test_get_measures_lastupdate_datetime(self): self.api.get_measures(lastupdate=datetime.datetime(2014, 9, 1)) Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/measure', + 'GET', 'https://api.health.nokia.com/measure', params={'action': 'getmeas', 'lastupdate': 1409529600}) def test_get_measures_lastupdate_arrow(self): @@ -266,7 +266,7 @@ def test_get_measures_lastupdate_arrow(self): self.api.get_measures(lastupdate=arrow.get('2014-09-01')) Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/measure', + 'GET', 'https://api.health.nokia.com/measure', params={'action': 'getmeas', 'lastupdate': 1409529600}) def test_subscribe(self): @@ -278,7 +278,7 @@ def test_subscribe(self): self.mock_request(None) resp = self.api.subscribe('http://www.example.com/', 'fake_comment') Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/notify', + 'GET', 'https://api.health.nokia.com/notify', params={'action': 'subscribe', 'comment': 'fake_comment', 'callbackurl': 'http://www.example.com/'}) self.assertEqual(resp, None) @@ -288,7 +288,7 @@ def test_subscribe(self): resp = self.api.subscribe('http://www.example.com/', 'fake_comment', appli=1) Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/notify', + 'GET', 'https://api.health.nokia.com/notify', params={'action': 'subscribe', 'appli': 1, 'comment': 'fake_comment', 'callbackurl': 'http://www.example.com/'}) @@ -303,7 +303,7 @@ def test_unsubscribe(self): self.mock_request(None) resp = self.api.unsubscribe('http://www.example.com/') Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/notify', + 'GET', 'https://api.health.nokia.com/notify', params={'action': 'revoke', 'callbackurl': 'http://www.example.com/'}) self.assertEqual(resp, None) @@ -312,7 +312,7 @@ def test_unsubscribe(self): self.mock_request(None) resp = self.api.unsubscribe('http://www.example.com/', appli=1) Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/notify', + 'GET', 'https://api.health.nokia.com/notify', params={'action': 'revoke', 'appli': 1, 'callbackurl': 'http://www.example.com/'}) self.assertEqual(resp, None) @@ -322,7 +322,7 @@ def test_is_subscribed(self): Check that is_subscribed fetches the right URL and returns the expected results """ - url = 'http://wbsapi.withings.net/notify' + url = 'https://api.health.nokia.com/notify' params = { 'callbackurl': 'http://www.example.com/', 'action': 'get', @@ -349,7 +349,7 @@ def test_list_subscriptions(self): ]}) resp = self.api.list_subscriptions() Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/notify', + 'GET', 'https://api.health.nokia.com/notify', params={'action': 'list', 'appli': 1}) self.assertEqual(type(resp), list) self.assertEqual(len(resp), 1) @@ -360,7 +360,7 @@ def test_list_subscriptions(self): self.mock_request({'profiles': []}) resp = self.api.list_subscriptions() Session.request.assert_called_once_with( - 'GET', 'http://wbsapi.withings.net/notify', + 'GET', 'https://api.health.nokia.com/notify', params={'action': 'list', 'appli': 1}) self.assertEqual(type(resp), list) self.assertEqual(len(resp), 0) diff --git a/tests/test_withings_auth.py b/tests/test_nokia_auth.py similarity index 71% rename from tests/test_withings_auth.py rename to tests/test_nokia_auth.py index ed47f89..5811f5a 100644 --- a/tests/test_withings_auth.py +++ b/tests/test_nokia_auth.py @@ -1,6 +1,6 @@ import unittest -from withings import WithingsAuth, WithingsCredentials +from nokia import NokiaAuth, NokiaCredentials from requests_oauthlib import OAuth1Session try: @@ -9,7 +9,7 @@ from mock import MagicMock -class TestWithingsAuth(unittest.TestCase): +class TestNokiaAuth(unittest.TestCase): def setUp(self): self.consumer_key = 'fake_consumer_key' self.consumer_secret = 'fake_consumer_secret' @@ -26,25 +26,25 @@ def setUp(self): return_value=self.access_token) def test_attributes(self): - """ Make sure the WithingsAuth objects have the right attributes """ - assert hasattr(WithingsAuth, 'URL') - auth = WithingsAuth(self.consumer_key, self.consumer_secret) + """ Make sure the NokiaAuth objects have the right attributes """ + assert hasattr(NokiaAuth, 'URL') + auth = NokiaAuth(self.consumer_key, self.consumer_secret) assert hasattr(auth, 'consumer_key') self.assertEqual(auth.consumer_key, self.consumer_key) assert hasattr(auth, 'consumer_secret') self.assertEqual(auth.consumer_secret, self.consumer_secret) def test_attribute_defaults(self): - """ Make sure WithingsAuth attributes have the proper defaults """ - self.assertEqual(WithingsAuth.URL, - 'https://oauth.withings.com/account') - auth = WithingsAuth(self.consumer_key, self.consumer_secret) + """ Make sure NokiaAuth attributes have the proper defaults """ + self.assertEqual(NokiaAuth.URL, + 'https://developer.health.nokia.com/account') + auth = NokiaAuth(self.consumer_key, self.consumer_secret) self.assertEqual(auth.oauth_token, None) self.assertEqual(auth.oauth_secret, None) def test_get_authorize_url(self): """ Make sure the get_authorize_url function works as expected """ - auth = WithingsAuth(self.consumer_key, self.consumer_secret) + auth = NokiaAuth(self.consumer_key, self.consumer_secret) # Returns the OAuth1Session.authorization_url results self.assertEqual(auth.get_authorize_url(), 'URL') # oauth_token and oauth_secret have now been set to the values @@ -54,11 +54,11 @@ def test_get_authorize_url(self): def test_get_credentials(self): """ Make sure the get_credentials function works as expected """ - auth = WithingsAuth(self.consumer_key, self.consumer_secret) - # Returns an authorized WithingsCredentials object + auth = NokiaAuth(self.consumer_key, self.consumer_secret) + # Returns an authorized NokiaCredentials object creds = auth.get_credentials('FAKE_OAUTH_VERIFIER') - assert isinstance(creds, WithingsCredentials) - # Check that the attributes of the WithingsCredentials object are + assert isinstance(creds, NokiaCredentials) + # Check that the attributes of the NokiaCredentials object are # correct. self.assertEqual(creds.access_token, 'fake_oauth_token') self.assertEqual(creds.access_token_secret, 'fake_oauth_token_secret') diff --git a/tests/test_withings_credentials.py b/tests/test_nokia_credentials.py similarity index 64% rename from tests/test_withings_credentials.py rename to tests/test_nokia_credentials.py index e1ae312..364d841 100644 --- a/tests/test_withings_credentials.py +++ b/tests/test_nokia_credentials.py @@ -1,17 +1,17 @@ import unittest -from withings import WithingsAuth, WithingsCredentials +from nokia import NokiaAuth, NokiaCredentials -class TestWithingsCredentials(unittest.TestCase): +class TestNokiaCredentials(unittest.TestCase): def test_attributes(self): """ - Make sure the WithingsCredentials objects have the right attributes + Make sure the NokiaCredentials objects have the right attributes """ - creds = WithingsCredentials(access_token=1, access_token_secret=1, - consumer_key=1, consumer_secret=1, - user_id=1) + creds = NokiaCredentials(access_token=1, access_token_secret=1, + consumer_key=1, consumer_secret=1, + user_id=1) assert hasattr(creds, 'access_token') self.assertEqual(creds.access_token, 1) assert hasattr(creds, 'access_token_secret') @@ -25,9 +25,9 @@ def test_attributes(self): def test_attribute_defaults(self): """ - Make sure WithingsCredentials attributes have the proper defaults + Make sure NokiaCredentials attributes have the proper defaults """ - creds = WithingsCredentials() + creds = NokiaCredentials() self.assertEqual(creds.access_token, None) self.assertEqual(creds.access_token_secret, None) self.assertEqual(creds.consumer_key, None) diff --git a/tests/test_withings_measure_group.py b/tests/test_nokia_measure_group.py similarity index 78% rename from tests/test_withings_measure_group.py rename to tests/test_nokia_measure_group.py index 491ecfa..6cb2c64 100644 --- a/tests/test_withings_measure_group.py +++ b/tests/test_nokia_measure_group.py @@ -1,14 +1,14 @@ import time import unittest -from withings import WithingsMeasureGroup +from nokia import NokiaMeasureGroup -class TestWithingsMeasureGroup(unittest.TestCase): +class TestNokiaMeasureGroup(unittest.TestCase): def test_attributes(self): """ Check that attributes get set as expected when creating a - WithingsMeasureGroup object + NokiaMeasureGroup object """ data = { 'attrib': 2, @@ -19,14 +19,14 @@ def test_attributes(self): 'category': 1, 'grpid': 111111111 } - group = WithingsMeasureGroup(data) + group = NokiaMeasureGroup(data) self.assertEqual(group.data, data) self.assertEqual(group.grpid, data['grpid']) self.assertEqual(group.attrib, data['attrib']) self.assertEqual(group.category, data['category']) self.assertEqual(group.date.timestamp, 1409361740) self.assertEqual(group.measures, data['measures']) - for _type, type_id in WithingsMeasureGroup.MEASURE_TYPES: + for _type, type_id in NokiaMeasureGroup.MEASURE_TYPES: assert hasattr(group, _type) self.assertEqual(getattr(group, _type), 86.0 if _type == 'weight' else None) @@ -35,7 +35,7 @@ def test_types(self): """ Check that all the different measure types are working as expected """ - for _, type_id in WithingsMeasureGroup.MEASURE_TYPES: + for _, type_id in NokiaMeasureGroup.MEASURE_TYPES: data = { 'attrib': 2, 'measures': [ @@ -45,8 +45,8 @@ def test_types(self): 'category': 1, 'grpid': 111111111 } - group = WithingsMeasureGroup(data) - for _type, type_id2 in WithingsMeasureGroup.MEASURE_TYPES: + group = NokiaMeasureGroup(data) + for _type, type_id2 in NokiaMeasureGroup.MEASURE_TYPES: assert hasattr(group, _type) self.assertEqual(getattr(group, _type), 86.0 if type_id == type_id2 else None) @@ -67,8 +67,8 @@ def test_multigroup_types(self): 'category': 1, 'grpid': 111111111 } - group = WithingsMeasureGroup(data) - for _type, type_id in WithingsMeasureGroup.MEASURE_TYPES: + group = NokiaMeasureGroup(data) + for _type, type_id in NokiaMeasureGroup.MEASURE_TYPES: assert hasattr(group, _type) if _type == 'diastolic_blood_pressure': self.assertEqual(getattr(group, _type), 80.0) @@ -83,29 +83,29 @@ def test_is_ambiguous(self): """ Test the is_ambiguous method """ data = {'attrib': 0, 'measures': [], 'date': 1409361740, 'category': 1, 'grpid': 111111111} - self.assertEqual(WithingsMeasureGroup(data).is_ambiguous(), False) + self.assertEqual(NokiaMeasureGroup(data).is_ambiguous(), False) data['attrib'] = 1 - assert WithingsMeasureGroup(data).is_ambiguous() + assert NokiaMeasureGroup(data).is_ambiguous() data['attrib'] = 2 - self.assertEqual(WithingsMeasureGroup(data).is_ambiguous(), False) + self.assertEqual(NokiaMeasureGroup(data).is_ambiguous(), False) data['attrib'] = 4 - assert WithingsMeasureGroup(data).is_ambiguous() + assert NokiaMeasureGroup(data).is_ambiguous() def test_is_measure(self): """ Test the is_measure method """ data = {'attrib': 0, 'measures': [], 'date': 1409361740, 'category': 1, 'grpid': 111111111} - assert WithingsMeasureGroup(data).is_measure() + assert NokiaMeasureGroup(data).is_measure() data['category'] = 2 - self.assertEqual(WithingsMeasureGroup(data).is_measure(), False) + self.assertEqual(NokiaMeasureGroup(data).is_measure(), False) def test_is_target(self): """ Test the is_target method """ data = {'attrib': 0, 'measures': [], 'date': 1409361740, 'category': 1, 'grpid': 111111111} - self.assertEqual(WithingsMeasureGroup(data).is_target(), False) + self.assertEqual(NokiaMeasureGroup(data).is_target(), False) data['category'] = 2 - assert WithingsMeasureGroup(data).is_target() + assert NokiaMeasureGroup(data).is_target() def test_get_measure(self): """ @@ -122,7 +122,7 @@ def test_get_measure(self): 'category': 1, 'grpid': 111111111 } - group = WithingsMeasureGroup(data) + group = NokiaMeasureGroup(data) self.assertEqual(group.get_measure(9), 80.0) self.assertEqual(group.get_measure(10), 120.0) self.assertEqual(group.get_measure(11), 86.0) diff --git a/tests/test_withings_measures.py b/tests/test_nokia_measures.py similarity index 73% rename from tests/test_withings_measures.py rename to tests/test_nokia_measures.py index 2311567..eaa5e8c 100644 --- a/tests/test_withings_measures.py +++ b/tests/test_nokia_measures.py @@ -1,12 +1,12 @@ import unittest -from withings import WithingsMeasureGroup, WithingsMeasures +from nokia import NokiaMeasureGroup, NokiaMeasures -class TestWithingsMeasures(unittest.TestCase): - def test_withings_measures_init(self): +class TestNokiaMeasures(unittest.TestCase): + def test_nokia_measures_init(self): """ - Check that WithingsMeasures create groups correctly and that the + Check that NokiaMeasures create groups correctly and that the update time is parsed correctly """ data = { @@ -20,15 +20,15 @@ def test_withings_measures_init(self): 'grpid': 111111112} ] } - measures = WithingsMeasures(data) - self.assertEqual(type(measures), WithingsMeasures) + measures = NokiaMeasures(data) + self.assertEqual(type(measures), NokiaMeasures) self.assertEqual(measures.data, data) self.assertEqual(type(measures.measuregrps), list) self.assertEqual(len(measures.measuregrps), 2) self.assertEqual(measures.measuregrps[0], data['measuregrps'][0]) self.assertEqual(measures.measuregrps[1], data['measuregrps'][1]) self.assertEqual(len(measures), 2) - self.assertEqual(type(measures[0]), WithingsMeasureGroup) + self.assertEqual(type(measures[0]), NokiaMeasureGroup) self.assertEqual(measures[0].weight, 86.0) self.assertEqual(measures[1].height, 1.85) self.assertEqual(measures.updatetime.timestamp, 1409596058) diff --git a/tests/test_withings_object.py b/tests/test_nokia_object.py similarity index 79% rename from tests/test_withings_object.py rename to tests/test_nokia_object.py index ca733de..f4400d9 100644 --- a/tests/test_withings_object.py +++ b/tests/test_nokia_object.py @@ -2,10 +2,10 @@ import unittest from datetime import datetime -from withings import WithingsObject +from nokia import NokiaObject -class TestWithingsObject(unittest.TestCase): +class TestNokiaObject(unittest.TestCase): def test_attributes(self): data = { "date": "2013-04-10", @@ -13,7 +13,7 @@ def test_attributes(self): "integer": 55555, "float": 5.67 } - obj = WithingsObject(data) + obj = NokiaObject(data) self.assertEqual(obj.date.date().isoformat(), data['date']) self.assertEqual(obj.string, data['string']) self.assertEqual(obj.integer, data['integer']) @@ -21,10 +21,10 @@ def test_attributes(self): # Test time as epoch data = {"date": 1409596058} - obj = WithingsObject(data) + obj = NokiaObject(data) self.assertEqual(obj.date.timestamp, data['date']) # Test funky time data = {"date": "weird and wacky date format"} - obj = WithingsObject(data) + obj = NokiaObject(data) self.assertEqual(obj.date, data['date']) diff --git a/tests/test_withings_sleep.py b/tests/test_nokia_sleep.py similarity index 78% rename from tests/test_withings_sleep.py rename to tests/test_nokia_sleep.py index c991385..dd11e3f 100644 --- a/tests/test_withings_sleep.py +++ b/tests/test_nokia_sleep.py @@ -1,10 +1,10 @@ import time import unittest -from withings import WithingsSleep, WithingsSleepSeries +from nokia import NokiaSleep, NokiaSleepSeries -class TestWithingsSleep(unittest.TestCase): +class TestNokiaSleep(unittest.TestCase): def test_attributes(self): data = { "series": [{ @@ -18,11 +18,11 @@ def test_attributes(self): }], "model": 16 } - sleep = WithingsSleep(data) + sleep = NokiaSleep(data) self.assertEqual(sleep.model, data['model']) self.assertEqual(type(sleep.series), list) self.assertEqual(len(sleep.series), 2) - self.assertEqual(type(sleep.series[0]), WithingsSleepSeries) + self.assertEqual(type(sleep.series[0]), NokiaSleepSeries) self.assertEqual(sleep.series[0].startdate.timestamp, data['series'][0]['startdate']) self.assertEqual(sleep.series[0].enddate.timestamp, diff --git a/tests/test_withings_sleep_series.py b/tests/test_nokia_sleep_series.py similarity index 71% rename from tests/test_withings_sleep_series.py rename to tests/test_nokia_sleep_series.py index 3fd453b..c98b5bf 100644 --- a/tests/test_withings_sleep_series.py +++ b/tests/test_nokia_sleep_series.py @@ -2,18 +2,18 @@ import unittest from datetime import timedelta -from withings import WithingsSleepSeries +from nokia import NokiaSleepSeries -class TestWithingsSleepSeries(unittest.TestCase): +class TestNokiaSleepSeries(unittest.TestCase): def test_attributes(self): data = { "startdate": 1387243618, "state": 3, "enddate": 1387265218 } - series = WithingsSleepSeries(data) - self.assertEqual(type(series), WithingsSleepSeries) + series = NokiaSleepSeries(data) + self.assertEqual(type(series), NokiaSleepSeries) self.assertEqual(series.startdate.timestamp, data['startdate']) self.assertEqual(series.state, data['state']) self.assertEqual(series.enddate.timestamp, data['enddate']) diff --git a/tox.ini b/tox.ini index 36213ca..a809273 100644 --- a/tox.ini +++ b/tox.ini @@ -2,5 +2,5 @@ envlist = pypy,pypy3,py36,py35,py34,py33,py27 [testenv] -commands = coverage run --branch --source=withings setup.py test +commands = coverage run --branch --source=nokia setup.py test deps = -r{toxinidir}/requirements/test.txt