Skip to content

Instantly share code, notes, and snippets.

@chareice
Created November 15, 2013 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chareice/7483854 to your computer and use it in GitHub Desktop.
Save chareice/7483854 to your computer and use it in GitHub Desktop.
Flask单元测试
import unittest
from flask.ext.testing import TestCase
from testconfig import TestConfig
from admin import app
from admin.urls import url_routes
from init_app import create_app
from extensions import db
def assertCreate(models):
models_arr = models.split(".")
model_p = __import__('%s.%s'%(models_arr[0],models_arr[1]), globals(), locals(), [models_arr[2]], -1)
model = getattr(model_p, models_arr[2])
form = model()
assert form
class FormsTestCase(TestCase):
def create_app(self):
return create_app(app=app, config=TestConfig, urls=url_routes)
def setUp(self):
pass
def tearDown(self):
pass
def testCreateGiveAwardForm(self):
assertCreate("forms.activity.GiveAwardForm")
def testCreateFirstChargeForm(self):
assertCreate("forms.analysis.FirstChargeForm")
def testCreateAddAdvertise(self):
assertCreate("forms.banner.AddAdvertise")
def testCreateAddImgForm(self):
assertCreate("forms.banner.AddImgForm")
def testCreateCardCardTypeAddForm(self):
assertCreate("forms.card.CardTypeAddForm")
def testCreateTonnnCardTypeAddForm(self):
assertCreate("forms.card.TonnnCardTypeAddForm")
def testCreateTonnnCardAddForm(self):
assertCreate("forms.card.TonnnCardAddForm")
def testCreateCardTypeAddForm(self):
assertCreate("forms.chargecard.CardTypeAddForm")
def testCreateTopicForm(self):
assertCreate("forms.forum.TopicForm")
def testCreateReplyForm(self):
assertCreate("forms.forum.ReplyForm")
def testCreateGameGameCompanyForm(self):
assertCreate("forms.game.GameCompanyForm")
def testCreateGameGameGiftForm(self):
assertCreate("forms.game.GameGiftForm")
def testCreateGameGameServerForm(self):
assertCreate("forms.game.GameServerForm")
def testCreateGameGame_apiForm(self):
assertCreate("forms.game.Game_apiForm")
def testCreateGameGameCategoryForm(self):
assertCreate("forms.game.GameCategoryForm")
def testCreateGameGameGameForm(self):
assertCreate("forms.game.GameGameForm")
def testCreateGameGameInternalUserAddForm(self):
assertCreate("forms.game.GameInternalUserAddForm")
def testCreateGameGameInternalUserEditForm(self):
assertCreate("forms.game.GameInternalUserEditForm")
def testCreateGiftAddCardGameForm(self):
assertCreate("forms.gift.AddCardGameForm")
def testCreateGiftAddCardSeralNoForm(self):
assertCreate("forms.gift.AddCardSeralNoForm")
def testCreateNewsNewsNewsForm(self):
assertCreate("forms.news.NewsNewsForm")
def testCreateNewsNewsCategoryForm(self):
assertCreate("forms.news.NewsCategoryForm")
def testCreateNewsOthers_flinkForm(self):
assertCreate("forms.news.Others_flinkForm")
def testCreatePaymentPayment_exchangeForm(self):
assertCreate("forms.payment.Payment_exchangeForm")
def testCreatePaymentPayment_apiconfForm(self):
assertCreate("forms.payment.Payment_apiconfForm")
def testCreatePaymentOrderForm(self):
assertCreate("forms.payment.OrderForm")
def testCreatePaymentCoinExchangeForm(self):
assertCreate("forms.payment.CoinExchangeForm")
def testCreatePaymentPaymentOrderForm(self):
assertCreate("forms.payment.PaymentOrderForm")
def testCreatePaymentPaymentOrdersupplyForm(self):
assertCreate("forms.payment.PaymentOrdersupplyForm")
def testCreatePaymentPresentFirstChargeForm(self):
assertCreate("forms.payment.PresentFirstChargeForm")
def testCreatePresentPresentApplyForm(self):
assertCreate("forms.present.PresentApplyForm")
def testCreatePromotionChannelWarningForm(self):
assertCreate("forms.promotion.ChannelWarningForm")
def testCreateQuestionAddQuestionForm(self):
assertCreate("forms.question.AddQuestionForm")
def testCreateQuestionEditQuestionForm(self):
#assert app
assertCreate("forms.question.EditQuestionForm")
def testCreateRoleLoginForm(self):
assertCreate("forms.role.LoginForm")
def testCreateUserLoginForm(self):
assertCreate("forms.user.LoginForm")
def testCreateUserRootLoginForm(self):
assertCreate("forms.user.RootLoginForm")
def testCreateUserSignupForm(self):
assertCreate("forms.user.SignupForm")
def testCreateUserQuickSignupForm(self):
assertCreate("forms.user.QuickSignupForm")
def testCreateUserProSignupForm(self):
assertCreate("forms.user.ProSignupForm")
def testCreateUserAccountInputForm(self):
assertCreate("forms.user.AccountInputForm")
def testCreateUserChangePasswd(self):
assertCreate("forms.user.ChangePasswd")
def testCreateUserResetpasswdForm(self):
assertCreate("forms.user.ResetpasswdForm")
def testCreateUserPasswdProtectForm(self):
assertCreate("forms.user.PasswdProtectForm")
def testCreateUserPasswdProtectChangeForm(self):
assertCreate("forms.user.PasswdProtectChangeForm")
def testCreateUserUserProfileForm(self):
assertCreate("forms.user.UserProfileForm")
def testCreateUserUserProfileUpdateForm(self):
assertCreate("forms.user.UserProfileUpdateForm")
def testCreateUserUserForm(self):
assertCreate("forms.user.UserForm")
def testCreateUserUserForm1(self):
assertCreate("forms.user.UserForm1")
def testCreateUserUserChangeForm(self):
assertCreate("forms.user.UserChangeForm")
def testCreateUserVipRankForm(self):
assertCreate("forms.user.VipRankForm")
def testCreateUserChangeFaceForm(self):
assertCreate("forms.user.ChangeFaceForm")
def testCreateUserCropImageForm(self):
assertCreate("forms.user.CropImageForm")
def testCreateUserAvoidIndulgeForm(self):
assertCreate("forms.user.AvoidIndulgeForm")
def suite():
suite = unittest.TestSuite()
suite.addTest(FormsTestCase("testCreateGiveAwardForm"))
suite.addTest(FormsTestCase("testCreateFirstChargeForm"))
suite.addTest(FormsTestCase("testCreateAddAdvertise"))
suite.addTest(FormsTestCase("testCreateAddImgForm"))
suite.addTest(FormsTestCase("testCreateCardCardTypeAddForm"))
suite.addTest(FormsTestCase("testCreateTonnnCardTypeAddForm"))
suite.addTest(FormsTestCase("testCreateTonnnCardAddForm"))
suite.addTest(FormsTestCase("testCreateCardTypeAddForm"))
suite.addTest(FormsTestCase("testCreateTopicForm"))
suite.addTest(FormsTestCase("testCreateReplyForm"))
suite.addTest(FormsTestCase("testCreateGameGameCompanyForm"))
suite.addTest(FormsTestCase("testCreateGameGameGiftForm"))
suite.addTest(FormsTestCase("testCreateGameGame_apiForm"))
suite.addTest(FormsTestCase("testCreateGameGameCategoryForm"))
suite.addTest(FormsTestCase("testCreateGameGameGameForm"))
suite.addTest(FormsTestCase("testCreateGameGameInternalUserAddForm"))
suite.addTest(FormsTestCase("testCreateGameGameInternalUserEditForm"))
suite.addTest(FormsTestCase("testCreateGiftAddCardGameForm"))
suite.addTest(FormsTestCase("testCreateGiftAddCardSeralNoForm"))
suite.addTest(FormsTestCase("testCreateNewsNewsNewsForm"))
suite.addTest(FormsTestCase("testCreateNewsNewsCategoryForm"))
suite.addTest(FormsTestCase("testCreateNewsOthers_flinkForm"))
suite.addTest(FormsTestCase("testCreatePaymentPayment_exchangeForm"))
suite.addTest(FormsTestCase("testCreatePaymentPayment_apiconfForm"))
suite.addTest(FormsTestCase("testCreatePaymentOrderForm"))
suite.addTest(FormsTestCase("testCreatePaymentCoinExchangeForm"))
suite.addTest(FormsTestCase("testCreatePaymentPaymentOrderForm"))
suite.addTest(FormsTestCase("testCreatePaymentPaymentOrdersupplyForm"))
suite.addTest(FormsTestCase("testCreatePaymentPresentFirstChargeForm"))
suite.addTest(FormsTestCase("testCreatePresentPresentApplyForm"))
suite.addTest(FormsTestCase("testCreatePromotionChannelWarningForm"))
suite.addTest(FormsTestCase("testCreateQuestionAddQuestionForm"))
suite.addTest(FormsTestCase("testCreateQuestionEditQuestionForm"))
suite.addTest(FormsTestCase("testCreateRoleLoginForm"))
suite.addTest(FormsTestCase("testCreateUserLoginForm"))
suite.addTest(FormsTestCase("testCreateUserRootLoginForm"))
suite.addTest(FormsTestCase("testCreateUserSignupForm"))
suite.addTest(FormsTestCase("testCreateUserQuickSignupForm"))
suite.addTest(FormsTestCase("testCreateUserProSignupForm"))
suite.addTest(FormsTestCase("testCreateUserAccountInputForm"))
suite.addTest(FormsTestCase("testCreateUserChangePasswd"))
suite.addTest(FormsTestCase("testCreateUserResetpasswdForm"))
suite.addTest(FormsTestCase("testCreateUserPasswdProtectForm"))
suite.addTest(FormsTestCase("testCreateUserPasswdProtectChangeForm"))
suite.addTest(FormsTestCase("testCreateUserUserProfileForm"))
suite.addTest(FormsTestCase("testCreateUserUserProfileUpdateForm"))
suite.addTest(FormsTestCase("testCreateUserUserForm"))
suite.addTest(FormsTestCase("testCreateUserUserForm1"))
suite.addTest(FormsTestCase("testCreateUserUserChangeForm"))
suite.addTest(FormsTestCase("testCreateUserVipRankForm"))
suite.addTest(FormsTestCase("testCreateUserChangeFaceForm"))
suite.addTest(FormsTestCase("testCreateUserCropImageForm"))
suite.addTest(FormsTestCase("testCreateUserAvoidIndulgeForm"))
return suite
if __name__ == "__main__":
unittest.main(defaultTest='suite')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment