Coverage for functions \ flipdare \ util \ code_generator.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

3# 

4# This file is part of Flipdare's proprietary software and contains 

5# confidential and copyrighted material. Unauthorised copying, 

6# modification, distribution, or use of this file is strictly 

7# prohibited without prior written permission from Flipdare Pty Ltd. 

8# 

9# This software includes third-party components licensed under MIT, 

10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

11# 

12 

13 

14import secrets 

15from typing import Any 

16 

17from flipdare.core.singleton import Singleton 

18 

19__all__ = ["CodeGenerator"] 

20 

21 

22class CodeGenerator(Singleton): 

23 

24 def __init__(self, rnd: secrets.SystemRandom | None = None, *args: Any, **kwargs: Any) -> None: 

25 super().__init__(*args, **kwargs) 

26 if rnd is None: 

27 rnd = secrets.SystemRandom() 

28 self._rnd = rnd 

29 

30 @property 

31 def rnd(self) -> secrets.SystemRandom: 

32 return self._rnd 

33 

34 def temp_password(self) -> str: 

35 return self._generate_code(10000000, 99999999) 

36 

37 def signup_code(self) -> str: 

38 return self._generate_code() 

39 

40 def delete_code(self) -> str: 

41 return self._generate_code(100000, 999999) 

42 

43 def _generate_code(self, min_value: int = 1000, max_value: int = 9999) -> str: 

44 return str(self.rnd.randint(min_value, max_value))