|
4 | 4 |
|
5 | 5 | from cleo.testers import CommandTester
|
6 | 6 |
|
| 7 | +from poetry.repositories.legacy_repository import LegacyRepository |
| 8 | +from poetry.semver import Version |
7 | 9 | from poetry.utils._compat import Path
|
8 | 10 | from tests.helpers import get_dependency
|
9 | 11 | from tests.helpers import get_package
|
@@ -634,6 +636,72 @@ def test_add_constraint_with_platform(app, repo, installer):
|
634 | 636 | }
|
635 | 637 |
|
636 | 638 |
|
| 639 | +def test_add_constraint_with_source(app, poetry, installer): |
| 640 | + repo = LegacyRepository(name="my-index", url="https://my-index.fake") |
| 641 | + repo.add_package(get_package("cachy", "0.2.0")) |
| 642 | + repo._cache.store("matches").put("cachy:0.2.0", [Version.parse("0.2.0")], 5) |
| 643 | + |
| 644 | + poetry.pool.add_repository(repo) |
| 645 | + |
| 646 | + command = app.find("add") |
| 647 | + tester = CommandTester(command) |
| 648 | + |
| 649 | + tester.execute("cachy=0.2.0 --source my-index") |
| 650 | + |
| 651 | + expected = """\ |
| 652 | +
|
| 653 | +Updating dependencies |
| 654 | +Resolving dependencies... |
| 655 | +
|
| 656 | +Writing lock file |
| 657 | +
|
| 658 | +
|
| 659 | +Package operations: 1 install, 0 updates, 0 removals |
| 660 | +
|
| 661 | + - Installing cachy (0.2.0) |
| 662 | +""" |
| 663 | + |
| 664 | + assert expected == tester.io.fetch_output() |
| 665 | + |
| 666 | + assert len(installer.installs) == 1 |
| 667 | + |
| 668 | + content = app.poetry.file.read()["tool"]["poetry"] |
| 669 | + |
| 670 | + assert "cachy" in content["dependencies"] |
| 671 | + assert content["dependencies"]["cachy"] == { |
| 672 | + "version": "0.2.0", |
| 673 | + "source": "my-index", |
| 674 | + } |
| 675 | + |
| 676 | + |
| 677 | +def test_add_constraint_with_source_that_does_not_exist(app): |
| 678 | + command = app.find("add") |
| 679 | + tester = CommandTester(command) |
| 680 | + |
| 681 | + with pytest.raises(ValueError) as e: |
| 682 | + tester.execute("foo --source i-dont-exist") |
| 683 | + |
| 684 | + assert 'Repository "i-dont-exist" does not exist.' == str(e.value) |
| 685 | + |
| 686 | + |
| 687 | +def test_add_constraint_not_found_with_source(app, poetry, mocker): |
| 688 | + repo = LegacyRepository(name="my-index", url="https://my-index.fake") |
| 689 | + mocker.patch.object(repo, "find_packages", return_value=[]) |
| 690 | + |
| 691 | + poetry.pool.add_repository(repo) |
| 692 | + |
| 693 | + pypi = poetry.pool.repositories[0] |
| 694 | + pypi.add_package(get_package("cachy", "0.2.0")) |
| 695 | + |
| 696 | + command = app.find("add") |
| 697 | + tester = CommandTester(command) |
| 698 | + |
| 699 | + with pytest.raises(ValueError) as e: |
| 700 | + tester.execute("cachy --source my-index") |
| 701 | + |
| 702 | + assert "Could not find a matching version of package cachy" == str(e.value) |
| 703 | + |
| 704 | + |
637 | 705 | def test_add_to_section_that_does_no_exist_yet(app, repo, installer):
|
638 | 706 | command = app.find("add")
|
639 | 707 | tester = CommandTester(command)
|
|
0 commit comments