diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..49ef590c --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,32 @@ +name: Tests + +on: + push: + branches: + - main + - dev + tags: + - v* + pull_request: + schedule: + - cron: "0 1 * * *" + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.9'] + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python }} + - name: Install dependencies + run: pip install -r requirements.dev.txt + - name: Run tests + working-directory: ./src + run: python -m unittest + env: + TGTG_PASSWORD: ${{secrets.TGTG_PASSWORD}} + TGTG_USERNAME: ${{secrets.TGTG_USERNAME}} \ No newline at end of file diff --git a/Makefile b/Makefile index f339e3e4..b80a6ef3 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,7 @@ bash: docker-compose -f docker-compose.builder.yml run --rm bash builder: - docker-compose -f docker-compose.builder.yml run --rm builder \ No newline at end of file + docker-compose -f docker-compose.builder.yml run --rm builder + +test: + docker-compose -f docker-compose.builder.yml run --rm test \ No newline at end of file diff --git a/README.md b/README.md index 2c32ed19..ae9d656e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,14 @@ [![Publish multi-arch Docker images](https://github.com/Der-Henning/tgtg/actions/workflows/docker-multi-arch.yml/badge.svg?branch=main)](https://github.com/Der-Henning/tgtg/actions/workflows/docker-multi-arch.yml) +[![Tests](https://github.com/Der-Henning/tgtg/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/Der-Henning/tgtg/actions/workflows/tests.yml) # TGTG Scanner Scanns your favorite TGTG Magic Bags for new available items and notifies you via mail, IFTTT or pushSafer. Notifications will be send when the available amount of magic bags rises from zero to something. +## Update + +The TGTG API has been updated! Please update to release 1.2.3 for working notifications! + ## Disclaimer TGTG forbids the use of their plattform the way this tool does. In their Terms and Conditions it says: "The Consumer must not misuse the Platform (including hacking or 'scraping')." @@ -58,6 +63,8 @@ When the scanner is started it will send a test notification on all configured n For developement I recommend using docker. The Makefile depends on docker and docker-compose. +Create ```.env``` based on ```sample.env``` for configuration. + ```make start-dev``` builds and starts the developement docker image ```make image``` builds docker image @@ -66,6 +73,8 @@ For developement I recommend using docker. The Makefile depends on docker and do ```make builder``` runs pyinstaller in python docker image +```make test``` runs unittests + ### Building executables The executables are build with pyinstaller. diff --git a/build.sh b/build.sh deleted file mode 100644 index e9cd1f4c..00000000 --- a/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -pip install -r requirements.dev.txt - -pyinstaller scanner.spec diff --git a/docker-compose.builder.yml b/docker-compose.builder.yml index 5a213d22..c24015cc 100644 --- a/docker-compose.builder.yml +++ b/docker-compose.builder.yml @@ -8,7 +8,13 @@ services: builder: extends: service: base - command: /bin/bash ./build.sh + command: /bin/bash -c "pip install -r requirements.dev.txt && pyinstaller scanner.spec" + test: + extends: + service: base + env_file: + - .env + command: /bin/bash -c "pip install -r requirements.txt && cd src && python -m unittest" bash: extends: service: base diff --git a/sample.env b/sample.env new file mode 100644 index 00000000..f3e743a2 --- /dev/null +++ b/sample.env @@ -0,0 +1,19 @@ +TGTG_USERNAME= +TGTG_PASSWORD= + +SMTP=false +SMTP_HOST=smtp.gmail.com +SMTP_PORT=465 +SMTP_USERNAME= +SMTP_PASSWORD= +SMTP_TLS=true +SMTP_SENDER= +SMTP_RECIPIENT= + +PUSH_SAFER=false +PUSH_SAFER_KEY= +PUSH_SAFER_DEVICE_ID= + +IFTTT=false +IFTTT_EVENT=tgtg_notification +IFTTT_KEY= \ No newline at end of file diff --git a/src/tests/__init__.py b/src/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/tests/tgtg/__init__.py b/src/tests/tgtg/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/tests/tgtg/constants.py b/src/tests/tgtg/constants.py new file mode 100644 index 00000000..980e8033 --- /dev/null +++ b/src/tests/tgtg/constants.py @@ -0,0 +1,50 @@ +GLOBAL_PROPERTIES = [ + "item", + "store", + "display_name", + "pickup_location", + "items_available", + "distance", + "favorite", + "in_sales_window", + "new_item", +] +STORE_PROPERTIES = [ + "store_id", + "store_name", + "description", + "tax_identifier", + "website", + "store_location", + "logo_picture", + "store_time_zone", + "hidden", + "favorite_count", + "items", + "milestones", + "we_care", +] +ITEM_PROPERTIES = [ + "item_id", + "price", + "sales_taxes", + "tax_amount", + "price_excluding_taxes", + "price_including_taxes", + "value_excluding_taxes", + "value_including_taxes", + "taxation_policy", + "show_sales_taxes", + "cover_picture", + "logo_picture", + "name", + "description", + "can_user_supply_packaging", + "packaging_option", + "diet_categories", + "item_category", + "badges", + "positive_rating_reasons", + "favorite_count", + "buffet", +] \ No newline at end of file diff --git a/src/tests/tgtg/test_tgtg.py b/src/tests/tgtg/test_tgtg.py new file mode 100644 index 00000000..528533af --- /dev/null +++ b/src/tests/tgtg/test_tgtg.py @@ -0,0 +1,33 @@ +import unittest +from .constants import GLOBAL_PROPERTIES, ITEM_PROPERTIES, STORE_PROPERTIES +from tgtg import TgtgClient +from os import environ + +class TGTG_API_Test(unittest.TestCase): + def test_get_items(self): + client = TgtgClient( + email=environ["TGTG_USERNAME"], password=environ["TGTG_PASSWORD"] + ) + data = client.get_items( + favorites_only=True + ) + assert len(data) > 0 + for property in GLOBAL_PROPERTIES: + assert property in data[0] + + + def test_get_one_item(self): + client = TgtgClient( + email=environ["TGTG_USERNAME"], password=environ["TGTG_PASSWORD"] + ) + item_id = "36684" + data = client.get_item(item_id) + + for property in GLOBAL_PROPERTIES: + assert property in data + for property in ITEM_PROPERTIES: + assert property in data["item"] + for property in STORE_PROPERTIES: + assert property in data["store"] + + assert data["item"]["item_id"] == item_id \ No newline at end of file diff --git a/src/tgtg/tgtgClient.py b/src/tgtg/tgtgClient.py index 85ed4879..c58e6820 100644 --- a/src/tgtg/tgtgClient.py +++ b/src/tgtg/tgtgClient.py @@ -1,7 +1,7 @@ ## copied from https://github.com/ahivert/tgtg-python import datetime -#import random +import random import logging from http import HTTPStatus from urllib.parse import urljoin @@ -16,9 +16,9 @@ REFRESH_ENDPOINT = "auth/v1/token/refresh" ALL_BUSINESS_ENDPOINT = "map/v1/listAllBusinessMap" USER_AGENTS = [ - "TGTG/20.12.3 Dalvik/2.1.0 (Linux; U; Android 6.0.1; Nexus 5 Build/M4B30Z)", - "TGTG/20.12.3 Dalvik/2.1.0 (Linux; U; Android 7.0; SM-G935F Build/NRD90M)", - "TGTG/20.12.3 Dalvik/2.1.0 (Linux; Android 6.0.1; SM-G920V Build/MMB29K)", + "TGTG/21.9.3 Dalvik/2.1.0 (Linux; U; Android 6.0.1; Nexus 5 Build/M4B30Z)", + "TGTG/21.9.3 Dalvik/2.1.0 (Linux; U; Android 7.0; SM-G935F Build/NRD90M)", + "TGTG/21.9.3 Dalvik/2.1.0 (Linux; Android 6.0.1; SM-G920V Build/MMB29K)", ] DEFAULT_ACCESS_TOKEN_LIFETIME = 3600 * 4 # 4 hours @@ -52,8 +52,7 @@ def __init__( self.user_id = user_id if self.user_id is not None: log.warn("'user_id' is deprecated; use 'email' and 'password'") - #self.user_agent = user_agent if user_agent else random.choice(USER_AGENTS) - self.user_agent = None + self.user_agent = user_agent if user_agent else random.choice(USER_AGENTS) self.language = language self.proxies = proxies self.timeout = timeout