def test_run_delete(self, delete_mock):
     self.test_job.model = self.BuildTaskResult("banana",
                                                "delete",
                                                "active",
                                                "ban",
                                                "ana", {},
                                                image="image",
                                                auth="YmFuYTpuYQ==")
     smart_contract_model.new_from_build_task = MagicMock(
         return_value=self.test_job.model)
     contract_job.EVENT = '{"task_type": "delete"}'
     contract_job.main()
     delete_mock.assert_called()
 def test_main_create(self):
     self.test_job.model = self.BuildTaskResult("banana",
                                                "create",
                                                "active",
                                                "ban",
                                                "ana", {},
                                                image="image",
                                                auth="YmFuYTpuYQ==")
     self.test_job.model.save = MagicMock()
     smart_contract_model.new_from_build_task = MagicMock(
         return_value=self.test_job.model)
     contract_job.EVENT = '{"task_type": "create"}'
     contract_job.ContractJob.create = MagicMock()
     contract_job.main()
     contract_job.ContractJob.create.assert_called()
    def test_main_pass_does_update_model(self, mock_docker, mock_login,
                                         mock_ecr, mock_secrets):
        contract_job.EVENT = '{"txn_type": "test", "task_type": "update", "id": "123", "start_state": "inactive", "auth": "auth", "image": "image", "cmd": "cmd", "args": "[one]", "secrets": "{}", "existing_secrets": "[]", "env": "{}", "cron": "None", "seconds": "30",  "execution_order": "serial", "desired_state": "active"}'  # noqa: B950
        self.test_job.model = self.BuildTaskResultWithHelpers(
            "banana",
            "create",
            "inactive",
            "ban",
            "ana", {},
            image="image",
            auth="YmFuYTpuYQ==")
        self.test_job.update_model = self.BuildTaskResultWithHelpers(
            "banana",
            "create",
            "active",
            "banana",
            "ana", {},
            image="new/image",
            auth="YmFuYTpuYQ=!")
        self.test_job.model.update_faas_fields(
            update_model=self.test_job.update_model)
        self.test_job.update_model.update_faas_fields(
            update_model=self.test_job.update_model)
        smart_contract_dao.get_contract_by_txn_type = MagicMock(
            return_value=self.test_job.model)
        smart_contract_model.new_from_build_task = MagicMock(
            return_value=self.test_job.update_model)
        contract_job.ContractJob.create_dockerfile = MagicMock()
        contract_job.ContractJob.create_openfaas_secrets = MagicMock()
        contract_job.ContractJob.delete_contract_image = MagicMock()
        contract_job.ContractJob.deploy_to_openfaas = MagicMock()
        contract_job.ContractJob.pull_image = MagicMock()
        contract_job.ContractJob.schedule_contract = MagicMock()
        mock_docker.from_env = MagicMock()
        mock_docker.images.push = MagicMock()
        mock_docker.images.get = MagicMock()

        try:
            job = contract_job.main()
            self.assertEqual(job.model.image, "new/image")
            self.assertEqual(job.update_model.image, "new/image")
            self.assertEqual(job.model.cmd, "banana")
            self.assertEqual(job.model.status["state"], "active")
            job.model.save.assert_called()
        except Exception:
            self.fail("should not have thrown a generic exception!")