|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
| 14 | +import requests |
| 15 | + |
14 | 16 | from twine import repository |
15 | 17 |
|
| 18 | +import pretend |
| 19 | + |
16 | 20 |
|
17 | 21 | def test_gpg_signature_structure_is_preserved(): |
18 | 22 | data = { |
@@ -90,3 +94,48 @@ def test_make_user_agent_string(): |
90 | 94 | assert 'requests-toolbelt/' in user_agent |
91 | 95 | assert 'pkginfo/' in user_agent |
92 | 96 | assert 'setuptools/' in user_agent |
| 97 | + |
| 98 | + |
| 99 | +def response_with(**kwattrs): |
| 100 | + resp = requests.Response() |
| 101 | + for attr, value in kwattrs.items(): |
| 102 | + if hasattr(resp, attr): |
| 103 | + setattr(resp, attr, value) |
| 104 | + |
| 105 | + return resp |
| 106 | + |
| 107 | + |
| 108 | +def test_package_is_uploaded_404s(): |
| 109 | + repo = repository.Repository( |
| 110 | + repository_url='https://pypi.python.org/pypi', |
| 111 | + username='username', |
| 112 | + password='password', |
| 113 | + ) |
| 114 | + repo.session = pretend.stub( |
| 115 | + get=lambda url, headers: response_with(status_code=404) |
| 116 | + ) |
| 117 | + package = pretend.stub( |
| 118 | + safe_name='fake', |
| 119 | + metadata=pretend.stub(version='2.12.0'), |
| 120 | + ) |
| 121 | + |
| 122 | + assert repo.package_is_uploaded(package) is False |
| 123 | + |
| 124 | + |
| 125 | +def test_package_is_uploaded_200s_with_no_releases(): |
| 126 | + repo = repository.Repository( |
| 127 | + repository_url='https://pypi.python.org/pypi', |
| 128 | + username='username', |
| 129 | + password='password', |
| 130 | + ) |
| 131 | + repo.session = pretend.stub( |
| 132 | + get=lambda url, headers: response_with(status_code=200, |
| 133 | + _content=b'{"releases": {}}', |
| 134 | + _content_consumed=True), |
| 135 | + ) |
| 136 | + package = pretend.stub( |
| 137 | + safe_name='fake', |
| 138 | + metadata=pretend.stub(version='2.12.0'), |
| 139 | + ) |
| 140 | + |
| 141 | + assert repo.package_is_uploaded(package) is False |
0 commit comments