1919
2020import pytest
2121
22- from twine .utils import DEFAULT_REPOSITORY , get_config , get_userpass_value
2322from twine import utils
2423
2524import helpers
@@ -38,9 +37,9 @@ def test_get_config(tmpdir):
3837 password = testpassword
3938 """ ))
4039
41- assert get_config (pypirc ) == {
40+ assert utils . get_config (pypirc ) == {
4241 "pypi" : {
43- "repository" : DEFAULT_REPOSITORY ,
42+ "repository" : utils . DEFAULT_REPOSITORY ,
4443 "username" : "testuser" ,
4544 "password" : "testpassword" ,
4645 },
@@ -57,9 +56,9 @@ def test_get_config_no_distutils(tmpdir):
5756 password = testpassword
5857 """ ))
5958
60- assert get_config (pypirc ) == {
59+ assert utils . get_config (pypirc ) == {
6160 "pypi" : {
62- "repository" : DEFAULT_REPOSITORY ,
61+ "repository" : utils . DEFAULT_REPOSITORY ,
6362 "username" : "testuser" ,
6463 "password" : "testpassword" ,
6564 },
@@ -79,9 +78,9 @@ def test_get_config_no_section(tmpdir):
7978 password = testpassword
8079 """ ))
8180
82- assert get_config (pypirc ) == {
81+ assert utils . get_config (pypirc ) == {
8382 "pypi" : {
84- "repository" : DEFAULT_REPOSITORY ,
83+ "repository" : utils . DEFAULT_REPOSITORY ,
8584 "username" : "testuser" ,
8685 "password" : "testpassword" ,
8786 },
@@ -91,23 +90,47 @@ def test_get_config_no_section(tmpdir):
9190def test_get_config_missing (tmpdir ):
9291 pypirc = os .path .join (str (tmpdir ), ".pypirc" )
9392
94- assert get_config (pypirc ) == {
93+ assert utils . get_config (pypirc ) == {
9594 "pypi" : {
96- "repository" : DEFAULT_REPOSITORY ,
95+ "repository" : utils . DEFAULT_REPOSITORY ,
9796 "username" : None ,
9897 "password" : None ,
9998 },
99+ "pypitest" : {
100+ "repository" : utils .TEST_REPOSITORY ,
101+ "username" : None ,
102+ "password" : None
103+ },
100104 }
101105
102106
107+ def test_get_repository_config_missing (tmpdir ):
108+ pypirc = os .path .join (str (tmpdir ), ".pypirc" )
109+
110+ repository_url = "https://notexisting.python.org/pypi"
111+ exp = {
112+ "repository" : repository_url ,
113+ "username" : None ,
114+ "password" : None ,
115+ }
116+ assert (utils .get_repository_from_config (pypirc , 'foo' , repository_url ) ==
117+ exp )
118+ exp = {
119+ "repository" : utils .DEFAULT_REPOSITORY ,
120+ "username" : None ,
121+ "password" : None ,
122+ }
123+ assert utils .get_repository_from_config (pypirc , "pypi" ) == exp
124+
125+
103126def test_get_config_deprecated_pypirc ():
104127 tests_dir = os .path .dirname (os .path .abspath (__file__ ))
105128 deprecated_pypirc_path = os .path .join (tests_dir , 'fixtures' ,
106129 'deprecated-pypirc' )
107130
108- assert get_config (deprecated_pypirc_path ) == {
131+ assert utils . get_config (deprecated_pypirc_path ) == {
109132 "pypi" : {
110- "repository" : DEFAULT_REPOSITORY ,
133+ "repository" : utils . DEFAULT_REPOSITORY ,
111134 "username" : 'testusername' ,
112135 "password" : 'testpassword' ,
113136 },
@@ -123,7 +146,7 @@ def test_get_config_deprecated_pypirc():
123146 ),
124147)
125148def test_get_userpass_value (cli_value , config , key , strategy , expected ):
126- ret = get_userpass_value (cli_value , config , key , strategy )
149+ ret = utils . get_userpass_value (cli_value , config , key , strategy )
127150 assert ret == expected
128151
129152
0 commit comments