pydantic / pydantic-extra-types

Extra Pydantic types.
MIT License
195 stars 51 forks source link

chore(feat): Add ABARouting number type #30

Closed RevinderDev closed 1 year ago

RevinderDev commented 1 year ago

Hi!

I am new here so apologies in advance if I had done something out of order. This PR is proposed ABARouting number for US based banks validation. One could use it like so:

import pytest

from pydantic import BaseModel, ValidationError
from pydantic_extra_types import ABARoutingNumber

class Bank(BaseModel):
    routing_number: ABARoutingNumber
    name: str

example = [
    {"name": "US Bank Arizona", "routing_number": "122105155"},
    {"name": "US Bank California, Southern", "routing_number": "122235821"},
    {"name": "US Bank Idaho", "routing_number": "123103729"},
    {"name": "US Evil Bank Inc.", "routing_number": "123103721"},
]

assert Bank(**example[0]).routing_number == "122105155"
assert Bank(**example[1]).routing_number == "122235821"
assert Bank(**example[2]).routing_number == "123103729"
with pytest.raises(ValidationError):
    Bank(**example[3])

As a sidenote, I wanted to try and tackle opened https://github.com/pydantic/pydantic-extra-types/issues/10 but I am not sure if @HomiGrotas is still progressing on that one or not.

HomiGrotas commented 1 year ago

Hi @RevinderDev :) I needed CountryCode PR (#14) approved to continue with the next chore. Now when it's approved, I'm working on #10

RevinderDev commented 1 year ago

I thought about it and decided against routing.py when creating that PR. The reason is that in IT, if I see routing.py / routing module, I'm thinking either API routes, or something to do with physical routers.

ABARoutingNumber is a thing only for banking (US banking specifically), therefore I named it bank.py with intention of that file having IBAN as well later on.

Alternatively, maybe there could be banking / banks module that has a file routing.py? Full path could look like this: pydantic-extra-types/types/banking/routing.py.

Or 3rd choice - routing_number.py?

Either way, I don't wanna push for my naming, so choice is yours :). LMK which one you want

yezz123 commented 1 year ago

routing_number.py

routing_number.py looks great!

RevinderDev commented 1 year ago

routing_number.py it is then:)