Repository: PrefectHQ/prefect

Issue:
Some blocks are missing code examples
### First check

- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the Prefect documentation for this issue.
- [X] I checked that this issue is related to Prefect and not one of its dependencies.

### Bug summary

Some of the blocks in the core library are missing code examples in the UI. For example, the Docker Container block:
![Screen Shot 2022-09-09 at 9 57 31 AM](https://user-images.githubusercontent.com/12350579/189380111-e12f0d5a-9fcc-4a9c-a2a5-141a5cf94025.png). Each block should have a code example that shows how a block can be loaded after configuration.


### Reproduction

```python
from prefect.infrastructure import DockerContainer

DockerContainer.get_code_example() # -> None
```


### Error

```

# Copy complete stack trace and error message here, including log output if applicable.

```


### Versions

```
Version:             2.3.2
API version:         0.8.0
Python version:      3.9.13
Git commit:          6e931ee9
Built:               Tue, Sep 6, 2022 12:36 PM
OS/Arch:             darwin/x86_64
Profile:             local
Server type:         ephemeral
Server:
  Database:          sqlite
  SQLite version:    3.39.2
```


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/src/prefect/blocks/core.py b/src/prefect/blocks/core.py
--- a/src/prefect/blocks/core.py
+++ b/src/prefect/blocks/core.py
@@ -36,6 +36,7 @@
 from prefect.utilities.collections import remove_nested_keys
 from prefect.utilities.dispatch import lookup_type, register_base_type
 from prefect.utilities.hashing import hash_objects
+from prefect.utilities.importtools import to_qualified_name
 
 if TYPE_CHECKING:
     from prefect.client import OrionClient
@@ -464,8 +465,30 @@ def get_code_example(cls) -> Optional[str]:
                         code_example = value.get("description")
                         break
 
+        if code_example is None:
+            # If no code example has been specified or extracted from the class
+            # docstring, generate a sensible default
+            code_example = cls._generate_code_example()
+
         return code_example
 
+    @classmethod
+    def _generate_code_example(cls) -> str:
+        """Generates a default code example for the current class"""
+        qualified_name = to_qualified_name(cls)
+        module_str = ".".join(qualified_name.split(".")[:-1])
+        class_name = cls.__name__
+        block_variable_name = f'{cls.get_block_type_slug().replace("-", "_")}_block'
+
+        return dedent(
+            f"""\
+        ```python
+        from {module_str} import {class_name}
+
+        {block_variable_name} = {class_name}.load("BLOCK_NAME")
+        ```"""
+        )
+
     @classmethod
     def _to_block_type(cls) -> BlockType:
         """


Test patch:
diff --git a/src/prefect/testing/standard_test_suites/blocks.py b/src/prefect/testing/standard_test_suites/blocks.py
--- a/src/prefect/testing/standard_test_suites/blocks.py
+++ b/src/prefect/testing/standard_test_suites/blocks.py
@@ -1,3 +1,4 @@
+import re
 from abc import ABC, abstractmethod
 from typing import Type
 
@@ -28,3 +29,15 @@ def test_all_fields_have_a_description(self, block: Type[Block]):
             assert field.field_info.description.endswith(
                 "."
             ), f"{name} description on {block.__name__} does not end with a period"
+
+    def test_has_a_valid_code_example(self, block: Type[Block]):
+        code_example = block.get_code_example()
+        assert code_example is not None, f"{block.__name__} is missing a code example"
+        import_pattern = rf"from .* import {block.__name__}"
+        assert (
+            re.search(import_pattern, code_example) is not None
+        ), f"The code example for {block.__name__} is missing an import statement matching the pattern {import_pattern}"
+        block_load_pattern = rf'.* = {block.__name__}\.load\("BLOCK_NAME"\)'
+        assert re.search(
+            block_load_pattern, code_example
+        ), f"The code example for {block.__name__} is missing a .load statement matching the pattern {block_load_pattern}"
diff --git a/tests/blocks/test_core.py b/tests/blocks/test_core.py
--- a/tests/blocks/test_core.py
+++ b/tests/blocks/test_core.py
@@ -1524,12 +1524,22 @@ class A(Block):
         assert A.get_description() == "But I will"
 
 
+class NoCodeExample(Block):
+    _block_type_name = "No code Example"
+
+    message: str
+
+
 class TestGetCodeExample:
     def test_no_code_example_configured(self):
-        class A(Block):
-            message: str
+        assert NoCodeExample.get_code_example() == dedent(
+            """\
+        ```python
+        from test_core import NoCodeExample
 
-        assert A.get_code_example() == None
+        no_code_example_block = NoCodeExample.load("BLOCK_NAME")
+        ```"""
+        )
 
     def test_code_example_from_docstring_example_heading(self, caplog):
         class A(Block):