Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/faker/providers/ssn/en_US/__init__.py: 18%

52 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1from typing import List 

2 

3from .. import Provider as BaseProvider 

4 

5 

6class Provider(BaseProvider): 

7 INVALID_SSN_TYPE = "INVALID_SSN" 

8 SSN_TYPE = "SSN" 

9 ITIN_TYPE = "ITIN" 

10 EIN_TYPE = "EIN" 

11 

12 def itin(self) -> str: 

13 """Generate a random United States Individual Taxpayer Identification Number (ITIN). 

14 

15 An United States Individual Taxpayer Identification Number 

16 (ITIN) is a tax processing number issued by the Internal 

17 Revenue Service. It is a nine-digit number that always begins 

18 with the number 9 and has a range of 70-88 in the fourth and 

19 fifth digit. Effective April 12, 2011, the range was extended 

20 to include 900-70-0000 through 999-88-9999, 900-90-0000 

21 through 999-92-9999 and 900-94-0000 through 999-99-9999. 

22 https://www.irs.gov/individuals/international-taxpayers/general-itin-information 

23 """ 

24 

25 area = self.random_int(min=900, max=999) 

26 serial = self.random_int(min=0, max=9999) 

27 

28 # The group number must be between 70 and 99 inclusively but not 89 or 93 

29 group: int = self.random_element([x for x in range(70, 100) if x not in [89, 93]]) 

30 

31 itin = f"{area:03d}-{group:02d}-{serial:04d}" 

32 return itin 

33 

34 def ein(self) -> str: 

35 """Generate a random United States Employer Identification Number (EIN). 

36 

37 An United States An Employer Identification Number (EIN) is 

38 also known as a Federal Tax Identification Number, and is 

39 used to identify a business entity. EINs follow a format of a 

40 two-digit prefix followed by a hyphen and a seven-digit sequence: 

41 ##-###### 

42 

43 https://www.irs.gov/businesses/small-businesses-self-employed/employer-id-numbers 

44 """ 

45 

46 # Only certain EIN Prefix values are assigned: 

47 # 

48 # https://www.irs.gov/businesses/small-businesses-self-employed/how-eins-are-assigned-and-valid-ein-prefixes 

49 

50 ein_prefix_choices: List[str] = [ 

51 "01", 

52 "02", 

53 "03", 

54 "04", 

55 "05", 

56 "06", 

57 "10", 

58 "11", 

59 "12", 

60 "13", 

61 "14", 

62 "15", 

63 "16", 

64 "20", 

65 "21", 

66 "22", 

67 "23", 

68 "24", 

69 "25", 

70 "26", 

71 "27", 

72 "30", 

73 "31", 

74 "32", 

75 "33", 

76 "34", 

77 "35", 

78 "36", 

79 "37", 

80 "38", 

81 "39", 

82 "40", 

83 "41", 

84 "42", 

85 "43", 

86 "44", 

87 "45", 

88 "46", 

89 "47", 

90 "48", 

91 "50", 

92 "51", 

93 "52", 

94 "53", 

95 "54", 

96 "55", 

97 "56", 

98 "57", 

99 "58", 

100 "59", 

101 "60", 

102 "61", 

103 "62", 

104 "63", 

105 "64", 

106 "65", 

107 "66", 

108 "67", 

109 "68", 

110 "71", 

111 "72", 

112 "73", 

113 "74", 

114 "75", 

115 "76", 

116 "77", 

117 "80", 

118 "81", 

119 "82", 

120 "83", 

121 "84", 

122 "85", 

123 "86", 

124 "87", 

125 "88", 

126 "90", 

127 "91", 

128 "92", 

129 "93", 

130 "94", 

131 "95", 

132 "98", 

133 "99", 

134 ] 

135 

136 ein_prefix: str = self.random_element(ein_prefix_choices) 

137 sequence = self.random_int(min=0, max=9999999) 

138 

139 ein = f"{ein_prefix:s}-{sequence:07d}" 

140 return ein 

141 

142 def invalid_ssn(self) -> str: 

143 """Generate a random invalid United States Social Security Identification Number (SSN). 

144 

145 Invalid SSNs have the following characteristics: 

146 Cannot begin with the number 9 

147 Cannot begin with 666 in positions 1 - 3 

148 Cannot begin with 000 in positions 1 - 3 

149 Cannot contain 00 in positions 4 - 5 

150 Cannot contain 0000 in positions 6 - 9 

151 

152 https://www.ssa.gov/kc/SSAFactSheet--IssuingSSNs.pdf 

153 

154 Additionally, return an invalid SSN that is NOT a valid ITIN by excluding certain ITIN related "group" values 

155 """ 

156 itin_group_numbers = [ 

157 70, 

158 71, 

159 72, 

160 73, 

161 74, 

162 75, 

163 76, 

164 77, 

165 78, 

166 79, 

167 80, 

168 81, 

169 82, 

170 83, 

171 84, 

172 85, 

173 86, 

174 87, 

175 88, 

176 90, 

177 91, 

178 92, 

179 94, 

180 95, 

181 96, 

182 97, 

183 98, 

184 99, 

185 ] 

186 area = self.random_int(min=0, max=999) 

187 if area < 900 and area not in {666, 0}: 

188 random_group_or_serial = self.random_int(min=1, max=1000) 

189 if random_group_or_serial <= 500: 

190 group = 0 

191 serial = self.random_int(0, 9999) 

192 else: 

193 group = self.random_int(0, 99) 

194 serial = 0 

195 elif area in {666, 0}: 

196 group = self.random_int(0, 99) 

197 serial = self.random_int(0, 9999) 

198 else: 

199 group = self.random_element([x for x in range(0, 100) if x not in itin_group_numbers]) 

200 serial = self.random_int(0, 9999) 

201 

202 invalid_ssn = f"{area:03d}-{group:02d}-{serial:04d}" 

203 return invalid_ssn 

204 

205 def ssn(self, taxpayer_identification_number_type: str = SSN_TYPE) -> str: 

206 """Generate a random United States Taxpayer Identification Number of the specified type. 

207 

208 If no type is specified, a US SSN is returned. 

209 """ 

210 

211 if taxpayer_identification_number_type == self.ITIN_TYPE: 

212 return self.itin() 

213 elif taxpayer_identification_number_type == self.EIN_TYPE: 

214 return self.ein() 

215 elif taxpayer_identification_number_type == self.INVALID_SSN_TYPE: 

216 return self.invalid_ssn() 

217 elif taxpayer_identification_number_type == self.SSN_TYPE: 

218 

219 # Certain numbers are invalid for United States Social Security 

220 # Numbers. The area (first 3 digits) cannot be 666 or 900-999. 

221 # The group number (middle digits) cannot be 00. The serial 

222 # (last 4 digits) cannot be 0000. 

223 

224 area = self.random_int(min=1, max=899) 

225 if area == 666: 

226 area += 1 

227 group = self.random_int(1, 99) 

228 serial = self.random_int(1, 9999) 

229 

230 ssn = f"{area:03d}-{group:02d}-{serial:04d}" 

231 return ssn 

232 

233 else: 

234 raise ValueError( 

235 "taxpayer_identification_number_type must be one of 'SSN', 'EIN', 'ITIN'," " or 'INVALID_SSN'." 

236 )