Using Pycharm
It is recommand to using pycharm(The most popular python IDE) to develop & testing plugins. Overall setting processes are as below.
1. Open projects and dependencies
First, open project Identity, python-core and api one by one.
Click Open
Select your project directory. In this example '~/source/cloudone/identity'
Click File > Open , then select related project one by one. In this example '~/source/cloudone/python-core'
Select New Window for an additional project. You might need to do several times if you have multiple projects. Ex) python-core and api
Now we have 3 windows. Just close python-core and API projects.
Once you open your project at least one time, you can attach them to each other. Let's do it on identity project. Do this again Open > select your anther project directory. In this example, python-core and API.
But this time, you can ATTACH it to Identity project.
You can attach a project as a module if it was imported at least once.
2. Configure Virtual Environment
Add additional python interpreter
Click virtual environment section
Designate base interpreter as 'Python 3.8'(Python3 need to be installed previously)
Then click 'OK'
Return to 'Python interpreter > Interpreter Settings..'
List of installed python package on virtual environment will be displayed
Click '+' button, Then search & click 'Install Package' below
'spaceone-core'
'spaceone-api'
'spaceone-tester'
Additional libraries are in 'pkg/pip_requirements.txt' in every repository. You also need to install them.
Repeat above process or you can install through command line
$> pip3 install -r pip_requirements.txt
3. Run Server
- Set source root directory
- Right click on 'src' directory 'Mark Directory as > Resource Root'
- Set test server configuration
- Fill in test server configurations are as below, then click 'OK'
Item | Configuration | Etc |
---|---|---|
Module name | spaceone.core.command | |
Parameters | grpc spaceone.inventory -p 50051 | -p option means portnumber (Can be changed) |
- You can run test server with 'play button' on the upper right side or the IDE
4. Execute Test Code
Every plugin repository has their own unit test case file in 'test/api' directory
- Right click on 'test_collector.py' file
- Click 'Run 'test_collector''
Some plugin needs credential to interface with other services. You need to make credential file and set them as environments before run
Go to test server configuration > test_server > Edit Configurations
Click Edit variables
Add environment variable as below
Item | Configuration | Etc |
---|---|---|
PYTHONUNBUFFERED | 1 | |
GOOGLE_APPLICATION_CREDENTIALS | Full path of your configuration file |
Finally you can test run your server
First, run test server locally
Second, run unit test