Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pytest Test Suite #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ build/
dist/
*.egg-info/
.idea/
# Python virtual-environment
/venv
# Created by pytest
.pytest_cache
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,36 @@ An important note about login function:
def login(self, email=None, password=None, gsfId=None, authSubToken=None)
```
for first time logins, you should only provide email and password.
The module will take care of initalizing the api,upload device information
to the google account you supplied, and retrieving
The module will take care of initalizing the api,upload device information
to the google account you supplied, and retrieving
a Google Service Framework ID (which, from now on, will be the android ID of a device).

For the next logins you **should** save the gsfId and the authSubToken, and provide them as parameters to the login function. If you login again with email and password only, this is the equivalent of re-initalizing your android device with a google account.

# Documentation

For some documentation about the google play API check out the relative folder.

# Development

If you haven't already, set up a virtual environment in the top-level of the project:

```
# Create the virtual environment
python3 -m venv venv
# Activate the virtual environment
source venv/bin/activate
# Install the project's dependencies
pip install -r requirements.txt
```

The dependencies installed for development include those described in `setup.py` as well as `pytest`, which is used to run the automated test suite.

To run `pytest`, first export your account `EMAIL` and `PASSWORD`, and also a hex-encoded `GSFID`, as environment variables. Next, run `pytest`.

```
export EMAIL='XXX'
export PASSWORD='XXX'
export GSFID='XXX'
python -m pytest -v
```
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
python_files = test_*.py
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
attrs==17.4.0
certifi==2018.1.18
chardet==3.0.4
idna==2.6
pluggy==0.6.0
protobuf==3.5.2
py==1.5.2
pycryptodome==3.5.1
pytest==3.4.2
requests==2.18.4
six==1.11.0
urllib3==1.22
36 changes: 36 additions & 0 deletions test/test_googleplay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import unittest

from gpapi.googleplay import GooglePlayAPI

class TestGooglePlay(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.EMAIL = os.environ['EMAIL']
cls.PASSWORD = os.environ['PASSWORD']
cls.GSFID = int(os.environ['GSFID'], 16)
# Next, get AUTHSUBTOKEN. These expire, so it must be regenerated each
# time the tests are run.
api = GooglePlayAPI(locale='en_US', timezone='EST')
c_password = api.encrypt_password(
cls.EMAIL, cls.PASSWORD).decode('utf-8')
api.getAuthSubToken(cls.EMAIL, c_password)
cls.AUTHSUBTOKEN = api.authSubToken

def setUp(self):
# Create a fresh instance of GooglePlayAPI for each test
self.API = GooglePlayAPI(locale='en_US', timezone='EST')
self.API.login(gsfId=self.GSFID, authSubToken=self.AUTHSUBTOKEN)

def test_search(self):
# Search for 'firefox', requesting just 1 result
results = self.API.search('firefox', 1)
self.assertTrue(len(results), 1)
result = results[0]
# Check that the legit Firefox app was found
self.assertEqual(result['docId'], 'org.mozilla.firefox')
# TODO Add assertions for each of the attributes which the rest of our
# code depends on. For now, I think this is the only attribute we
# depend on.
self.assertIn('versionCode', result)