def test_create_subdomain_out_of_quota(flask_client): user = login(flask_client) sl_domain = setup_sl_domain() for i in range(MAX_NB_SUBDOMAIN): CustomDomain.create( domain=f"test{i}.{sl_domain.domain}", user_id=user.id, is_sl_subdomain=True, commit=True, ) assert CustomDomain.count() == MAX_NB_SUBDOMAIN flask_client.post( url_for("dashboard.subdomain_route"), data={ "form-name": "create", "subdomain": "test", "domain": sl_domain.domain }, follow_redirects=True, ) # no new subdomain is created assert CustomDomain.count() == MAX_NB_SUBDOMAIN
def test_create_subdomain_invalid(flask_client): login(flask_client) sl_domain = setup_sl_domain() # subdomain can't end with dash (-) flask_client.post( url_for("dashboard.subdomain_route"), data={ "form-name": "create", "subdomain": "test-", "domain": sl_domain.domain }, follow_redirects=True, ) assert CustomDomain.count() == 0 # subdomain can't contain underscore (_) flask_client.post( url_for("dashboard.subdomain_route"), data={ "form-name": "create", "subdomain": "test_test", "domain": sl_domain.domain, }, follow_redirects=True, ) assert CustomDomain.count() == 0 # subdomain must have at least 3 characters flask_client.post( url_for("dashboard.subdomain_route"), data={ "form-name": "create", "subdomain": "te", "domain": sl_domain.domain }, follow_redirects=True, ) assert CustomDomain.count() == 0