blob: e776d134e4baceb2777e0a937cc8e535888b6ddd [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001# 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 Williams045b63d2019-01-22 16:30:57 -070015from __future__ import print_function
16from xosapi import xos_grpc_client
Scott Bakeraa556b02017-03-07 16:07:34 -080017import sys
Zack Williams045b63d2019-01-22 16:30:57 -070018
Scott Bakeraa556b02017-03-07 16:07:34 -080019sys.path.append("..")
20
Scott Bakeraa556b02017-03-07 16:07:34 -080021
22def test_callback():
Zack Williams045b63d2019-01-22 16:30:57 -070023 print("TEST: vtr_crud")
Scott Bakeraa556b02017-03-07 16:07:34 -080024
25 c = xos_grpc_client.coreclient
26
27 sr = c.xos_orm.CordSubscriberRoot.objects.first()
28 if not sr:
Zack Williams045b63d2019-01-22 16:30:57 -070029 print("No subscriber roots!")
Scott Bakeraa556b02017-03-07 16:07:34 -080030 return
31
32 vt = c.xos_orm.VTRTenant.objects.new()
33 vt.target = sr
Zack Williams045b63d2019-01-22 16:30:57 -070034 vt.test = "ping"
35 vt.scope = "vm"
36 vt.argument = "8.8.8.8"
Scott Bakeraa556b02017-03-07 16:07:34 -080037 vt.save()
38
Zack Williams045b63d2019-01-22 16:30:57 -070039 assert vt.id is not None
40 assert vt.id > 0
Scott Bakeraa556b02017-03-07 16:07:34 -080041
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 Williams045b63d2019-01-22 16:30:57 -070045 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 Bakeraa556b02017-03-07 16:07:34 -080048
49 vt2.delete()
50
51 # now, make sure it has been deleted
52 vt3 = c.xos_orm.VTRTenant.objects.filter(id=vt.id)
Zack Williams045b63d2019-01-22 16:30:57 -070053 assert not vt3
Scott Bakeraa556b02017-03-07 16:07:34 -080054
Zack Williams045b63d2019-01-22 16:30:57 -070055 print(" okay")
56
Scott Bakeraa556b02017-03-07 16:07:34 -080057
58xos_grpc_client.start_api_parseargs(test_callback)