1. 程式人生 > >只想寫一個真正能用的django mock

只想寫一個真正能用的django mock

urn env list hello amp obj action UNC creat

調參數的過程,百轉千回。

還好,搞得差不多了。

確實,方便寫測試用例,

也是一個開發水平高低的衡量~~~:(

為了測試這個mock,不得不改下代碼~~

還要不斷的將Model裏允許Null的參數寫完,

不然,報錯呀~~~

model_mommy,喲,不錯的寫測試數據的東東。

class DeployFunctionTests(TestCase):
    def setUp(self):
        self.user = User.objects.create_user(
            username=test,
            email
=[email protected], password=test,) self.client.login(username=test, password=test) self.new_server = mommy.make(Server, env_name__name=‘fat‘, app_name__script_url="http://", app_user=self.user, app_name__name="hello", app_name__zip_package_name="heh", app_name__package_name="heh", port="3456"
, ) self.new_deploy = mommy.make(DeployPool, name="2018--12-24-56XN", is_inc_tot=tot) DeployStatus.objects.create(name="FINISH", memo="FINISH") @patch(deploy.salt_cmd_views.cmd_run) def test_deploy_function(self, mock_cmd_run): mock_cmd_run.return_value
= True self.assertEqual(deploy.salt_cmd_views.deploy( subserver_list=[[1, 2, 3], [4, 5, 6]], deploy_type="deployall", is_restart_server=True, user_name=self.user, deploy_version="2018--12-24-56XN", operation_type="deploy" ), True) @patch(deploy.salt_cmd_views.salt_run) def test_cmd_run_function(self, mock_salt_run): mock_salt_run.return_value = {return: [{self.new_server.name: {retcode: 0}}]} self.assertEqual(deploy.salt_cmd_views.cmd_run( server_id=self.new_server.id, action="deploy", user_name=self.user, percent_value="100%", deploy_version="2018--12-24-56XN", operation_type="deploy"), True)

只想寫一個真正能用的django mock