Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 15 | from __future__ import print_function |
| 16 | from xosapi import xos_grpc_client |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 17 | import sys |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 18 | |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 19 | sys.path.append("..") |
| 20 | |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 21 | |
| 22 | def test_callback(): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 23 | print("TEST: vtr_crud") |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 24 | |
| 25 | c = xos_grpc_client.coreclient |
| 26 | |
| 27 | sr = c.xos_orm.CordSubscriberRoot.objects.first() |
| 28 | if not sr: |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 29 | print("No subscriber roots!") |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 30 | return |
| 31 | |
| 32 | vt = c.xos_orm.VTRTenant.objects.new() |
| 33 | vt.target = sr |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 34 | vt.test = "ping" |
| 35 | vt.scope = "vm" |
| 36 | vt.argument = "8.8.8.8" |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 37 | vt.save() |
| 38 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 39 | assert vt.id is not None |
| 40 | assert vt.id > 0 |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 41 | |
| 42 | # Check and make sure we can read it back, pay particular attention to |
| 43 | # the generic foreign key. |
| 44 | vt2 = c.xos_orm.VTRTenant.objects.get(id=vt.id) |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 45 | assert vt2.target_id == sr.id |
| 46 | assert vt2.target_type_id == sr.self_content_type_id |
| 47 | assert "TenantRoot" in vt2.target.class_names |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 48 | |
| 49 | vt2.delete() |
| 50 | |
| 51 | # now, make sure it has been deleted |
| 52 | vt3 = c.xos_orm.VTRTenant.objects.filter(id=vt.id) |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 53 | assert not vt3 |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 54 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 55 | print(" okay") |
| 56 | |
Scott Baker | aa556b0 | 2017-03-07 16:07:34 -0800 | [diff] [blame] | 57 | |
| 58 | xos_grpc_client.start_api_parseargs(test_callback) |