|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import phpypam |
| 4 | +import json |
| 5 | +import yaml |
| 6 | + |
| 7 | +with open('tests/vars/server.yml') as c: |
| 8 | + server = yaml.safe_load(c) |
| 9 | + |
| 10 | +from phpypam import PHPyPAMEntityNotFoundException |
| 11 | + |
| 12 | + |
| 13 | +if __name__ == '__main__': |
| 14 | + pi = phpypam.api( |
| 15 | + url=server['url'], |
| 16 | + app_id=server['app_id'], |
| 17 | + username=server['username'], |
| 18 | + password=server['password'], |
| 19 | + ssl_verify=True |
| 20 | + ) |
| 21 | + |
| 22 | + my_section = dict( |
| 23 | + name='foobar', |
| 24 | + description='new section', |
| 25 | + permissions='{"3":"1","2":"2"}' |
| 26 | + ) |
| 27 | + try: |
| 28 | + entity = pi.get_entity(controller='sections', controller_path=my_section['name']) |
| 29 | + except PHPyPAMEntityNotFoundException: |
| 30 | + print('create entity') |
| 31 | + entity = pi.create_entity(controller='sections', data=my_section) |
| 32 | + entity = pi.get_entity(controller='sections', controller_path=my_section['name']) |
| 33 | + |
| 34 | + entity = pi.get_entity(controller='sections', controller_path=my_section['name']) |
| 35 | + print(json.dumps(entity, indent=4, sort_keys=True)) |
| 36 | + |
| 37 | + my_section['description'] = 'new description' |
| 38 | + |
| 39 | + print('update entity') |
| 40 | + pi.update_entity(controller='sections', controller_path=entity['id'], data=my_section) |
| 41 | + |
| 42 | + entity = pi.get_entity(controller='sections', controller_path=my_section['name']) |
| 43 | + print(json.dumps(entity, indent=4, sort_keys=True)) |
| 44 | + |
| 45 | + print('delete entity') |
| 46 | + pi.delete_entity(controller='sections', controller_path=entity['id']) |
0 commit comments