Prva verzija mini web serverja (flask). Hvala, Github Copilot.
This commit is contained in:
106
tests/test_mock.py
Normal file
106
tests/test_mock.py
Normal file
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Test Flask servera brez Tkinter aplikacije
|
||||
"""
|
||||
|
||||
import sqlite3
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Simuliraj SongProjector stanu
|
||||
class MockSongProjector:
|
||||
def __init__(self):
|
||||
self.current_song = None
|
||||
self.pages = []
|
||||
self.current_page_index = 0
|
||||
self.song_number = ""
|
||||
self.song_number_last = ""
|
||||
self.all_caps_mode = False
|
||||
self.waiting_for_song = True
|
||||
|
||||
# Otvori bazu
|
||||
try:
|
||||
self.conn = sqlite3.connect(f"file:songs.db?mode=ro", uri=True)
|
||||
self.cursor = self.conn.cursor()
|
||||
except:
|
||||
self.conn = None
|
||||
self.cursor = None
|
||||
|
||||
# Čitaj settings
|
||||
with open('settings.json', 'r', encoding='utf-8') as f:
|
||||
self.settings = json.load(f)
|
||||
|
||||
def load_song(self):
|
||||
"""Simulacija load_song metode"""
|
||||
if not self.song_number or not self.cursor:
|
||||
return
|
||||
|
||||
try:
|
||||
song_id = int(self.song_number)
|
||||
self.cursor.execute("SELECT lyrics FROM songs WHERE id=?", (song_id,))
|
||||
result = self.cursor.fetchone()
|
||||
if result:
|
||||
lyrics = result[0]
|
||||
self.pages = [lyrics] # Jednostavno - brez stranica
|
||||
self.current_page_index = 0
|
||||
self.waiting_for_song = False
|
||||
self.song_number_last = self.song_number
|
||||
else:
|
||||
self.pages = []
|
||||
self.waiting_for_song = True
|
||||
except:
|
||||
self.pages = []
|
||||
finally:
|
||||
self.song_number = ""
|
||||
|
||||
def next_page(self):
|
||||
if self.pages and self.current_page_index + 1 < len(self.pages):
|
||||
self.current_page_index += 1
|
||||
|
||||
def prev_page(self):
|
||||
if self.pages and self.current_page_index > 0:
|
||||
self.current_page_index -= 1
|
||||
|
||||
def clear_screen(self):
|
||||
self.pages = []
|
||||
self.current_page_index = 0
|
||||
self.waiting_for_song = True
|
||||
|
||||
def show_page(self):
|
||||
pass # Dummy
|
||||
|
||||
# Kreiraj mock aplikacijo
|
||||
app_mock = MockSongProjector()
|
||||
|
||||
# Testiraj
|
||||
print("=" * 60)
|
||||
print("Test MockSongProjector")
|
||||
print("=" * 60)
|
||||
|
||||
print("\n1. Početno stanje:")
|
||||
print(f" Pages: {len(app_mock.pages)}")
|
||||
print(f" Current page: {app_mock.current_page_index}")
|
||||
print(f" Waiting for song: {app_mock.waiting_for_song}")
|
||||
|
||||
print("\n2. Naloži pesmu broj 1:")
|
||||
app_mock.song_number = "1"
|
||||
app_mock.load_song()
|
||||
print(f" Pages: {len(app_mock.pages)}")
|
||||
print(f" Current page: {app_mock.current_page_index}")
|
||||
print(f" Waiting for song: {app_mock.waiting_for_song}")
|
||||
print(f" Text: {(app_mock.pages[0] if app_mock.pages else 'N/A')[:50]}...")
|
||||
|
||||
print("\n3. Očisti ekran:")
|
||||
app_mock.clear_screen()
|
||||
print(f" Pages: {len(app_mock.pages)}")
|
||||
print(f" Waiting for song: {app_mock.waiting_for_song}")
|
||||
|
||||
print("\n4. Web konfiguracija:")
|
||||
print(f" Web port: {app_mock.settings.get('web_port', 'nije postavljeno')}")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("Svi testovi su prošli!")
|
||||
print("=" * 60)
|
||||
Reference in New Issue
Block a user