def test_init_with_remote_resource_not_changed(self, mocker, patch_base_class, mock_api_client, local_configuration): mocker.patch.object( resources.BaseResource, "_get_state_from_file", mocker.Mock(return_value=mocker.Mock(configuration_hash="my_hash")) ) mocker.patch.object(resources.BaseResource, "_get_remote_resource", mocker.Mock(return_value={"resource_id": "my_resource_id"})) mocker.patch.object(resources, "hash_config", mocker.Mock(return_value="my_hash")) resource = resources.BaseResource(mock_api_client, "workspace_id", local_configuration, "bar.yaml") assert resource.was_created is True assert resource.local_file_changed is False assert resource.resource_id == resource.state.resource_id
def test_get_diff_with_remote_resource(self, patch_base_class, mocker, mock_api_client, local_configuration, was_created): mocker.patch.object(resources.BaseResource, "_get_remote_comparable_configuration") mocker.patch.object(resources.BaseResource, "was_created", was_created) resource = resources.BaseResource(mock_api_client, "workspace_id", local_configuration, "bar.yaml") mocker.patch.object(resources, "compute_diff") if was_created: diff = resource.get_diff_with_remote_resource() resources.compute_diff.assert_called_with(resource._get_remote_comparable_configuration.return_value, resource.configuration) assert diff == resources.compute_diff.return_value.pretty.return_value else: with pytest.raises(resources.NonExistingResourceError): resource.get_diff_with_remote_resource()
def test_init_no_remote_resource(self, mocker, patch_base_class, mock_api_client, local_configuration): mocker.patch.object(resources.BaseResource, "_get_state_from_file", mocker.Mock(return_value=None)) mocker.patch.object(resources, "hash_config") resource = resources.BaseResource(mock_api_client, "workspace_id", local_configuration, "bar.yaml") assert resource.APPLY_PRIORITY == 0 assert resource.workspace_id == "workspace_id" assert resource.raw_configuration == local_configuration assert resource.configuration_path == "bar.yaml" assert resource.api_instance == resource.api.return_value resource.api.assert_called_with(mock_api_client) assert resource.state == resource._get_state_from_file.return_value assert resource.remote_resource is None assert resource.was_created is False assert resource.local_file_changed is True assert resource.resource_id is None
def resource(self, patch_base_class, mock_api_client, local_configuration): return resources.BaseResource(mock_api_client, "workspace_id", local_configuration, "bar.yaml")