Skip to content

Commit 9820cae

Browse files
Merge pull request #170 from MothScientist/fix
update
2 parents 185f959 + 1834132 commit 9820cae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1615
-553
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Codes of conduct help create a community based on kindness, cooperation, and mutual respect
2+
3+
1. Respect other participants, avoid offensive language and discrimination
4+
2. Interact openly and constructively, value diversity of opinions and ideas
5+
3. Be honest and transparent in your actions and communications
6+
4. Seek to collaborate and support each other to achieve common goals
7+
5. Avoid breaches of confidentiality and respect the personal space of each participant

.github/workflows/eslint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Eslint
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'tests/**'
7+
pull_request:
8+
paths-ignore:
9+
- 'tests/**'
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: '22'
23+
24+
- name: npm install
25+
run: |
26+
npm install
27+
28+
- name: Lint with eslint
29+
run: |
30+
npx eslint . --ignore-pattern 'tests/**' # Запускаем ESLint, исключая папку tests

.github/workflows/flake8.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
# stop the build if there are Python syntax errors or undefined names
3535
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3636
# --exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37-
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
37+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics

.github/workflows/go_lint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Golangci-lint
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'tests/**'
7+
pull_request:
8+
paths-ignore:
9+
- 'tests/**'
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: '1.23'
23+
24+
- name: Lint with golangci-lint
25+
run: |
26+
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
27+
golangci-lint run ./... --exclude-use-default # Запускаем линтер для всех файлов, исключая папку tests

.github/workflows/unit_tests.yml

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
pip install --upgrade pip
3737
pip install -r requirements.txt
3838
pip install pytest
39+
pip install pytest-asyncio
3940
4041
- name: Create .env file
4142
env:
@@ -47,9 +48,14 @@ jobs:
4748
- name: Run UnitTests
4849
run: |
4950
cd tests || exit 1
50-
python -m pytest test_sources.py test_validators.py test_localization.py test_user_cache.py test_csv_tables.py
51+
python -m pytest \
52+
test_sources.py \
53+
test_validators.py \
54+
test_localization.py \
55+
test_user_cache.py \
56+
test_csv_tables.py
5157
52-
database-queries-unit-tests:
58+
database-queries-unit-tests-1:
5359
runs-on: ubuntu-latest
5460

5561
services:
@@ -107,4 +113,66 @@ jobs:
107113
- name: Run UnitTests
108114
run: |
109115
cd tests || exit 1
110-
python -m pytest test_database_queries.py
116+
rm -f pytest.ini # no need to run async tests
117+
python -m pytest test_database_queries_1.py
118+
119+
database-queries-unit-tests-2:
120+
runs-on: ubuntu-latest
121+
122+
services:
123+
postgres:
124+
image: postgres:16.2-alpine3.18
125+
env:
126+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
127+
options: >-
128+
--health-cmd pg_isready
129+
--health-interval 10s
130+
--health-timeout 5s
131+
--health-retries 5
132+
ports:
133+
- 5432:5432
134+
135+
steps:
136+
- name: Checkout repository
137+
uses: actions/checkout@v4
138+
139+
- name: Set up Python
140+
uses: actions/setup-python@v5
141+
with:
142+
python-version: '3.12'
143+
architecture: 'x64'
144+
check-latest: true
145+
146+
- name: Install dependencies
147+
run: |
148+
pip install --upgrade pip
149+
pip install -r requirements.txt
150+
pip install pytest
151+
152+
- name: Create .env file
153+
env:
154+
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
155+
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
156+
POSTGRES_NAME: ${{ secrets.POSTGRES_NAME }}
157+
POSTGRES_USERNAME: ${{ secrets.POSTGRES_USERNAME }}
158+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
159+
HASH_LOG_SALT_TEST: ${{ secrets.HASH_LOG_SALT_TEST }}
160+
run: |
161+
cd budget_graph
162+
echo "POSTGRES_HOST=${POSTGRES_HOST}" >> .env
163+
echo "POSTGRES_PORT=${POSTGRES_PORT}" >> .env
164+
echo "POSTGRES_NAME=${POSTGRES_NAME}" >> .env
165+
echo "POSTGRES_USERNAME=${POSTGRES_USERNAME}" >> .env
166+
echo "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}" >> .env
167+
echo "HASH_LOG_SALT"=${HASH_LOG_SALT_TEST} >> .env
168+
169+
- name: Build infrastructure
170+
run: |
171+
cd tests || exit 1
172+
python build_test_infrastructure.py
173+
174+
- name: Run UnitTests
175+
run: |
176+
cd tests || exit 1
177+
rm -f pytest.ini # no need to run async tests
178+
python -m pytest test_database_queries_2.py

.pylintrc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
[MASTER]
2+
fail-under=9.9
23
ignore-paths=
34
tests/.*
45

56
disable=
67
logging-fstring-interpolation,
7-
missing-module-docstring,
88
missing-function-docstring,
9-
wrong-import-position,
9+
missing-module-docstring,
10+
consider-using-f-string,
1011
missing-class-docstring,
1112
too-few-public-methods,
13+
no-value-for-parameter,
14+
wrong-import-position,
1215
trailing-whitespace,
13-
consider-using-f-string,
16+
bad-indentation,
1417
fixme
18+
1519
[FORMAT]
1620
max-line-length=120

Dockerfile-bot

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ RUN rm build_project.py \
2626
sql/create_db.sql \
2727
sql/indexes.sql \
2828
sql/func_auto_count_users_of_group.sql \
29-
sql/func_transaction_number.sql
29+
sql/func_transaction_number.sql \
30+
sql/update_group_uuid_after_transaction.sql
3031

