SEBA-271 unit test for field numbers
Change-Id: Idbb6e522fddea16e8ccb265446488ba07b427198
diff --git a/lib/xos-genx/xos-genx-tests/test_generator.py b/lib/xos-genx/xos-genx-tests/test_generator.py
index 9b1a44a..1a81f8a 100644
--- a/lib/xos-genx/xos-genx-tests/test_generator.py
+++ b/lib/xos-genx/xos-genx-tests/test_generator.py
@@ -32,9 +32,11 @@
BASE_XPROTO = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xproto/base.xproto")
TEST_XPROTO = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xproto/test.xproto")
+FIELDTEST_XPROTO = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xproto/fieldtest.xproto")
SKIP_DJANGO_XPROTO = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xproto/skip_django.xproto")
VROUTER_XPROTO = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xproto/vrouterport.xproto")
TEST_TARGET = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xtarget/test.xtarget")
+FIELDTEST_TARGET = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xtarget/fieldtest.xtarget")
SPLIT_TARGET = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/xtarget/split.xtarget")
TEST_ATTICS = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/attics/")
@@ -205,6 +207,28 @@
self.assertLess(base_line, xosmodel_line)
self.assertLess(xosmodel_line, vrouter_line)
+ def test_field_numbers(self):
+ args = FakeArgs()
+ args.files = [FIELDTEST_XPROTO]
+ args.target = FIELDTEST_TARGET
+ output = XOSProcessor.process(args)
+
+ def _assert_field(modelname, fieldname, id):
+ self.assertIn("%s,%s,%s" % (modelname, fieldname, id), output)
+
+ _assert_field("Site", "id", 1)
+ _assert_field("Site", "base_field", 2)
+ _assert_field("Site", "base_field2", 3)
+ _assert_field("Site", "otherstuff_field", 102)
+ _assert_field("Site", "slice_field", 201)
+ _assert_field("Site", "slices_ids", 1002)
+
+ _assert_field("Slice", "id", 1)
+ _assert_field("Slice", "base_field", 2)
+ _assert_field("Slice", "base_field2", 3)
+ _assert_field("Slice", "slice_field", 101)
+ _assert_field("Slice", "site", 102)
+
if __name__ == '__main__':
unittest.main()
diff --git a/lib/xos-genx/xos-genx-tests/xproto/fieldtest.xproto b/lib/xos-genx/xos-genx-tests/xproto/fieldtest.xproto
new file mode 100644
index 0000000..2d576e3
--- /dev/null
+++ b/lib/xos-genx/xos-genx-tests/xproto/fieldtest.xproto
@@ -0,0 +1,19 @@
+option app_label = "core";
+
+message XOSBase {
+ optional string base_field = 2 [default = "stuff", max_length = 1024];
+ optional string base_field2 = 3 [default = "stuff", max_length = 1024];
+}
+
+message Otherstuff {
+ optional string otherstuff_field = 2 [default = "stuff", max_length = 1024];
+}
+
+message Site (XOSBase, Otherstuff) {
+ optional string slice_field = 1 [default = "other stuff", max_length=1024];
+}
+
+message Slice (XOSBase) {
+ optional string slice_field = 1 [default = "other stuff", max_length=1024];
+ required manytoone site->Site:slices = 2:1002 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
+}
diff --git a/lib/xos-genx/xos-genx-tests/xtarget/fieldtest.xtarget b/lib/xos-genx/xos-genx-tests/xtarget/fieldtest.xtarget
new file mode 100644
index 0000000..89e8e9e
--- /dev/null
+++ b/lib/xos-genx/xos-genx-tests/xtarget/fieldtest.xtarget
@@ -0,0 +1,8 @@
+{% for object in proto.messages|sort(attribute='name') %}
+{%- for field in xproto_fields(object, proto.message_table) | sort(attribute='id') %}
+{{ object.name }},{{ field.name }},{{ field.id }}
+{%- endfor %}
+{%- for field in xproto_rlinks(object, proto.message_table) | sort(attribute='id') %}
+{{ object.name}},{{ field.src_port }}_ids,{{ field.id }}
+{%- endfor %}
+{%- endfor %}