This commit is contained in:
Travis Prescott 2016-04-08 16:18:02 -07:00
Родитель 6ddfccaa5a
Коммит 7c96231871
14 изменённых файлов: 228 добавлений и 36 удалений

Просмотреть файл

@ -93,14 +93,32 @@ The repo has a launch.json file that will launch the version of Python that is f
<clone root>\src\python -m azure.cli [commands]
```
##Running Unit Tests:
##Running Tests:
####Command line
#####Windows:
Provided your PYTHONPATH was set correctly, from `<clone root>\src` run:
Provided your PYTHONPATH was set correctly, you can run the tests from your `<root clone>` directory.
To test the core of the CLI:
```BatchFile
python -m unittest discover -s azure\cli\tests [--buffer]
```
Use of `--buffer` will automatically fail any VCR-style tests which do not have an expected result recorded. Omit `--buffer` to permit recording of tests. To re-record any tests, you can either remove the test's entry from the `expected_results.res` file or remove the corresponding `<test>.yaml` VCR cassette and re-run without `--buffer`.
python -m unittest discover -s src/azure/cli/tests
```
To test the command modules:
```BatchFile
python scripts/command_modules/test.py
```
To check or pylint errors in the core of the CLI:
```BatchFile
pylint src/azure
```
To check the command modules for pylint errors:
```Batch
python scripts/command_modules/pylint.py
```
Additionally, you can run pylint tests for the core CLI and all command modules using the `lintall.bat` script, and run tests for the core CLI and all command modules using the `testall.bat` script.
####VS Code
Under construction...

3
lintall.bat Normal file
Просмотреть файл

@ -0,0 +1,3 @@
@echo off
pylint src/azure
python scripts/command_modules/pylint.py

Просмотреть файл

