Skip to content

Commit

Permalink
Merge pull request #10 from Der-Henning/dev
Browse files Browse the repository at this point in the history
Added Tests
  • Loading branch information
Der-Henning authored Oct 6, 2021
2 parents a7bbb1c + 67a4165 commit ede4cef
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 11 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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}}
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
docker-compose -f docker-compose.builder.yml run --rm builder

test:
docker-compose -f docker-compose.builder.yml run --rm test
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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')."
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions build.sh

This file was deleted.

8 changes: 7 additions & 1 deletion docker-compose.builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -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=
Empty file added src/tests/__init__.py
Empty file.
Empty file added src/tests/tgtg/__init__.py
Empty file.
50 changes: 50 additions & 0 deletions src/tests/tgtg/constants.py
Original file line number Diff line number Diff line change
@@ -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",
]
33 changes: 33 additions & 0 deletions src/tests/tgtg/test_tgtg.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 5 additions & 6 deletions src/tgtg/tgtgClient.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ede4cef

Please sign in to comment.