forked from datacontract/datacontract-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First support for server-specific types in a config map.
Resolves datacontract#150
- Loading branch information
1 parent
49814f7
commit 96bf6e6
Showing
7 changed files
with
40 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,47 @@ | ||
import os | ||
|
||
import requests | ||
from typer.testing import CliRunner | ||
|
||
from datacontract.cli import app | ||
|
||
runner = CliRunner() | ||
_datacontract_test_path = "./.tmp/datacontract.yaml" | ||
_default_template_url = "https://datacontract.com/datacontract.init.yaml" | ||
_custom_template_url = "https://studio.datacontract.com/s/ef47b7ea-879c-48d5-adf4-aa68b000b00f.yaml" | ||
|
||
|
||
def test_download_datacontract_file_with_defaults(): | ||
_setup() | ||
|
||
runner.invoke(app, ["init", _datacontract_test_path]) | ||
|
||
_compare_test_datacontract_with(_default_template_url) | ||
|
||
|
||
def test_download_datacontract_file_from_custom_url(): | ||
_setup() | ||
def test_download_datacontract_file_with_defaults(tmp_path): | ||
datacontract_test_path = tmp_path / "datacontract.yaml" | ||
runner.invoke(app, ["init", str(datacontract_test_path)]) | ||
_compare_test_datacontract_with(str(datacontract_test_path), _default_template_url) | ||
|
||
runner.invoke(app, ["init", _datacontract_test_path, "--template", _custom_template_url]) | ||
|
||
_compare_test_datacontract_with(_custom_template_url) | ||
def test_download_datacontract_file_from_custom_url(tmp_path): | ||
datacontract_test_path = tmp_path / "datacontract.yaml" | ||
runner.invoke(app, ["init", str(datacontract_test_path), "--template", _custom_template_url]) | ||
_compare_test_datacontract_with(str(datacontract_test_path), _custom_template_url) | ||
|
||
|
||
def test_download_datacontract_file_file_exists(): | ||
_setup() | ||
|
||
def test_download_datacontract_file_file_exists(tmp_path): | ||
datacontract_test_path = tmp_path / "datacontract.yaml" | ||
# invoke twice to produce error | ||
runner.invoke(app, ["init", _datacontract_test_path]) | ||
result = runner.invoke(app, ["init", _datacontract_test_path, "--template", _custom_template_url]) | ||
runner.invoke(app, ["init", str(datacontract_test_path)]) | ||
result = runner.invoke(app, ["init", str(datacontract_test_path), "--template", _custom_template_url]) | ||
|
||
assert result.exit_code == 1 | ||
assert "File already exists, use --overwrite to overwrite" in result.stdout | ||
_compare_test_datacontract_with(_default_template_url) | ||
|
||
_compare_test_datacontract_with(str(datacontract_test_path), _default_template_url) | ||
|
||
def test_download_datacontract_file_overwrite_file(): | ||
_setup() | ||
|
||
runner.invoke(app, ["init", _datacontract_test_path]) | ||
result = runner.invoke(app, ["init", _datacontract_test_path, "--template", _custom_template_url, "--overwrite"]) | ||
def test_download_datacontract_file_overwrite_file(tmp_path): | ||
datacontract_test_path = tmp_path / "datacontract.yaml" | ||
runner.invoke(app, ["init", str(datacontract_test_path)]) | ||
result = runner.invoke(app, | ||
["init", str(datacontract_test_path), "--template", _custom_template_url, "--overwrite"]) | ||
|
||
assert result.exit_code == 0 | ||
_compare_test_datacontract_with(_custom_template_url) | ||
|
||
|
||
def _setup(): | ||
os.makedirs(".tmp", exist_ok=True) | ||
if os.path.exists(_datacontract_test_path): | ||
os.remove(_datacontract_test_path) | ||
_compare_test_datacontract_with(str(datacontract_test_path), _custom_template_url) | ||
|
||
|
||
def _compare_test_datacontract_with(url: str): | ||
def _compare_test_datacontract_with(datacontract_test_path, url: str): | ||
text = requests.get(url).text | ||
with open(_datacontract_test_path, "r") as tmp: | ||
with open(datacontract_test_path, "r") as tmp: | ||
assert tmp.read().replace("\r", "") == text.replace("\r", "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters