Skip to main content

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

Metadata

Release files for fakespotipy 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fakespotipy 0.7.0
File Size Uploaded
fakespotipy-0.7.0.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fakespotipy 0.7.0
File Interpreter ABI Platform
fakespotipy-0.7.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 5.7 kB

Release files / fakespotipy-0.7.0.tar.gz

Download URL fakespotipy-0.7.0.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b2f221f08f83b570a7da943c12db0e46950b595664e946b8f1fa51de19a7ae5b
BLAKE2b-256 checksum
How to use checksums
0ad60a299f3b1e6d3af02b27828813d7366780eb1bdf2be084f7076c9ce37266
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / fakespotipy-0.7.0-py2.py3-none-any.whl

Download URL fakespotipy-0.7.0-py2.py3-none-any.whl
Size 2.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
37ea4a228e4db122ff8c31b41d26497f9e528773f0b1141c12959b6c1d4fa53e
BLAKE2b-256 checksum
How to use checksums
aa2ae09625b67343b8be7dc511401c0e713f30bbbbe5994f3454927253b5e375
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.8.0

2 release files

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page