Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d65b022d

Přidáno uživatelem David Friesecký před asi 4 roky(ů)

Re #8578 - Cover private_key_repository tests
- created tests for functions create, read, read_all, update, delete
- (+) edited certificate_repository to the same stylistics

Zobrazit rozdíly:

src/dao/certificate_repository.py
1 1
from typing import Dict, List
2 2
from sqlite3 import Connection, Cursor, Error
3 3

  
4
from src.exceptions.database_exception import DatabaseException
4 5
from src.model.certificate import Certificate
5 6
from src.constants import *
6 7

  
......
70 71
                        self.cursor.execute(sql, values)
71 72
                        self.connection.commit()
72 73
        except Error as e:
73
            return e
74
            raise DatabaseException(e)
74 75

  
75 76
        return last_id
76 77

  
......
114 115
                                                   certificate_row[5],
115 116
                                                   certificate_row[6])
116 117
        except Error as e:
117
            return e
118
            raise DatabaseException(e)
118 119

  
119
        if len(certificate_row) > 0:
120
            return certificate
121
        else:
122
            return None
120
        return certificate
123 121

  
124 122
    def read_all(self, filter_type: int = None):
125 123
        """
......
166 164
                                                certificate_row[5],
167 165
                                                certificate_row[6]))
168 166
        except Error as e:
169
            return e
167
            raise DatabaseException(e)
170 168

  
171
        if len(certificates) > 0:
172
            return certificates
173
        else:
174
            return None
169
        return certificates
175 170

  
176 171
    def update(self, certificate_id: int, certificate: Certificate):
177 172
        """
......
228 223
                    self.cursor.execute(sql, values)
229 224
                    self.connection.commit()
230 225
        except Error as e:
231
            return e
226
            raise DatabaseException(e)
232 227

  
233
        if self.cursor.rowcount > 0:
234
            return True
235

  
236
        return False
228
        return self.cursor.rowcount > 0
237 229

  
238 230
    def delete(self, certificate_id: int):
239 231
        """
......
251 243
            self.cursor.execute(sql, values)
252 244
            self.connection.commit()
253 245
        except Error as e:
254
            return e
246
            raise DatabaseException(e)
255 247

  
256 248
        return self.cursor.rowcount > 0
257 249

  
......
285 277
            self.cursor.execute(sql, values)
286 278
            self.connection.commit()
287 279
        except Error as e:
288
            return e
289

  
290
        if self.cursor.rowcount > 0:
291
            return True
280
            raise DatabaseException(e)
292 281

  
293
        return False
282
        return self.cursor.rowcount > 0
294 283

  
295 284
    def clear_certificate_revocation(self, certificate_id: int):
296 285
        """
......
312 301
            self.cursor.execute(sql, values)
313 302
            self.connection.commit()
314 303
        except Error as e:
315
            return e
304
            raise DatabaseException(e)
316 305

  
317
        return True
306
        return self.cursor.rowcount > 0
318 307

  
319 308
    def get_all_revoked_by(self, certificate_id: int):
320 309
        """
......
359 348
                                                certificate_row[5],
360 349
                                                certificate_row[6]))
361 350
        except Error as e:
362
            return e
351
            raise DatabaseException(e)
363 352

  
364
        if len(certificates) > 0:
365
            return certificates
366
        else:
367
            return None
353
        return certificates
368 354

  
369 355
    def get_all_issued_by(self, certificate_id: int):
370 356
        """
......
409 395
                                                certificate_row[5],
410 396
                                                certificate_row[6]))
411 397
        except Error as e:
412
            return e
398
            raise DatabaseException(e)
413 399

  
414
        if len(certificates) > 0:
415
            return certificates
416
        else:
417
            return None
400
        return certificates

Také k dispozici: Unified diff