mirror of
https://github.com/acatoire/bipbipzizik.git
synced 2026-03-10 08:01:18 +00:00
Read only database access is tested
This commit is contained in:
8
box.py
8
box.py
@@ -13,9 +13,9 @@ import requests
|
||||
# Bipbipzizic import
|
||||
from modules.rfid_reader.Reader import Reader
|
||||
from modules.card_memory.CardMemory import CardMemory
|
||||
from modules.cards_bdd.Card import Card
|
||||
from modules.cards_bdd.AppConfig import AppConfig
|
||||
from modules.cards_bdd.DbManager import DbManager
|
||||
from modules.bipbipzizik_database.Card import Card
|
||||
from modules.bipbipzizik_database.AppConfig import AppConfig
|
||||
from modules.bipbipzizik_database.DbManager import DbManager
|
||||
from modules.tools import get_serial
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ def main():
|
||||
UPDATE_PERIOD = 60
|
||||
|
||||
reader = Reader()
|
||||
database = DbManager('https://bipbipzizik.firebaseio.com/', 'prod', 'modules/cards_bdd/serviceAccountKey.json')
|
||||
database = DbManager('https://bipbipzizik.firebaseio.com/', 'prod', 'modules/bipbipzizik_database/serviceAccountKey.json')
|
||||
|
||||
app_serial = get_serial()
|
||||
cfg = database.get_config(app_serial)
|
||||
|
||||
@@ -59,12 +59,14 @@ class AppConfig:
|
||||
"""
|
||||
|
||||
print("Application config:")
|
||||
print(self.cfg_application_id)
|
||||
print(self.cfg_sonos_server_ip)
|
||||
print(self.cfg_sonos_server_port)
|
||||
print(self.cfg_room_name)
|
||||
print(self.cfg_multi_read_mode)
|
||||
print(self.cfg_card_timeout)
|
||||
print(" - " + self.cfg_app_name)
|
||||
print(" - " + self.cfg_app_owner)
|
||||
print(" - " + self.cfg_application_id)
|
||||
print(" - " + self.cfg_sonos_server_ip)
|
||||
print(" - " + self.cfg_sonos_server_port)
|
||||
print(" - " + self.cfg_room_name)
|
||||
print(" - " + self.cfg_multi_read_mode)
|
||||
print(" - " + str(self.cfg_card_timeout))
|
||||
|
||||
|
||||
# For test purpose
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
# Script that fill the database with all cards
|
||||
|
||||
from modules.cards_bdd.DbManager import DbManager
|
||||
from modules.bipbipzizik_database.DbManager import DbManager
|
||||
|
||||
data_base = DbManager('https://bipbipzizik.firebaseio.com/', 'prod', 'WriteKey.json')
|
||||
data_base.delete('cards_prod')
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
# Script that fill the database with all configs
|
||||
|
||||
from modules.cards_bdd.DbManager import DbManager
|
||||
from modules.bipbipzizik_database.DbManager import DbManager
|
||||
|
||||
data_base = DbManager('https://bipbipzizik.firebaseio.com/', 'prod', 'WriteKey.json')
|
||||
data_base.delete('config_prod')
|
||||
@@ -6,8 +6,9 @@
|
||||
|
||||
from firebase import firebase
|
||||
|
||||
from .Card import Card
|
||||
from .AppConfig import AppConfig
|
||||
|
||||
from modules.bipbipzizik_database.Card import Card
|
||||
from modules.bipbipzizik_database.AppConfig import AppConfig
|
||||
|
||||
|
||||
class DbReader:
|
||||
@@ -37,7 +38,8 @@ class DbReader:
|
||||
"""
|
||||
|
||||
self.config_db_python = self.database.get('/' + self.config_bdd_name, None)
|
||||
self.cards_db_python = self.database.get('/' + self.config_bdd_name, None)
|
||||
self.cards_db_python = self.database.get('/' + self.card_bdd_name, None)
|
||||
|
||||
|
||||
def count_cards(self):
|
||||
"""
|
||||
@@ -6,8 +6,7 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from modules.cards_bdd.Card import Card
|
||||
from modules.cards_bdd.DbManager import DbManager
|
||||
from modules.bipbipzizik_database.DbManager import DbManager
|
||||
|
||||
|
||||
class CardsWrite(unittest.TestCase):
|
||||
61
modules/bipbipzizik_database/test_DatabaseRead.py
Normal file
61
modules/bipbipzizik_database/test_DatabaseRead.py
Normal file
@@ -0,0 +1,61 @@
|
||||
#
|
||||
# BIPBIPZIZIK
|
||||
# Unit test for Card and FirebaseBdd classes
|
||||
# It test the read of cards on production database with a public key
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
from modules.bipbipzizik_database.DbReader import DbReader
|
||||
|
||||
|
||||
class DatabaseReadTest(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
cls.database = DbReader('https://bipbipzizik.firebaseio.com/', 'prod')
|
||||
|
||||
# def setUp(self):
|
||||
# nothing yet
|
||||
|
||||
def test_read_card(self):
|
||||
card_expected = {"user": "user",
|
||||
"name": "name",
|
||||
"comment": "comment",
|
||||
"ids": "template",
|
||||
"mode": "mode",
|
||||
"action": "action",
|
||||
"data": "data"}
|
||||
|
||||
card = self.database.get_card("template")
|
||||
|
||||
self.assertEqual(card.parameters, card_expected)
|
||||
|
||||
def test_read_config(self):
|
||||
card_expected = {"app_name": "For test purpose",
|
||||
"app_owner": "axel",
|
||||
"app_id": "template",
|
||||
"sonos_server_ip": "HHH.UUU.GGG.OOO",
|
||||
"sonos_server_port": "2017",
|
||||
"room_name": "Ginette",
|
||||
"multi_read_mode": "none",
|
||||
"card_timeout": "42"}
|
||||
|
||||
config = self.database.get_config("template")
|
||||
|
||||
self.assertEqual(config.cfg_app_name, card_expected.get("app_name"))
|
||||
self.assertEqual(config.cfg_app_owner, card_expected.get("app_owner"))
|
||||
self.assertEqual(config.cfg_application_id, card_expected.get("app_id"))
|
||||
self.assertEqual(config.cfg_sonos_server_ip, card_expected.get("sonos_server_ip"))
|
||||
self.assertEqual(config.cfg_sonos_server_port, card_expected.get("sonos_server_port"))
|
||||
self.assertEqual(config.cfg_room_name, card_expected.get("room_name"))
|
||||
self.assertEqual(config.cfg_multi_read_mode, card_expected.get("multi_read_mode"))
|
||||
self.assertEqual(config.cfg_card_timeout, int(card_expected.get("card_timeout")))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#
|
||||
# BIPBIPZIZIK
|
||||
# Unit test for Card and FirebaseBdd classes
|
||||
# It test the read of cards on production database with a public key
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
from modules.cards_bdd.Card import Card
|
||||
from modules.cards_bdd.DbManager import DbManager
|
||||
|
||||
|
||||
class CardsRead(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
cls.bdd = DbManager('https://bipbipzizik.firebaseio.com/', 'prod', 'ReadKey.json')
|
||||
|
||||
# def setUp(self):
|
||||
# nothing yet
|
||||
|
||||
def test_read_card(self):
|
||||
card_expected = {"user": "user",
|
||||
"name": "name",
|
||||
"comment": "comment",
|
||||
"ids": "template",
|
||||
"mode": "mode",
|
||||
"action": "action",
|
||||
"data": "data"}
|
||||
|
||||
card = self.bdd.get_card("template")
|
||||
|
||||
self.assertEqual(card.parameters, card_expected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#
|
||||
# BIPBIPZIZIK
|
||||
# Unit test for Card and FirebaseBdd classes
|
||||
# It test the read of cards on production database with a public key
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
from modules.cards_bdd.Card import Card
|
||||
from modules.cards_bdd.DbManager import DbManager
|
||||
|
||||
|
||||
class ConfigRead(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
#def setUpClass(cls):
|
||||
|
||||
#cls.bdd = DbManager('https://bipbipzizik.firebaseio.com/', 'prod', 'ReadKey.json')
|
||||
|
||||
# def setUp(self):
|
||||
# nothing yet
|
||||
|
||||
def test_read_config(self):
|
||||
card_expected = {"app_name": "For test purpose",
|
||||
"app_owner": "axel",
|
||||
"app_id": "template",
|
||||
"sonos_server_ip": "HHH.UUU.GGG.OOO",
|
||||
"sonos_server_port": "2017",
|
||||
"room_name": "Ginette",
|
||||
"multi_read_mode": "none",
|
||||
"card_timeout": "42"}
|
||||
self.database = DbManager('https://bipbipzizik.firebaseio.com/', 'prod', 'ReadKey.json')
|
||||
config = self.database.get_config("template")
|
||||
config.print()
|
||||
self.assertEqual(config.cfg_sonos_server_port, "2017")
|
||||
self.assertEqual(config.cfg_app_name, "For test purpose")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
requests
|
||||
evdev==1.2.0
|
||||
# For firebase read only
|
||||
firebase
|
||||
python_jwt
|
||||
gcloud
|
||||
sseclient
|
||||
requests-toolbelt
|
||||
pycryptodome
|
||||
# For firebase read/write
|
||||
firebase_admin==3.1.0
|
||||
requests
|
||||
cryptography==2.8
|
||||
urllib3==1.25.6
|
||||
urllib3==1.25.7
|
||||
# For usb read, not avaiable on windows
|
||||
evdev==1.2.0
|
||||
Reference in New Issue
Block a user