feat: add comprehensive tests and samples for host and user rights endpoints
- Added GraphQL sample queries and mutations for host and user rights endpoints in the 'docs' directory. - Implemented unit tests for all remaining GraphQL endpoints, including hosts, devices, host groups, locations, and user permissions. - Created dedicated integration tests for host and user rights workflows, utilizing the new sample files. - Fixed a bug in 'HostImporter.getHostGroupHierarchyNames' to correctly process and sort nested host group hierarchies. - Refined Zabbix API mocking in tests to improve reliability and support path-based routing. - Verified all 38 tests across 11 suites pass successfully.
This commit is contained in:
parent
a3ed4886a3
commit
fdfd5f1e0e
14 changed files with 729 additions and 6 deletions
21
docs/sample_all_devices_query.graphql
Normal file
21
docs/sample_all_devices_query.graphql
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
### Query
|
||||
Use this query to list all devices (hosts with device type and state).
|
||||
|
||||
```graphql
|
||||
query AllDevices($name_pattern: String, $with_items: Boolean) {
|
||||
allDevices(name_pattern: $name_pattern, with_items: $with_items) {
|
||||
hostid
|
||||
host
|
||||
name
|
||||
deviceType
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Variables
|
||||
```json
|
||||
{
|
||||
"name_pattern": "%",
|
||||
"with_items": true
|
||||
}
|
||||
```
|
||||
18
docs/sample_all_host_groups_query.graphql
Normal file
18
docs/sample_all_host_groups_query.graphql
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
### Query
|
||||
# Use this query to list all host groups.
|
||||
|
||||
```graphql
|
||||
query AllHostGroups($search_name: String) {
|
||||
allHostGroups(search_name: $search_name) {
|
||||
groupid
|
||||
name
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Variables
|
||||
```json
|
||||
{
|
||||
"search_name": "Baustellen-Devices/*"
|
||||
}
|
||||
```
|
||||
25
docs/sample_all_hosts_query.graphql
Normal file
25
docs/sample_all_hosts_query.graphql
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
### Query
|
||||
Use this query to list all hosts, filtered by name pattern and/or device type.
|
||||
|
||||
```graphql
|
||||
query AllHosts($name_pattern: String, $tag_deviceType: [String]) {
|
||||
allHosts(name_pattern: $name_pattern, tag_deviceType: $tag_deviceType) {
|
||||
hostid
|
||||
host
|
||||
name
|
||||
deviceType
|
||||
hostgroups {
|
||||
groupid
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Variables
|
||||
```json
|
||||
{
|
||||
"name_pattern": "BT_%",
|
||||
"tag_deviceType": ["bt_device_tracker_generic"]
|
||||
}
|
||||
```
|
||||
28
docs/sample_export_user_rights_query.graphql
Normal file
28
docs/sample_export_user_rights_query.graphql
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
### Query
|
||||
Use this query to export all user rights (roles and groups).
|
||||
|
||||
```graphql
|
||||
query ExportUserRights($name_pattern: String) {
|
||||
exportUserRights(name_pattern: $name_pattern) {
|
||||
userGroups {
|
||||
usrgrpid
|
||||
name
|
||||
hostgroup_rights {
|
||||
name
|
||||
permission
|
||||
}
|
||||
}
|
||||
userRoles {
|
||||
roleid
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Variables
|
||||
```json
|
||||
{
|
||||
"name_pattern": "Admin%"
|
||||
}
|
||||
```
|
||||
28
docs/sample_import_host_groups_mutation.graphql
Normal file
28
docs/sample_import_host_groups_mutation.graphql
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
### Mutation
|
||||
Use this mutation to import host groups.
|
||||
|
||||
```graphql
|
||||
mutation ImportHostGroups($hostGroups: [CreateHostGroup!]!) {
|
||||
importHostGroups(hostGroups: $hostGroups) {
|
||||
groupName
|
||||
groupid
|
||||
message
|
||||
error {
|
||||
message
|
||||
code
|
||||
data
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Variables
|
||||
```json
|
||||
{
|
||||
"hostGroups": [
|
||||
{
|
||||
"groupName": "ConstructionSite/Test"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
36
docs/sample_import_hosts_mutation.graphql
Normal file
36
docs/sample_import_hosts_mutation.graphql
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
### Mutation
|
||||
Use this mutation to import hosts and assign them to host groups.
|
||||
|
||||
```graphql
|
||||
mutation ImportHosts($hosts: [CreateHost!]!) {
|
||||
importHosts(hosts: $hosts) {
|
||||
deviceKey
|
||||
hostid
|
||||
message
|
||||
error {
|
||||
message
|
||||
code
|
||||
data
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Variables
|
||||
```json
|
||||
{
|
||||
"hosts": [
|
||||
{
|
||||
"deviceKey": "TEST_DEVICE_001",
|
||||
"name": "Test Device 001",
|
||||
"deviceType": "bt_device_tracker_generic",
|
||||
"groupNames": ["ConstructionSite/Test"],
|
||||
"location": {
|
||||
"name": "Test Location",
|
||||
"location_lat": "52.5200",
|
||||
"location_lon": "13.4050"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
50
docs/sample_import_user_rights_mutation.graphql
Normal file
50
docs/sample_import_user_rights_mutation.graphql
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
### Mutation
|
||||
Use this mutation to import user rights (roles and groups).
|
||||
|
||||
```graphql
|
||||
mutation ImportUserRights($input: UserRightsInput!, $dryRun: Boolean) {
|
||||
importUserRights(input: $input, dryRun: $dryRun) {
|
||||
userRoles {
|
||||
id
|
||||
name
|
||||
message
|
||||
}
|
||||
userGroups {
|
||||
id
|
||||
name
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Variables
|
||||
```json
|
||||
{
|
||||
"input": {
|
||||
"userRoles": [
|
||||
{
|
||||
"name": "Test Role",
|
||||
"type": 1,
|
||||
"rules": {
|
||||
"api_access": 1,
|
||||
"api": ["host.get", "item.get"]
|
||||
}
|
||||
}
|
||||
],
|
||||
"userGroups": [
|
||||
{
|
||||
"name": "Test Group",
|
||||
"gui_access": 0,
|
||||
"hostgroup_rights": [
|
||||
{
|
||||
"name": "ConstructionSite/Test",
|
||||
"permission": "READ_WRITE"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"dryRun": false
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue