async def test_validate_attr_EMAIL_allowed_domains_email(): attr_val = await validate_attr( attr_name='test_validate_attr_EMAIL', attr_type=ATTR.EMAIL(allowed_domains=['foo.com', 'bar.net']), attr_val='*****@*****.**', mode='create', ) assert attr_val == '*****@*****.**'
async def test_validate_attr_EMAIL_disallowed_domains_email_invalid(): with pytest.raises(InvalidAttrException): await validate_attr( attr_name='test_validate_attr_EMAIL', attr_type=ATTR.EMAIL(disallowed_domains=['foo.com', 'bar.net']), attr_val='*****@*****.**', mode='create', )
async def test_validate_attr_EMAIL_None_allow_none(): attr_val = await validate_attr( attr_name='test_validate_attr_EMAIL', attr_type=ATTR.EMAIL(), attr_val=None, mode='update', ) assert attr_val == None
async def test_validate_attr_EMAIL_None(): with pytest.raises(InvalidAttrException): await validate_attr( attr_name='test_validate_attr_EMAIL', attr_type=ATTR.EMAIL(), attr_val=None, mode='create', )
async def test_validate_attr_EMAIL_email(): attr_val = await validate_attr( attr_name='test_validate_attr_EMAIL', attr_type=ATTR.EMAIL(), attr_val='*****@*****.**', mode='create', ) assert attr_val == '*****@*****.**'
async def test_validate_attr_EMAIL_allowed_domains_strict_email_invalid(): with pytest.raises(InvalidAttrException): await validate_attr( attr_name='test_validate_attr_EMAIL', attr_type=ATTR.EMAIL(allowed_domains=['foo.com', 'bar.net'], strict=True), attr_val='*****@*****.**', mode='create', )
async def test_validate_attr_LIST_muti_list_invalid(): with pytest.raises(InvalidAttrException): await validate_attr( attr_name='test_validate_attr_LIST', attr_type=ATTR.LIST( list=[ATTR.EMAIL(), ATTR.URI_WEB()]), attr_val=['*****@*****.**', 'http://sub.example.com', '1'], mode='create', )
async def test_validate_attr_EMAIL_default_int_allow_none(): attr_type = ATTR.EMAIL() attr_type._default = 'test_validate_attr_EMAIL' attr_val = await validate_attr( attr_name='test_validate_attr_EMAIL', attr_type=attr_type, attr_val=1, mode='update', ) assert attr_val == None
async def test_validate_attr_EMAIL_default_None(): attr_type = ATTR.EMAIL() attr_type._default = 'test_validate_attr_EMAIL' attr_val = await validate_attr( attr_name='test_validate_attr_EMAIL', attr_type=attr_type, attr_val=None, mode='create', ) assert attr_val == 'test_validate_attr_EMAIL'
async def test_validate_attr_LIST_typed_dict(): list_attr_val = [ '*****@*****.**', 'http://sub.example.com', 'https://sub.domain.com', ] attr_val = await validate_attr( attr_name='test_validate_attr_LIST', attr_type=ATTR.LIST(list=[ATTR.EMAIL(), ATTR.URI_WEB()], min=1, max=3), attr_val=list_attr_val, mode='create', ) assert attr_val == list_attr_val
version='1.0.0', gateways={ 'mailgun_messages': mailgun_messages_gateway, 'mailgun_newsletters': mailgun_newsletters_gateway, }, vars_types={ 'mailgun': ATTR.TYPED_DICT( dict={ 'key': ATTR.STR(), 'newsletters': ATTR.KV_DICT(key=ATTR.STR(), val=ATTR.STR()), 'senders': ATTR.KV_DICT( key=ATTR.STR(), val=ATTR.TYPED_DICT( dict={ 'uri': ATTR.URI_WEB(allowed_domains=['api.mailgun.net'], strict=True), 'sender_name': ATTR.STR(), 'sender_email': ATTR.EMAIL(), }), ), }) }, )
def test_generate_attr_EMAIL_allowed_domains_strict(): attr_val = utils.generate_attr(attr_type=ATTR.EMAIL( allowed_domains=['foo.com', 'bar.net', 'baz.ae'], strict=True)) assert attr_val.endswith('@foo.com') or attr_val.endswith( '@bar.net') or attr_val.endswith('@baz.ae')
def test_generate_attr_EMAIL_allowed_domains(): attr_val = utils.generate_attr(attr_type=ATTR.EMAIL( allowed_domains=['foo.com', 'bar.net', 'baz.ae'])) assert attr_val.endswith('@mail.foo.com') or attr_val.endswith( '@mail.bar.net') or attr_val.endswith('@mail.baz.ae')
def test_generate_attr_EMAIL_no_args(): attr_val = utils.generate_attr(attr_type=ATTR.EMAIL()) assert re.match(r'^[^@]+@[^@]+\.[^@]+$', attr_val) != None
# Use this App Config Attr to set debug mode based on existence of environment variable DEBUG # debug='$__env.DEBUG', data_server='__PROD_DATA_SERVER__', # Use this App Config Attr to force use of SSL connection data_ssl=True, ), }, # define name of the database for your app data_name='__DATA_NAME__', # Define app locales in the form of language_COUNTRY locales=['__LOCALES__'], # Define app default locale, which is the required value for LOCALE Attr Type locale='__LOCALE__', # Define user attrs, these are unique attributes per user that can be used to authenticate the user user_attrs={ 'email': ATTR.EMAIL(), # 'username': ATTR.STR(), # 'phone': ATTR.PHONE(), }, # Define user_settings, these are user-specific settings that are created with Setting module, in order to give access to users to these settings without breaching User module security model # user_settings={ # # If you define a user_settings item with type: user, it means user has ability to change its value using setting/update call # # If you define a user_settings item with default: NAWAH_VALUES.NONE_VALUE, it means this settings attr requires a value at time of creating user. Notice that we had to supply a value for ADMIN doc to avoid breaking Nawah app launch # 'age': { # 'type': 'user', # 'val_type': ATTR.INT(ranges=[[18, 121]]), # 'default': NAWAH_VALUES.NONE_VALUE, # }, # # If you would like to have a default value so that if user/create call doesn't fail for not specifying a value, you can set a matching default value # 'bio': { # 'type': 'user',