-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerators.py
More file actions
134 lines (115 loc) · 4.91 KB
/
generators.py
File metadata and controls
134 lines (115 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""Mock data generators for testing."""
import random
import string
from .utils import generate_verhoeff, generate_luhn_check_digit
class Generate:
"""Generate valid mock Indian document numbers."""
@staticmethod
def pan() -> str:
"""Generate valid PAN card number."""
prefix = "".join(random.choices(string.ascii_uppercase, k=3))
suffix = random.choice(string.ascii_uppercase)
digits = "".join(random.choices(string.digits, k=4))
return f"{prefix}P{random.choice(string.ascii_uppercase)}{digits}{suffix}"
@staticmethod
def tan() -> str:
"""Generates a random valid TAN number."""
first_four = "".join(random.choices(string.ascii_uppercase, k=4))
digits = "".join(random.choices(string.digits, k=5))
last_char = random.choice(string.ascii_uppercase)
return first_four + digits + last_char
@staticmethod
def dl() -> str:
"""Generates a random Indian Driving License number."""
state = random.choice(["MH", "DL", "KA", "UP", "TN", "GJ", "WB"])
rto = f"{random.randint(1, 99):02d}"
year = str(random.randint(1990, 2024))
number = "".join(random.choices(string.digits, k=7))
return state + rto + year + number
@staticmethod
def uan() -> str:
"""Generates a random valid UAN (12 digits)."""
return "100" + "".join(random.choices(string.digits, k=9))
@staticmethod
def abha(formatted: bool = True) -> str:
"""
Generates a random ABHA Health ID (14 digits).
If formatted is True, returns with standard hyphens (XX-XXXX-XXXX-XXXX).
"""
part1 = str(random.randint(11, 99))
part2 = "".join(random.choices(string.digits, k=4))
part3 = "".join(random.choices(string.digits, k=4))
part4 = "".join(random.choices(string.digits, k=4))
if formatted:
return f"{part1}-{part2}-{part3}-{part4}"
return part1 + part2 + part3 + part4
@staticmethod
def fssai() -> str:
"""Generates a random FSSAI License Number (14 digits)."""
first_digit = random.choice(["1", "2"])
state = f"{random.randint(1, 36):02d}"
rest = "".join(random.choices(string.digits, k=11))
return first_digit + state + rest
@staticmethod
def pran() -> str:
"""Generates a random PRAN for National Pension System (12 digits)."""
return "11" + "".join(random.choices(string.digits, k=10))
@staticmethod
def mobile() -> str:
"""Generate valid Indian mobile number."""
start = random.choice("6789")
rest = "".join(random.choices(string.digits, k=9))
return f"{start}{rest}"
@staticmethod
def vehicle() -> str:
"""Generate valid vehicle registration number."""
state = random.choice(["DL", "UP", "MH", "KA", "TN", "HR"])
dist = f"{random.randint(1, 99):02}"
series = "".join(random.choices(string.ascii_uppercase, k=2))
num = f"{random.randint(1, 9999):04}"
return f"{state}{dist}{series}{num}"
@staticmethod
def aadhaar() -> str:
"""Generate valid Aadhaar number with Verhoeff checksum."""
first = random.choice("23456789")
middle = "".join(random.choices(string.digits, k=10))
base_11 = first + middle
checksum = generate_verhoeff(base_11)
return base_11 + checksum
@staticmethod
def voterid() -> str:
"""Generate valid Voter ID (EPIC) number."""
letters = "".join(random.choices(string.ascii_uppercase, k=3))
digits = "".join(random.choices(string.digits, k=7))
return letters + digits
@staticmethod
def passport() -> str:
"""Generate valid Passport number."""
letter = random.choice(string.ascii_uppercase)
digits = "".join(random.choices(string.digits, k=7))
return letter + digits
@staticmethod
def cin() -> str:
"""Generate valid Corporate Identity Number."""
ownership = random.choice(["L", "U"])
industry = "".join(random.choices(string.digits, k=5))
state = "".join(random.choices(string.ascii_uppercase, k=2))
year = str(random.randint(2000, 2024))
type_code = random.choice(["PTC", "PLC", "OPC", "GOI"])
registration = "".join(random.choices(string.digits, k=6))
return f"{ownership}{industry}{state}{year}{type_code}{registration}"
@staticmethod
def pincode() -> str:
"""Generate valid Indian pincode."""
first = random.randint(1, 9)
rest = "".join(random.choices(string.digits, k=5))
return f"{first}{rest}"
@staticmethod
def credit_card() -> str:
"""
Generates a random, valid 16-digit credit card number.
Defaults to a Visa format (starts with 4).
"""
partial = "4" + "".join(random.choices(string.digits, k=14))
check_digit = generate_luhn_check_digit(partial)
return partial + check_digit