Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions doc/configuring_your_machine.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
Setting up your development environment
========================================
The Azure Python CLI projects sources are located on GitHub (https://github.com/Azure/azure-cli/). In order to contribute to the project, you are expected to:
- Have a GitHub account. For Microsoft contributors, follow the guidelines on https://opensourcehub.microsoft.com/ to create, configure and link your account
- Fork the https://github.com/Azure/azure-cli/ repository into your private GitHub account
- Create pull requests against the https://github.com/azure/azure-cli repository to get your code changes merged into the project repository.
- Have a GitHub account. For Microsoft contributors, follow the guidelines on https://opensourcehub.microsoft.com/ to create, configure and link your account
- Fork the https://github.com/Azure/azure-cli/ repository into your private GitHub account
- Create pull requests against the https://github.com/azure/azure-cli repository to get your code changes merged into the project repository.

##Preparing your machine
1. Install Python 3.5.x from http://python.org. Please note that the version of Python that comes preinstalled on OSX is 2.7.
2. Clone your repository and check out the master branch.
3. Create a new virtual environment “env” for Python 3.5 in the root of your clone. You can do this by running:
## Preparing your machine
1. Install Python 3.5.x from http://python.org. Please note that the version of Python that comes preinstalled on OSX is 2.7.
2. Clone your repository and check out the master branch.
3. Create a new virtual environment “env” for Python 3.5 in the root of your clone. You can do this by running:

#####Windows
#### Windows
```BatchFile
python -m venv <clone root>\env
```
#####OSX/Ubuntu (bash)
#### OSX/Ubuntu (bash)
```Shell
python –m venv <clone root>/env
```
4. Activate the env virtual environment by running:

#####Windows
#### Windows
```BatchFile
<clone root>\env\scripts\activate.bat
```
#####OSX/Ubuntu (bash)
#### OSX/Ubuntu (bash)
```Shell
. <clone root>/env/bin/activate
```

5. Install the dependencies and load the command modules as local packages using pip.
5. Install the dependencies and load the command modules as local packages using pip.
```Shell
python scripts/dev_setup.py
```
6. Add `<clone root>\src` to your PYTHONPATH environment variable:

#####Windows
#### Windows
```BatchFile
set PYTHONPATH=<clone root>\src;%PYTHONPATH%
```
#####OSX/Ubuntu (bash)
#### OSX/Ubuntu (bash)
```Shell
export PYTHONPATH=<clone root>/src:${PYTHONPATH}
```
Expand All @@ -51,43 +51,43 @@ The Azure Python CLI projects sources are located on GitHub (https://github.com/
source az.completion.sh
```

##Configuring your IDE
####Visual Studio (Windows only)
1. Install Python Tools for Visual Studio. As of 2/18/2016, the current version (PTVS 2.2) can be found at http://microsoft.github.io/PTVS/.
2. Open the azure-cli.pyproj project
## Configuring your IDE
#### Visual Studio (Windows only)
1. Install Python Tools for Visual Studio. As of 2/18/2016, the current version (PTVS 2.2) can be found at http://microsoft.github.io/PTVS/.
2. Open the azure-cli.pyproj project
You should now be able to launch your project by pressing F5/start debugging

####Visual Studio Code (Any platform)
#### Visual Studio Code (Any platform)
Experimental steps – still haven’t been able to get virtual environments to work well with VSCode

1. Install VS Code
2. Install (one of) the python extension(s) (https://marketplace.visualstudio.com/items?itemName=donjayamanne.python)
1. Install VS Code
2. Install (one of) the python extension(s) (https://marketplace.visualstudio.com/items?itemName=donjayamanne.python)
Debugging should now work (including stepping and setting breakpoints).

The repo has a launch.json file that will launch the version of Python that is first on your path.

##Running CLI
####Command line
## Running CLI
#### Command line
1. Activate your virtual environment if not already done

#####OSX/Ubuntu (bash):
#### OSX/Ubuntu (bash):
```Shell
source <clone root>/env/scripts/activate
```

#####Windows:
#### Windows:
```BatchFile
<clone root>\env\scripts\activate.bat
```

2. Invoke the CLI using:

#####OSX/Ubuntu (bash):
#### OSX/Ubuntu (bash):
```Shell
az
```

#####Windows:
#### Windows:
```BatchFile
<clone root>\az.bat [commands]
```
Expand All @@ -96,9 +96,9 @@ 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 Tests:
####Command line
#####Windows:
## Running Tests:
#### Command line
##### Windows:
Provided your PYTHONPATH was set correctly, you can run the tests from your `<root clone>` directory.

To test the core of the CLI:
Expand All @@ -123,8 +123,9 @@ The repo has a launch.json file that will launch the version of Python that is f

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
#### VS Code
Under construction...

####Visual Studio
#### Visual Studio
Select `Test > Windows > Test Explorer` and click `Run All` in the Test Explorer pane.

24 changes: 12 additions & 12 deletions doc/recording_vcr_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Azure CLI uses the VCR.py library to record the HTTP messages exchanged during a program run and play them back at a later time, making it useful for creating command level scenario tests. These tests can be replayed at a later time without any network activity, allowing us to detect regressions in the handling of parameters and in the compatability between AzureCLI and the PythonSDK.

##Overview
## Overview

Each command module has a `tests` folder with a file called: `test_<module>_commands.py`. This is where you will define tests.

Expand All @@ -15,7 +15,7 @@ After adding your test, run it. The test driver will automatically detect the te

If the tests are run on TravisCI, any tests which cannot be replayed will automatically fail.

##Authoring Tests
## Authoring Tests

To create a new test, simply create a class in the `test_<module>_commands.py` file with the following structure:

Expand Down Expand Up @@ -49,7 +49,7 @@ The `set_up` and `tear_down` methods are optional and can be omitted. For the Re

A number of helper methods are available for structuring your script tests.

####cmd(command_string, checks=None, allowed_exceptions=None, debug=False)
#### cmd(command_string, checks=None, allowed_exceptions=None, debug=False)

This method executes a given command and returns the output. If the output is in JSON format, the method will return the results as a JSON object for easier manuipulation.

Expand All @@ -59,18 +59,18 @@ The `allowed_exceptions` parameter allows you to specify one or more (as a list)

The `checks` parameter allows you to specify one or more (as a list) checks to automatically validate the output. A number of Check objects exist for this purpose. You can create your own as long as they implement the compare method (see existing checks for examples):

#####JMESPathCheck(query, expected_result)
#### JMESPathCheck(query, expected_result)

Use the JMESPathCheck object to validate the result using any valid JMESPath query. This is useful for checking that the JSON result has fields you were expecting, arrays of certain lengths etc. See www.jmespath.org for guidance on writing JMESPath queries.

######Usage
##### Usage
```
JMESPathCheck(query, expected_result)
```
- `query` - JMESPath query as a string.
- `expected_result` - The expected result from the JMESPath query (see [jmespath.search()](https://github.com/jmespath/jmespath.py#api))

######Example
##### Example

The example below shows how you can use a JMESPath query to validate the values from a command.
When calling `test(command_string, checks)` you can pass in just one JMESPathComparator or a list of JMESPathComparators.
Expand All @@ -81,27 +81,27 @@ self.cmd('vm list-ip-addresses --resource-group myResourceGroup', checks=[
JMESPathCheck('[0].virtualMachine.name', 'myVMName')
])
```
#####NoneCheck()
#### NoneCheck()

Use this to verify that the output contains nothing. Note that this is different from `checks=None` which will skip any validation.

#####StringCheck(expected_result)
#### StringCheck(expected_result)

Matches string output to expected.

#####BooleanCheck(expected_result)
#### BooleanCheck(expected_result)

Compares truthy responses (True, 'true', 1, etc.) to a Boolean True or False.

####set_env(variable_name, value)
#### set_env(variable_name, value)

This method is a wrapper around `os.environ` and simply sets an environment variable to the specified value.

####pop_env(variable_name)
#### pop_env(variable_name)

Another wrapper around `os.environ` this pops the value of the indicated environment variable.

##Test Issues
## Test Issues

Here are some common issues that occur when authoring tests that you should be aware of.

Expand Down