@ -22,19 +22,19 @@ command_table = CommandTable()
def _storage_client_factory(*args): # pylint: disable=unused-argument
return get_mgmt_service_client(StorageManagementClient, StorageManagementClientConfiguration)
def _file_data_service_factory(*args):
def _file_data_service_factory(args):
return get_data_service_client(
FileService,
args[0].pop('account_name', None),
args[0].pop('account_key', None),
args[0].pop('connection_string', None))
args.pop('account_name', None),
args.pop('account_key', None),
args.pop('connection_string', None))
def _blob_data_service_factory(*args):
def _blob_data_service_factory(args):
return get_data_service_client(
BlockBlobService,
args[0].pop('account_name', None),
args[0].pop('account_key', None),
args[0].pop('connection_string', None))
args.pop('account_name', None),
args.pop('account_key', None),
args.pop('connection_string', None))
# HELPER METHODS
@ -470,7 +470,9 @@ build_operation(
AutoCommandDefinition(FileService.list_directories_and_files,
'[ShareContents]', 'contents'),
AutoCommandDefinition(FileService.create_share, 'Boolean', 'create'),
AutoCommandDefinition(FileService.delete_share, 'Boolean', 'delete')
AutoCommandDefinition(FileService.delete_share, 'Boolean', 'delete'),
AutoCommandDefinition(FileService.get_share_metadata, 'Metadata', 'show-metadata'),
AutoCommandDefinition(FileService.set_share_metadata, None, 'set-metadata')
],
command_table,
{
@ -494,7 +496,9 @@ build_operation(
'storage directory', None, _file_data_service_factory,
[
AutoCommandDefinition(FileService.create_directory, 'Boolean', 'create'),
AutoCommandDefinition(FileService.delete_directory, 'Boolean', 'delete')
AutoCommandDefinition(FileService.delete_directory, 'Boolean', 'delete'),
AutoCommandDefinition(FileService.get_directory_metadata, 'Metadata', 'show-metadata'),
AutoCommandDefinition(FileService.set_directory_metadata, None, 'set-metadata')
],
command_table,
{

Просмотреть файл

@ -153,11 +153,10 @@ TEST_DEF = [
'test_name': 'storage_share_create_simple',
'command': 'storage share create --share-name testshare02 --fail-on-exist'
},
# TODO: Metadata doesn't fail...but it doesn't take either...
#{
# 'test_name': 'storage_share_create_with_metadata',
# 'command': 'storage share create --share-name testshare03 --fail-on-exist --metadata foo=bar;cat=hat'
#},
{
'test_name': 'storage_share_create_with_metadata',
'command': 'storage share create --share-name testshare03 --fail-on-exist --metadata foo=bar;cat=hat'
},
{
'test_name': 'storage_share_exists',
'command': 'storage share exists --share-name testshare01'
@ -174,6 +173,18 @@ TEST_DEF = [
'test_name': 'storage_share_delete',
'command': 'storage share delete --share-name testshare02 --fail-not-exist'
},
{
'test_name': 'storage_share_set_metadata',
'command': 'storage share set-metadata --share-name testshare01 --metadata a=b;c=d'
},
{
'test_name': 'storage_share_show_metadata',
'command': 'storage share show-metadata --share-name testshare01'
},
{
'test_name': 'storage_share_clear_metadata',
'command': 'storage share set-metadata --share-name testshare01'
},
# STORAGE DIRECTORY TESTS
{
'test_name': 'storage_directory_exists',
@ -183,15 +194,26 @@ TEST_DEF = [
'test_name': 'storage_directory_create_simple',
'command': 'storage directory create --share-name testshare01 --directory-name tempdir01 --fail-on-exist'
},
# TODO: Metadata doesn't fail...but it doesn't take either...
#{
# 'test_name': 'storage_directory_create_with_metadata',
# 'command': 'storage directory create --share-name testshare01 --directory-name tempdir02 --fail-on-exist --metadata foo=bar;cat=hat'
#},
{
'test_name': 'storage_directory_create_with_metadata',
'command': 'storage directory create --share-name testshare01 --directory-name tempdir02 --fail-on-exist --metadata foo=bar;cat=hat'
},
{
'test_name': 'storage_directory_delete',
'command': 'storage directory delete --share-name testshare01 --directory-name tempdir01 --fail-not-exist'
},
{
'test_name': 'storage_directory_set_metadata',
'command': 'storage directory set-metadata --share-name testshare01 --directory-name testdir1 --metadata a=b;c=d'
},
{
'test_name': 'storage_directory_show_metadata',
'command': 'storage directory show-metadata --share-name testshare01 --directory-name testdir1'
},
{
'test_name': 'storage_directory_clear_metadata',
'command': 'storage directory set-metadata --share-name testshare01 --directory-name testdir1'
},
# STORAGE FILE TESTS
{
'test_name': 'storage_file_upload_simple',
@ -228,5 +250,5 @@ TEST_DEF = [
{
'test_name': 'storage_file_delete_with_subdir',
'command': 'storage file delete --share-name testshare01 --directory-name testdir1 --file-name testfile02.rst'
},
}
]

Просмотреть файл

@ -26,9 +26,13 @@
"test_storage_container_lease_renew": "",
"test_storage_container_list": "Next Marker : \nItems :\n Metadata : None\n Name : bootdiagnostics-testvm234-8bc8e6e1-9728-4540-b2a3-7f741fdd4609\n Properties :\n Etag : \"0x8D34D260EA39931\"\n Last Modified : 2016-03-15T23:03:43+00:00\n Lease Duration : None\n Lease State : available\n Lease Status : unlocked\n Lease :\n Duration : None\n State : None\n Status : None\n Metadata : None\n Name : testcontainer01\n Properties :\n Etag : \"0x8D35FC34FD02B14\"\n Last Modified : 2016-04-08T15:34:45+00:00\n Lease Duration : None\n Lease State : available\n Lease Status : unlocked\n Lease :\n Duration : None\n State : None\n Status : None\n Metadata : None\n Name : testcontainer03\n Properties :\n Etag : \"0x8D35A49D49A78A9\"\n Last Modified : 2016-04-01T16:22:33+00:00\n Lease Duration : None\n Lease State : available\n Lease Status : unlocked\n Lease :\n Duration : None\n State : None\n Status : None\n Metadata : None\n Name : testcontainer1234\n Properties :\n Etag : \"0x8D34F6C318A43C6\"\n Last Modified : 2016-03-18T20:30:49+00:00\n Lease Duration : None\n Lease State : expired\n Lease Status : unlocked\n Lease :\n Duration : None\n State : None\n Status : None\n Metadata : None\n Name : vhds\n Properties :\n Etag : \"0x8D34D260EEA5070\"\n Last Modified : 2016-03-15T23:03:44+00:00\n Lease Duration : infinite\n Lease State : leased\n Lease Status : locked\n Lease :\n Duration : None\n State : None\n Status : None\n\n\n",
"test_storage_container_show": "Name : testcontainer01\nMetadata :\n None\nProperties :\n Etag : \"0x8D35FC34FD02B14\"\n Last Modified : 2016-04-08T15:34:45+00:00\n Lease :\n Duration : None\n State : available\n Status : unlocked\n\n\n",
"test_storage_directory_clear_metadata": "",
"test_storage_directory_create_simple": "True\n\n\n",
"test_storage_directory_create_with_metadata": "True\n\n\n",
"test_storage_directory_delete": "True\n\n\n",
"test_storage_directory_exists": "True\n\n\n",
"test_storage_directory_set_metadata": "",
"test_storage_directory_show_metadata": "A : b\nC : d\n\n\n",
"test_storage_file_delete_simple": "",
"test_storage_file_delete_with_subdir": "",
"test_storage_file_download_simple": "",
@ -37,10 +41,14 @@
"test_storage_file_exists_with_subdir": "True\n\n\n",
"test_storage_file_upload_simple": "",
"test_storage_file_upload_with_subdir": "",
"test_storage_share_clear_metadata": "",
"test_storage_share_contents": "Next Marker : None\nItems :\n Content : None\n Metadata : None\n Name : large.txt\n Properties :\n Content Length : 89344384\n Etag : None\n Last Modified : None\n Content Settings :\n Cache Control : None\n Content Disposition : None\n Content Encoding : None\n Content Language : None\n Content Md5 : None\n Content Type : None\n Copy :\n Completion Time : None\n Id : None\n Progress : None\n Source : None\n Status : None\n Status Description : None\n Content : None\n Metadata : None\n Name : testfile01.rst\n Properties :\n Content Length : 1328\n Etag : None\n Last Modified : None\n Content Settings :\n Cache Control : None\n Content Disposition : None\n Content Encoding : None\n Content Language : None\n Content Md5 : None\n Content Type : None\n Copy :\n Completion Time : None\n Id : None\n Progress : None\n Source : None\n Status : None\n Status Description : None\n Metadata : None\n Name : tempdir02\n Properties :\n Etag : None\n Last Modified : None\n Metadata : None\n Name : testdir1\n Properties :\n Etag : None\n Last Modified : None\n Metadata : None\n Name : testdir2\n Properties :\n Etag : None\n Last Modified : None\n\n\n",
"test_storage_share_contents_with_subdirectory": "Next Marker : None\nItems :\n Content : None\n Metadata : None\n Name : test.txt\n Properties :\n Content Length : 89344384\n Etag : None\n Last Modified : None\n Content Settings :\n Cache Control : None\n Content Disposition : None\n Content Encoding : None\n Content Language : None\n Content Md5 : None\n Content Type : None\n Copy :\n Completion Time : None\n Id : None\n Progress : None\n Source : None\n Status : None\n Status Description : None\n Content : None\n Metadata : None\n Name : testfile02.rst\n Properties :\n Content Length : 1328\n Etag : None\n Last Modified : None\n Content Settings :\n Cache Control : None\n Content Disposition : None\n Content Encoding : None\n Content Language : None\n Content Md5 : None\n Content Type : None\n Copy :\n Completion Time : None\n Id : None\n Progress : None\n Source : None\n Status : None\n Status Description : None\n Metadata : None\n Name : test\n Properties :\n Etag : None\n Last Modified : None\n\n\n",
"test_storage_share_create_simple": "True\n\n\n",
"test_storage_share_create_with_metadata": "True\n\n\n",
"test_storage_share_delete": "True\n\n\n",
"test_storage_share_exists": "True\n\n\n",
"test_storage_share_list": "Next Marker : None\nItems :\n Metadata : None\n Name : testshare01\n Properties :\n Etag : \"0x8D352D422AB9D3B\"\n Last Modified : 2016-03-23T04:32:25+00:00\n Quota : 5120\n Metadata : None\n Name : testshare03\n Properties :\n Etag : \"0x8D35E6002CBFE71\"\n Last Modified : 2016-04-06T21:11:24+00:00\n Quota : 5120\n\n\n"
"test_storage_share_list": "Next Marker : None\nItems :\n Metadata : None\n Name : testshare01\n Properties :\n Etag : \"0x8D352D422AB9D3B\"\n Last Modified : 2016-03-23T04:32:25+00:00\n Quota : 5120\n Metadata : None\n Name : testshare03\n Properties :\n Etag : \"0x8D35E6002CBFE71\"\n Last Modified : 2016-04-06T21:11:24+00:00\n Quota : 5120\n\n\n",
"test_storage_share_set_metadata": "",
"test_storage_share_show_metadata": "A : b\nC : d\n\n\n"
}

Просмотреть файл

@ -0,0 +1,22 @@
interactions:
- request:
body: null
headers:
Accept-Encoding: [identity]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [Azure-Storage/0.30.0 (Python CPython 3.5.1; Windows 10)]
x-ms-date: ['Fri, 08 Apr 2016 22:29:16 GMT']
x-ms-version: ['2015-04-05']
method: PUT
uri: https://travistestresourcegr3014.file.core.windows.net/testshare01/testdir1?restype=directory&comp=metadata
response:
body: {string: ''}
headers:
Date: ['Fri, 08 Apr 2016 22:29:17 GMT']
ETag: ['"0x8D35FFD39055AB6"']
Last-Modified: ['Fri, 08 Apr 2016 22:29:17 GMT']
Server: [Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0]
x-ms-version: ['2015-04-05']
status: {code: 200, message: OK}
version: 1

Просмотреть файл

@ -6,7 +6,7 @@ interactions:
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [Azure-Storage/0.30.0 (Python CPython 3.5.1; Windows 10)]
x-ms-date: ['Fri, 08 Apr 2016 15:56:34 GMT']
x-ms-date: ['Fri, 08 Apr 2016 22:24:07 GMT']
x-ms-meta-cat: [hat]
x-ms-meta-foo: [bar]
x-ms-version: ['2015-04-05']
@ -15,9 +15,9 @@ interactions:
response:
body: {string: ''}
headers:
Date: ['Fri, 08 Apr 2016 15:56:34 GMT']
ETag: ['"0x8D35FC65C703424"']
Last-Modified: ['Fri, 08 Apr 2016 15:56:34 GMT']
Date: ['Fri, 08 Apr 2016 22:24:07 GMT']
ETag: ['"0x8D35FFC8058B56C"']
Last-Modified: ['Fri, 08 Apr 2016 22:24:07 GMT']
Server: [Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0]
x-ms-version: ['2015-04-05']
status: {code: 201, message: Created}

Просмотреть файл

@ -0,0 +1,24 @@
interactions:
- request:
body: null
headers:
Accept-Encoding: [identity]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [Azure-Storage/0.30.0 (Python CPython 3.5.1; Windows 10)]
x-ms-date: ['Fri, 08 Apr 2016 22:28:22 GMT']
x-ms-meta-a: [b]
x-ms-meta-c: [d]
x-ms-version: ['2015-04-05']
method: PUT
uri: https://travistestresourcegr3014.file.core.windows.net/testshare01/testdir1?restype=directory&comp=metadata
response:
body: {string: ''}
headers:
Date: ['Fri, 08 Apr 2016 22:28:23 GMT']
ETag: ['"0x8D35FFD1866246A"']
Last-Modified: ['Fri, 08 Apr 2016 22:28:23 GMT']
Server: [Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0]
x-ms-version: ['2015-04-05']
status: {code: 200, message: OK}
version: 1

Просмотреть файл

@ -0,0 +1,23 @@
interactions:
- request:
body: null
headers:
Accept-Encoding: [identity]
Connection: [keep-alive]
User-Agent: [Azure-Storage/0.30.0 (Python CPython 3.5.1; Windows 10)]
x-ms-date: ['Fri, 08 Apr 2016 22:28:52 GMT']
x-ms-version: ['2015-04-05']
method: GET
uri: https://travistestresourcegr3014.file.core.windows.net/testshare01/testdir1?restype=directory&comp=metadata
response:
body: {string: ''}
headers:
Date: ['Fri, 08 Apr 2016 22:28:51 GMT']
ETag: ['"0x8D35FFD1866246A"']
Last-Modified: ['Fri, 08 Apr 2016 22:28:23 GMT']
Server: [Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0]
x-ms-meta-a: [b]
x-ms-meta-c: [d]
x-ms-version: ['2015-04-05']
status: {code: 200, message: OK}
version: 1

Просмотреть файл

@ -0,0 +1,22 @@
interactions:
- request:
body: null
headers:
Accept-Encoding: [identity]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [Azure-Storage/0.30.0 (Python CPython 3.5.1; Windows 10)]
x-ms-date: ['Fri, 08 Apr 2016 22:19:15 GMT']
x-ms-version: ['2015-04-05']
method: PUT
uri: https://travistestresourcegr3014.file.core.windows.net/testshare01?restype=share&comp=metadata
response:
body: {string: ''}
headers:
Date: ['Fri, 08 Apr 2016 22:19:15 GMT']
ETag: ['"0x8D35FFBD26EF9D3"']
Last-Modified: ['Fri, 08 Apr 2016 22:19:16 GMT']
Server: [Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0]
x-ms-version: ['2015-04-05']
status: {code: 200, message: OK}
version: 1

Просмотреть файл

@ -6,7 +6,7 @@ interactions:
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [Azure-Storage/0.30.0 (Python CPython 3.5.1; Windows 10)]
x-ms-date: ['Fri, 08 Apr 2016 16:06:35 GMT']
x-ms-date: ['Fri, 08 Apr 2016 22:20:06 GMT']
x-ms-meta-cat: [hat]
x-ms-meta-foo: [bar]
x-ms-version: ['2015-04-05']
@ -15,9 +15,9 @@ interactions:
response:
body: {string: ''}
headers:
Date: ['Fri, 08 Apr 2016 16:06:36 GMT']
ETag: ['"0x8D35FC7C31DF682"']
Last-Modified: ['Fri, 08 Apr 2016 16:06:36 GMT']
Date: ['Fri, 08 Apr 2016 22:20:06 GMT']
ETag: ['"0x8D35FFBF0F5F48F"']
Last-Modified: ['Fri, 08 Apr 2016 22:20:07 GMT']
Server: [Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0]
x-ms-version: ['2015-04-05']
status: {code: 201, message: Created}

Просмотреть файл

@ -0,0 +1,24 @@
interactions:
- request:
body: null
headers:
Accept-Encoding: [identity]
Connection: [keep-alive]
Content-Length: ['0']
User-Agent: [Azure-Storage/0.30.0 (Python CPython 3.5.1; Windows 10)]
x-ms-date: ['Fri, 08 Apr 2016 22:18:04 GMT']
x-ms-meta-a: [b]
x-ms-meta-c: [d]
x-ms-version: ['2015-04-05']
method: PUT
uri: https://travistestresourcegr3014.file.core.windows.net/testshare01?restype=share&comp=metadata
response:
body: {string: ''}
headers:
Date: ['Fri, 08 Apr 2016 22:18:04 GMT']
ETag: ['"0x8D35FFBA801F9FA"']
Last-Modified: ['Fri, 08 Apr 2016 22:18:04 GMT']
Server: [Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0]
x-ms-version: ['2015-04-05']
status: {code: 200, message: OK}
version: 1

Просмотреть файл

@ -0,0 +1,23 @@
interactions:
- request:
body: null
headers:
Accept-Encoding: [identity]
Connection: [keep-alive]
User-Agent: [Azure-Storage/0.30.0 (Python CPython 3.5.1; Windows 10)]
x-ms-date: ['Fri, 08 Apr 2016 22:18:51 GMT']
x-ms-version: ['2015-04-05']
method: GET
uri: https://travistestresourcegr3014.file.core.windows.net/testshare01?restype=share&comp=metadata
response:
body: {string: ''}
headers:
Date: ['Fri, 08 Apr 2016 22:18:51 GMT']
ETag: ['"0x8D35FFBA801F9FA"']
Last-Modified: ['Fri, 08 Apr 2016 22:18:04 GMT']
Server: [Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0]
x-ms-meta-a: [b]
x-ms-meta-c: [d]
x-ms-version: ['2015-04-05']
status: {code: 200, message: OK}
version: 1

Просмотреть файл

@ -1,4 +1,3 @@
@echo off
python scripts/command_modules/pylint.py
python -m unittest discover -s src/azure/cli/tests
python scripts/command_modules/test.py