|
2 | 2 |
|
3 | 3 | """Tests for authentication commands.""" |
4 | 4 |
|
| 5 | +import json |
5 | 6 | import unittest.mock |
6 | 7 |
|
| 8 | +from binstar_client import errors |
| 9 | + |
7 | 10 | from tests.fixture import CLITestCase, main |
8 | 11 | from tests.urlmock import urlpatch |
| 12 | +from tests.utils.utils import data_dir |
9 | 13 |
|
10 | 14 |
|
11 | 15 | class Test(CLITestCase): |
@@ -111,3 +115,33 @@ def test_legacy_login_user_pass_flags(self, urls, store_token, _do_auth_flow): |
111 | 115 |
|
112 | 116 | self.assertTrue(store_token.called) |
113 | 117 | self.assertEqual(store_token.call_args[0][0], 'a-token') |
| 118 | + |
| 119 | + @unittest.mock.patch('binstar_client.commands.login.bool_input') |
| 120 | + @unittest.mock.patch('binstar_client.commands.login._do_auth_flow') |
| 121 | + @urlpatch |
| 122 | + @unittest.skip("Cannot accurately test this scenario") |
| 123 | + def test_login_required_args(self, urls, _do_auth_flow, bool_input): |
| 124 | + org_data = { |
| 125 | + "company": "foo", |
| 126 | + "created_at": "2015-11-19 18:22:23.061000+00:00", |
| 127 | + "description": "", |
| 128 | + "location": "here", |
| 129 | + "login": "org-name", |
| 130 | + "name": "Me", |
| 131 | + "url": "", |
| 132 | + "user_type": "org", |
| 133 | + } |
| 134 | + |
| 135 | + urls.register(method='HEAD', path='/', status=200) |
| 136 | + urls.register(method='GET', path='/user/org-name', content=json.dumps(org_data)) |
| 137 | + urls.register(method="GET", path="/dist/org-name/foo/0.1/osx-64/foo-0.1-0.tar.bz2", status=401, content={}) |
| 138 | + |
| 139 | + # We just need make sure we get past the legacy_flag determination |
| 140 | + # We don't need to finish login or upload |
| 141 | + bool_input.return_value = False |
| 142 | + |
| 143 | + with self.assertRaises(SystemExit): |
| 144 | + main(['--show-traceback', 'upload', "-u", "org-name", data_dir('foo-0.1-0.tar.bz2')]) |
| 145 | + |
| 146 | + self.assertIn("\"org-name\" as upload username", self.stream.getvalue()) |
| 147 | + self.assertIn("The action you are performing requires authentication", self.stream.getvalue()) |
0 commit comments