Skip to main content

A fake spotipy client. For unit tests and stuff.

Project description

fakespotipy

A fake spotipy client. For unit tests and stuff.

Installation

pip install fakespotipy

Usage

# Initialize the client
>>> from fakespotipy import FakeSpotify
>>> client = FakeSpotify()

# 1. Example of a mock object response
# First, set up a mock response
>>> response = {
...     'expires_in': 60,
...     'access_token': 'BQDdKdI1eLRl2ErhCRC0jHdfr_DYEm_ecUuUPq2-dW_txQZeCrA32lNSYOZO7v7rEPXqC846nHlgSeg4m0c3-y05W9ISJRluCXdco4igf8eMhgLojXZb4RbE0vmlH4a06T3TX7Jg-uN1ClYFEkXnCGCA0NBNqkiFYDKlvMWqZExQom-XF-8pr6gV_PpzNJ2eKRRR6_ORp1ABUhtJ_aD8f5W4GexLq1mzpWQLkKE_Fq_LuwE1JhpxxNxRI-FLtzz46Jc',
...     'token_type': 'Bearer',
...     'refresh_token': 'AQDDNE-U4IElufFWfNjlwy7rOn-Kyt2PeIN1Nze2I5rVi7c9Etcx9blVkHVe5liSoKRMbJzS3etlA3sQ-0UqMKxRJ-HN08jrO_1IoDgciSZOaAUaQUiSkBOgtgnmO_tEHCU',
...     'scope': 'user-top-read',
... }

# Prep the client with that response
>>> client.add_response('refresh_access_token', response)

# And trigger it
>>> client.refresh_access_token('refresh_token_str_here')
{'access_token': 'BQDdKdI1eLRl2ErhCRC0jHdfr_DYEm_ecUuUPq2-dW_txQZeCrA32lNSYOZO7v7rEPXqC846nHlgSeg4m0c3-y05W9ISJRluCXdco4igf8eMhgLojXZb4RbE0vmlH4a06T3TX7Jg-uN1ClYFEkXnCGCA0NBNqkiFYDKlvMWqZExQom-XF-8pr6gV_PpzNJ2eKRRR6_ORp1ABUhtJ_aD8f5W4GexLq1mzpWQLkKE_Fq_LuwE1JhpxxNxRI-FLtzz46Jc', 'token_type': 'Bearer', 'expires_in': 60, 'refresh_token': 'AQDDNE-U4IElufFWfNjlwy7rOn-Kyt2PeIN1Nze2I5rVi7c9Etcx9blVkHVe5liSoKRMbJzS3etlA3sQ-0UqMKxRJ-HN08jrO_1IoDgciSZOaAUaQUiSkBOgtgnmO_tEHCU', 'scope': 'user-top-read'}

# If we try again, we get a NotImplementedError
>>> client.refresh_access_token('refresh_token_str_here')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fakespotipy.py", line 37, in method
    raise NotImplementedError
NotImplementedError

# 2. Example of a mock function response
# First set up the mock function
>>> def refresh_response(refresh_token_str):
...     print "i'm refreshing!"
...     if refresh_token_str == 'foo':
...         raise Exception("Foo! Oh noes!")
...     return {'foo': 'bar'}
... 

# Add it a couple of times (so we can call it twice)
>>> client.add_response('refresh_access_token', refresh_response)
>>> client.add_response('refresh_access_token', refresh_response)

# Trigger it
>>> client.refresh_access_token('refresh_token_str_here')
i'm refreshing!
{'foo': 'bar'}

# Trigger again, using anticipated input to trigger custom Exception
>>> client.refresh_access_token('foo')
i'm refreshing!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fakespotipy.py", line 40, in method
    return response(*args, **kwargs)
  File "<stdin>", line 4, in refresh_response
Exception: Foo! Oh noes!

# Try one more time, get NotImplementedError
>>> client.refresh_access_token('foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fakespotipy.py", line 37, in method
    raise NotImplementedError
NotImplementedError

Testing

python setup.py test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fakespotipy-0.8.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

fakespotipy-0.8.0-py2.py3-none-any.whl (2.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file fakespotipy-0.8.0.tar.gz.

File metadata

  • Download URL: fakespotipy-0.8.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fakespotipy-0.8.0.tar.gz
Algorithm Hash digest
SHA256 f15a26c8198b47e6b7fabde244fb75f16c9b538fd52e7ede9f299b6818183670
MD5 20b42ce8ab1cd58448b7a2f1f39a1471
BLAKE2b-256 7cc47dafce580cb84a8c27869fa1fa371b4478879c20798f74991344a51fe4f0

See more details on using hashes here.

File details

Details for the file fakespotipy-0.8.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for fakespotipy-0.8.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ce8b290db5febf0954b5f0275f0ad95a8320b34525efe8006415e2461109dbfc
MD5 daec99850aaea640d510591a6f54d977
BLAKE2b-256 e0a7a73bd38cf9379c5c46a0931c4e75c0e45412cd1b82b55f81147f4dad31c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page