3132
# Removing some unnecessary directories
3233
RUN rm -rf /static \

budget_graph/bot.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313

1414
sys_path.append('../')
1515
from budget_graph.logger import setup_logger
16-
# from budget_graph.time_checking import timeit
17-
from budget_graph.create_csv import CsvFileWithTable
1816
from budget_graph.registration_service import user_registration
1917
from budget_graph.dictionary import Stickers, receive_translation
2018
from budget_graph.encryption import getting_hash, get_salt, logging_hash
19+
from budget_graph.create_csv import CsvFileWithTable, check_csv_is_actual
2120
from budget_graph.user_cache_structure import UserLanguageCache, UserRegistrationStatusCache
22-
from budget_graph.db_manager import DatabaseQueries, connect_db, close_db, connect_defer_close_db
21+
from budget_graph.db_manager import connect_defer_close_db
2322
from budget_graph.validation import date_validation, value_validation, description_validation, username_validation, \
2423
password_validation, category_validation
2524
from budget_graph.helpers import StorageMsgIdForDeleteAfterOperation, get_category_button_labels, get_bot_commands, \
@@ -553,16 +552,18 @@ def get_csv(db_connection, message, user_language: str) -> None:
553552
telegram_id: int = message.from_user.id
554553
group_id: int = db_connection.get_group_id_by_telegram_id(telegram_id)
555554
# to be able to call a function from any file
556-
file_path: str = path.join(path.dirname(__file__), f'csv_tables/table_{group_id}.csv')
555+
group_uuid: str = db_connection.get_group_transaction_uuid(group_id)
556+
file_path: str = path.join(path.dirname(__file__), f'csv_tables/{group_id}_{group_uuid}.csv')
557557
# 10_000 row limit
558558
table_data: tuple[tuple, ...] = db_connection.select_data_for_household_table(group_id, 0)
559559
if table_data:
560560
try:
561561
csv_obj = CsvFileWithTable(file_path, table_data)
562-
csv_obj.create_csv_file()
562+
if not check_csv_is_actual(group_id, group_uuid):
563+
csv_obj.create_csv_file()
563564
file_size: float = csv_obj.get_file_size_kb()
564565
file_checksum: str = csv_obj.get_file_checksum()
565-
with open(f'csv_tables/table_{group_id}.csv', 'rb') as csv_table_file:
566+
with open(f'csv_tables/{group_id}_{group_uuid}.csv', 'rb') as csv_table_file:
566567
caption: str = (f"{receive_translation(user_language, 'file_size')}: "
567568
f"{'{:.3f}'.format(file_size)} kB\n\n"
568569
f"{receive_translation(user_language, 'hashsum')} "
@@ -820,13 +821,12 @@ def process_delete_group(db_connection, message, group_id: int, user_language: s
820821

821822

822823
# TODO reuse func
823-
def get_str_with_group_users(telegram_id: int, with_owner: bool) -> str:
824+
@connect_defer_close_db
825+
def get_str_with_group_users(db_connection, telegram_id: int, with_owner: bool) -> str:
824826
user_language: str = check_user_language(telegram_id)
825-
connection = connect_db()
826-
bot_db = DatabaseQueries(connection)
827-
group_id: int = bot_db.get_group_id_by_telegram_id(telegram_id)
828-
group_owner_username: str = bot_db.get_group_owner_username_by_group_id(group_id)
829-
group_users_list: tuple = bot_db.get_group_usernames(group_id)
827+
group_id: int = db_connection.get_group_id_by_telegram_id(telegram_id)
828+
group_owner_username: str = db_connection.get_group_owner_username_by_group_id(group_id)
829+
group_users_list: tuple = db_connection.get_group_usernames(group_id)
830830

831831
if with_owner:
832832
res: str = '\n'.join(
@@ -842,7 +842,6 @@ def get_str_with_group_users(telegram_id: int, with_owner: bool) -> str:
842842
for user in group_users_list
843843
if user != group_owner_username
844844
)
845-
close_db(connection)
846845
return res
847846

848847

budget_graph/build_project.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def create_tables_in_db() -> None:
3232
Creating a Database Infrastructure
3333
"""
3434
conn = connect_db()
35-
sql_filenames: tuple = ('create_db', 'indexes', 'func_transaction_number', 'func_auto_count_users_of_group')
35+
sql_filenames: tuple = ('create_db', 'indexes', 'func_transaction_number', 'func_auto_count_users_of_group',
36+
'update_group_uuid_after_transaction')
3637
try:
3738
with conn.cursor() as cur:
3839
for filename in sql_filenames:

budget_graph/create_csv.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,13 @@ def validate_incoming_data(self):
8383
# the length of each nested tuple is equal to the number of columns in the table
8484
if not all(len(self.table_headers) == len(_row) for _row in self.table_data):
8585
raise ValueError('Data tuples have different lengths and/or their lengths do not match the headers')
86+
87+
88+
def check_csv_is_actual(group_id: int, group_uuid: str) -> bool:
89+
"""
90+
Checks for the presence of an up-to-date file, if there is one, returns True, otherwise False
91+
If this group already has such a file, but its uuid is not up-to-date, then deletes it
92+
"""
93+
if os_path.isfile(f'csv_tables/{group_id}_{group_uuid}.csv'):
94+
return True
95+
return False

0 commit comments

Comments
 (0)