Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: DBPT-1519 Refactor codebase command and tests #618

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

chiaramapellimt
Copy link
Contributor

@chiaramapellimt chiaramapellimt commented Nov 4, 2024

Addresses DBTP-1519

Please add any relevant context for you pull request here, or delete this if none needed.


Checklist:

Title:

  • Scope included as per conventional commits
  • Ticket reference included (unless it's a quick out of ticket thing)

Description:

  • Link to ticket included (unless it's a quick out of ticket thing)
  • Includes tests (or an explanation for why it doesn't)
  • If the work includes user interface changes, before and after screenshots included in description
  • Includes any applicable changes to the documentation in this code base
  • Includes link(s) to any applicable changes to the documentation in the DBT Platform Documentation (can be to a pull request)

Tasks:

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
596 1 595 0
View the top 1 failed tests by shortest run time
tests/platform_helper/domain/test_codebase.py::test_codebase_prepare_generates_the_expected_files
Stack Traces | 0.026s run time
.../platform_helper/domain/test_codebase.py:117: in test_codebase_prepare_generates_the_expected_files
    assert is_same_files(compare_directories) is True
E   assert False is True
E    +  where False = is_same_files(<filecmp.dircmp object at 0x7f498f2724b0>)

To view more test analytics, go to the Test Analytics Dashboard
Got feedback? Let us know on Github

@chiaramapellimt chiaramapellimt changed the title refactor: DBPT-1519-Extracting class from codebase.py refactor: DBPT-1519-Refactoring codebase.py Nov 7, 2024
@chiaramapellimt chiaramapellimt changed the title refactor: DBPT-1519-Refactoring codebase.py refactor: DBPT-1519-Refactoring codebase tests and commands Nov 7, 2024
repository=repository, builder_version=builder_version
)

self.echo_fn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about if we ever had click (echo) functionality at command level, would these domain class commands require split up between echo's to support "echoing" progress

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i dont get this can you explain this a bit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, we can ignore my comment.
What I was thinking at the time was that the click functionality should be at the command layer but as you call it here would you need to split the function up if you were to move the echo to the command layer.
Although this does not matter as techinically self.echo_fn could be any logging function it could be strout but also anything else too.

@WillGibson WillGibson changed the title refactor: DBPT-1519-Refactoring codebase tests and commands refactor: DBPT-1519 Refactoring codebase tests and commands Nov 12, 2024
@WillGibson WillGibson changed the title refactor: DBPT-1519 Refactoring codebase tests and commands refactor: DBPT-1519 Refactor codebase command and tests Nov 12, 2024
pytest.ini Outdated Show resolved Hide resolved
@@ -420,3 +420,78 @@ def get_vpc_info_by_name(session: Session, app: str, env: str, vpc_name: str) ->
raise AWSException(f"No matching security groups found in vpc '{vpc_name}'")

return Vpc(subnets, sec_groups)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to be a pain but do you thinking adding theese functions to a new providers/aws would split this logic from the old utilis?

}


@patch("requests.get")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe overkill but is it possible to also inject requests like subprocess meaning you can mock this instead of patching?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only use it one place at the moment and it's a standard library so probably not great to add yet another 'injectable' argument to the class

dbt_platform_helper/commands/codebase.py Show resolved Hide resolved
)
@patch("dbt_platform_helper.commands.codebase.Codebase")
def test_codebase_prepare_calls_codebase_prepare_method(self, mock_codebase_object):
mock_codebase_object_instance = mock_codebase_object.return_value

result = CliRunner().invoke(prepare)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will no longer be confused by this once the codebase command method has been renamed.

Suggested change
result = CliRunner().invoke(prepare)
result = CliRunner().invoke(codebase)

It looked to me like we were asserting that the method we just invoked has been called.

)
assert result.exit_code == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this behaviour the responsibility of domain.Codebase now?

So all we would want to be testing here is that domain.Codebase.build was called with the correct arguments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants