Skip to content

Commit

Permalink
Merge pull request #38 from Yelp/release_1_0_1
Browse files Browse the repository at this point in the history
Release 1.0.1 on pypi, bringing master up to date
  • Loading branch information
watterso committed Jan 21, 2016
2 parents 266a3ba + 0363c4e commit 4a8bea6
Show file tree
Hide file tree
Showing 19 changed files with 383 additions and 305 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,12 @@ We use VCR.py to record and serialize HTTP requests. Add your test to `tests/int
@int_vcr.use_cassette(**cassette_params)

The first time you run the test, VCR.py will record the HTTP request to the folder `/tests/integration/vcr_cassettes` in a yaml file of the same name as the test, filtering out your oauth tokens prior to writing. VCR.py will replay the response for subsequent runs. This allows us to have deterministic tests and continuously integrate with Travis CI. To clear the recorded response, delete the cassette file. Running the test again will make a new HTTP request and record it. For more information, see [VCR.py documentation](https://github.com/kevin1024/vcrpy).

### Git Workflow

We are using the [git flow](http://nvie.com/posts/a-successful-git-branching-model/)
workflow. Atlassian has a [solid overview](https://www.atlassian.com/git/workflows#!workflow-gitflow).
Essentially, new development is merged into the develop branch from feature
branches, then merged from develop to a release branch, then to master from
the release branch. Master should always contain the most recently released
version of the library.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage==4.0
mock==1.3.0
pre-commit==0.6.0
pre-commit==0.7.6
pytest==2.8.1
vcrpy==1.7.4
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup(
name='yelp',

version='1.0',
version='1.0.1',

description='Python Clientlib for Yelp Public API',

Expand All @@ -13,6 +13,15 @@
author='Yelp',
author_email='partnerships@yelp.com',

classifiers=[
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: CPython'
],

license='MIT',

keywords='yelp',
Expand Down
99 changes: 14 additions & 85 deletions tests/client_test.py
Original file line number Diff line number Diff line change
@@ -1,103 +1,32 @@
# -*- coding: UTF-8 -*-
import io
import json

import mock
import pytest
import six

from tests.testing import resource_filename
from yelp.client import Client
from yelp.oauth1_authenticator import Oauth1Authenticator
from yelp.obj.business_response import BusinessResponse
from yelp.obj.search_response import SearchResponse


class TestClient(object):

sample_location = 'San Francisco, CA'

@classmethod
def setup_class(cls):
with io.open(resource_filename('json/credentials.json')) as cred:
test_creds = json.load(cred)
auth = Oauth1Authenticator(**test_creds)
cls.client = Client(auth)

with io.open(resource_filename('json/search_response.json')) as resp:
cls.search_response = json.load(resp)
with io.open(resource_filename('json/business_response.json')) as resp:
cls.business_response = json.load(resp)

def test_get_business_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
request.return_value = self.business_response
response = self.client.get_business('test-id')
request.assert_called_once_with('/v2/business/test-id', {})
assert type(response) is BusinessResponse

def test_get_business_builds_correct_params_with_lang(self):
with mock.patch('yelp.client.Client._make_request') as request:
request.return_value = self.business_response
params = {'lang': 'fr'}
self.client.get_business('test-id', **params)
request.assert_called_once_with('/v2/business/test-id', params)

def test_search_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
request.return_value = self.search_response
params = {
'term': 'food',
}
response = self.client.search(self.sample_location, **params)
params.update({
'location': self.sample_location
})
request.assert_called_once_with('/v2/search/', params)
assert type(response) is SearchResponse

def test_search_builds_correct_params_with_current_lat_long(self):
with mock.patch('yelp.client.Client._make_request') as request:
params = {
'term': 'food',
}
self.client.search(self.sample_location, 0, 0, **params)
params.update({
'location': self.sample_location,
'cll': '0,0'
})
request.assert_called_once_with('/v2/search/', params)

def test_search_by_bounding_box_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
params = {
'term': 'food',
}
self.client.search_by_bounding_box(0, 0, 0, 0, **params)
params['bounds'] = '0,0|0,0'
request.assert_called_once_with('/v2/search/', params)

def test_search_by_coordinates_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
self.client.search_by_coordinates(0, 0, 0, 0, 0)
request.assert_called_once_with('/v2/search/', {'ll': '0,0,0,0,0'})

def test_phone_search_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
request.return_value = self.search_response
params = {
'category': 'fashion'
}
response = self.client.phone_search('5555555555', **params)
params['phone'] = '5555555555'
request.assert_called_once_with('/v2/phone_search/', params)
assert type(response) is SearchResponse
auth = mock.Mock()
cls.client = Client(auth)

def test_add_instance_methods(self):
methods = [
('_private', 'private_method'),
('public', 'public_method')
]
self.client._add_instance_methods(methods)
assert self.client.public == 'public_method'
assert not hasattr(self.client, '_private')

def test_make_connection_closes(self):
mock_conn = mock.Mock()
mock_conn.read.return_value = b"{}"
mock_conn.read.return_value = b'{}'
with mock.patch(
'six.moves.urllib.request.urlopen', return_value=mock_conn,
'six.moves.urllib.request.urlopen', return_value=mock_conn,
):
self.client._make_connection("")
mock_conn.close.assert_called_once_with()
Expand All @@ -106,7 +35,7 @@ def test_make_connection_closes_with_exception(self):
mock_conn = mock.Mock()
mock_conn.read.side_effect = Exception
with mock.patch(
'six.moves.urllib.request.urlopen', return_value=mock_conn,
'six.moves.urllib.request.urlopen', return_value=mock_conn,
):
with pytest.raises(Exception):
self.client._make_connection("")
Expand Down
Empty file added tests/endpoint/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions tests/endpoint/business_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: UTF-8 -*-
import mock

from yelp.client import Client
from yelp.obj.business_response import BusinessResponse


class TestBusiness(object):

@classmethod
def setup_class(cls):
auth = mock.Mock()
cls.client = Client(auth)

def test_get_business_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
request.return_value = '{}'
response = self.client.get_business('test-id')
request.assert_called_once_with('/v2/business/test-id', {})
assert type(response) is BusinessResponse

def test_get_business_builds_correct_params_with_lang(self):
with mock.patch('yelp.client.Client._make_request') as request:
params = {'lang': 'fr'}
self.client.get_business('test-id', **params)
request.assert_called_once_with('/v2/business/test-id', params)
24 changes: 24 additions & 0 deletions tests/endpoint/phone_search_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: UTF-8 -*-
import mock

from yelp.client import Client
from yelp.obj.search_response import SearchResponse


class TestBusiness(object):

@classmethod
def setup_class(cls):
auth = mock.Mock()
cls.client = Client(auth)

def test_phone_search_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
request.return_value = '{}'
params = {
'category': 'fashion'
}
response = self.client.phone_search('5555555555', **params)
params['phone'] = '5555555555'
request.assert_called_once_with('/v2/phone_search/', params)
assert type(response) is SearchResponse
54 changes: 54 additions & 0 deletions tests/endpoint/search_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: UTF-8 -*-
import mock

from yelp.client import Client
from yelp.obj.search_response import SearchResponse


class TestBusiness(object):

sample_location = 'San Francisco, CA'

@classmethod
def setup_class(cls):
auth = mock.Mock()
cls.client = Client(auth)

def test_search_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
request.return_value = '{}'
params = {
'term': 'food',
}
response = self.client.search(self.sample_location, **params)
params.update({
'location': self.sample_location
})
request.assert_called_once_with('/v2/search/', params)
assert type(response) is SearchResponse

def test_search_builds_correct_params_with_current_lat_long(self):
with mock.patch('yelp.client.Client._make_request') as request:
params = {
'term': 'food',
}
self.client.search(self.sample_location, 0, 0, **params)
params.update({
'location': self.sample_location,
'cll': '0,0'
})
request.assert_called_once_with('/v2/search/', params)

def test_search_by_bounding_box_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
params = {
'term': 'food',
}
self.client.search_by_bounding_box(0, 0, 0, 0, **params)
params['bounds'] = '0,0|0,0'
request.assert_called_once_with('/v2/search/', params)

def test_search_by_coordinates_builds_correct_params(self):
with mock.patch('yelp.client.Client._make_request') as request:
self.client.search_by_coordinates(0, 0, 0, 0, 0)
request.assert_called_once_with('/v2/search/', {'ll': '0,0,0,0,0'})
14 changes: 0 additions & 14 deletions tests/obj/rating_test.py

This file was deleted.

6 changes: 3 additions & 3 deletions tests/obj/response_object_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import json

from tests.testing import resource_filename
from yelp.obj.business import Business
from yelp.obj.deal import Deal
from yelp.obj.location import Location
from yelp.obj.rating import Rating
from yelp.obj.response_object import ResponseObject


Expand Down Expand Up @@ -39,5 +39,5 @@ def test_response_obj_parse_one(self):

def test_parse_main_response_body(self):
obj = ResponseObject('{}')
obj._parse_main_response_body('rating', Rating, self.response)
assert type(obj.rating) is Rating
obj._parse_main_response_body('business', Business, self.response)
assert type(obj.business) is Business
2 changes: 0 additions & 2 deletions tests/obj/review_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json

from tests.testing import resource_filename
from yelp.obj.rating import Rating
from yelp.obj.review import Review
from yelp.obj.user import User

Expand All @@ -13,5 +12,4 @@ def test_init_review():
response = json.load(biz)['reviews'][0]
review = Review(response)
assert review.id == response['id']
assert type(review.rating) is Rating
assert type(review.user) is User
Loading

0 comments on commit 4a8bea6

Please sign in to comment.