Skip to content

Commit

Permalink
Add minimal assertion tests around new “docs” format
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Dzombak <[email protected]>
  • Loading branch information
andrewsardone and cdzombak committed Apr 10, 2018
1 parent eaef702 commit 62a58a8
Showing 1 changed file with 181 additions and 0 deletions.
181 changes: 181 additions & 0 deletions zschema/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,178 @@ def test_invalid(self):
}
}

VALID_DOCS_OUTPUT_FOR_ES_FIELDS = {
"host": {
"category": None,
"doc": None,
"fields": {
"443": {
"category": "heartbleed",
"doc": None,
"fields": {
"heartbleed": {
"category": None,
"doc": None,
"fields": {
"heartbeat_support": {
"category": None,
"detail_type": "Boolean",
"doc": None,
"examples": [],
"required": False,
"type": "boolean"
},
"heartbleed_vulnerable": {
"category": "Vulnerabilities",
"detail_type": "Boolean",
"doc": None,
"examples": [],
"required": False,
"type": "boolean"
},
"timestamp": {
"category": None,
"detail_type": "DateTime",
"doc": None,
"examples": [],
"required": False,
"type": "date"
}
},
"required": False,
"type": "SubRecord"
},
"tls": {
"category": None,
"detail_type": "String",
"doc": None,
"examples": [],
"required": False,
"type": "keyword"
}
},
"required": False,
"type": "SubRecord"
},
"ip": {
"category": None,
"detail_type": "Long",
"doc": "The IP Address of the host",
"examples": [],
"required": False,
"type": "long"
},
"ipstr": {
"category": None,
"detail_type": "IPv4Address",
"doc": None,
"examples": [
"8.8.8.8"
],
"required": True,
"type": "ip"
},
"tags": {
"category": None,
"detail_type": "String",
"doc": None,
"examples": [],
"repeated": True,
"required": False,
"type": "keyword"
}
},
"required": False,
"type": "Record"
}
}

VALID_DOCS_OUTPUT_FOR_BIG_QUERY_FIELDS = {
"host": {
"category": None,
"doc": None,
"fields": {
"ip": {
"category": None,
"detail_type": "Long",
"doc": "The IP Address of the host",
"examples": [],
"required": False,
"type": "INTEGER"
},
"ipstr": {
"category": None,
"detail_type": "IPv4Address",
"doc": None,
"examples": [
"8.8.8.8"
],
"required": True,
"type": "STRING"
},
"p443": {
"category": "heartbleed",
"doc": None,
"fields": {
"heartbleed": {
"category": None,
"doc": None,
"fields": {
"heartbeat_support": {
"category": None,
"detail_type": "Boolean",
"doc": None,
"examples": [],
"required": False,
"type": "BOOLEAN"
},
"heartbleed_vulnerable": {
"category": "Vulnerabilities",
"detail_type": "Boolean",
"doc": None,
"examples": [],
"required": False,
"type": "BOOLEAN"
},
"timestamp": {
"category": None,
"detail_type": "DateTime",
"doc": None,
"examples": [],
"required": False,
"type": "DATETIME"
}
},
"required": False,
"type": "SubRecord"
},
"tls": {
"category": None,
"detail_type": "String",
"doc": None,
"examples": [],
"required": False,
"type": "STRING"
}
},
"required": False,
"type": "SubRecord"
},
"tags": {
"category": None,
"detail_type": "String",
"doc": None,
"examples": [],
"repeated": True,
"required": False,
"type": "STRING"
}
},
"required": False,
"type": "Record"
}
}

VALID_BIG_QUERY = [
{
"fields": [
Expand Down Expand Up @@ -178,6 +350,15 @@ def test_elasticsearch(self):
r = self.host.to_es("host")
self.assertEqual(r, VALID_ELASTIC_SEARCH)

def test_docs_output(self):
global VALID_DOCS_OUTPUT_FOR_ES_FIELDS
r = self.host.docs_es("host")
self.assertEqual(r, VALID_DOCS_OUTPUT_FOR_ES_FIELDS)

global VALID_DOCS_OUTPUT_FOR_BIG_QUERY_FIELDS
r = self.host.docs_bq("host")
self.assertEqual(r, VALID_DOCS_OUTPUT_FOR_BIG_QUERY_FIELDS)

def test_validation_known_good(self):
test = {
"ipstr":"141.212.120.1",
Expand Down

0 comments on commit 62a58a8

Please sign in to comment.