Revize d65b022d
Přidáno uživatelem David Friesecký před asi 4 roky(ů)
src/dao/private_key_repository.py | ||
---|---|---|
1 | 1 |
from sqlite3 import Connection, Cursor, Error |
2 | 2 |
from typing import List |
3 | 3 |
|
4 |
from src.exceptions.database_exception import DatabaseException |
|
4 | 5 |
from src.model.private_key import PrivateKey |
5 | 6 |
from src.constants import * |
6 | 7 |
|
... | ... | |
38 | 39 |
last_id = self.cursor.lastrowid |
39 | 40 |
self.connection.commit() |
40 | 41 |
except Error as e: |
41 |
print(e) |
|
42 |
return None |
|
42 |
raise DatabaseException(e) |
|
43 | 43 |
|
44 | 44 |
return last_id |
45 | 45 |
|
... | ... | |
59 | 59 |
self.cursor.execute(sql, values) |
60 | 60 |
private_key_row = self.cursor.fetchone() |
61 | 61 |
|
62 |
if private_key_row is None: |
|
63 |
return None |
|
64 |
|
|
62 | 65 |
private_key: PrivateKey = PrivateKey(private_key_row[0], |
63 | 66 |
private_key_row[1], |
64 | 67 |
private_key_row[2]) |
65 | 68 |
except Error as e: |
66 |
print(e) |
|
67 |
return None |
|
69 |
raise DatabaseException(e) |
|
68 | 70 |
|
69 |
if len(private_key_row) > 0: |
|
70 |
return private_key |
|
71 |
else: |
|
72 |
return None |
|
71 |
return private_key |
|
73 | 72 |
|
74 | 73 |
def read_all(self): |
75 | 74 |
""" |
... | ... | |
89 | 88 |
private_key_row[1], |
90 | 89 |
private_key_row[2])) |
91 | 90 |
except Error as e: |
92 |
print(e) |
|
93 |
return None |
|
91 |
raise DatabaseException(e) |
|
94 | 92 |
|
95 |
if len(private_keys) > 0: |
|
96 |
return private_keys |
|
97 |
else: |
|
98 |
return None |
|
93 |
return private_keys |
|
99 | 94 |
|
100 | 95 |
def update(self, private_key_id: int, private_key: PrivateKey) -> bool: |
101 | 96 |
""" |
... | ... | |
118 | 113 |
self.cursor.execute(sql, values) |
119 | 114 |
self.connection.commit() |
120 | 115 |
except Error as e: |
121 |
print(e) |
|
122 |
return False |
|
116 |
raise DatabaseException(e) |
|
123 | 117 |
|
124 |
return True
|
|
118 |
return self.cursor.rowcount > 0
|
|
125 | 119 |
|
126 | 120 |
def delete(self, private_key_id: int) -> bool: |
127 | 121 |
""" |
... | ... | |
139 | 133 |
self.cursor.execute(sql, values) |
140 | 134 |
self.connection.commit() |
141 | 135 |
except Error as e: |
142 |
print(e) |
|
143 |
return False |
|
136 |
raise DatabaseException |
|
144 | 137 |
|
145 | 138 |
return self.cursor.rowcount > 0 |
Také k dispozici: Unified diff
Re #8578 - Cover private_key_repository tests
- created tests for functions create, read, read_all, update, delete
- (+) edited certificate_repository to the same stylistics