|
1 | 1 | # -*- coding: utf-8 -*- |
| 2 | +import json |
2 | 3 | import unittest |
3 | 4 |
|
4 | 5 | import intelmq.lib.test as test |
|
40 | 41 | "source.ip": "2002:3ee0:3972:0001::1", |
41 | 42 | "time.observation": "2015-01-01T00:00:00+00:00", |
42 | 43 | } |
43 | | -EXAMPLE_6TO4_OUTPUT = {"__type": "Event", |
44 | | - "source.ip": "2002:3ee0:3972:0001::1", |
45 | | - "source.network": "2002::/16", |
46 | | - "source.asn": 1103, |
47 | | - "source.as_name": "SURFNET-NL SURFnet, The Netherlands, NL", |
48 | | - "time.observation": "2015-01-01T00:00:00+00:00", |
49 | | - } |
50 | | -EXAMPLE_6TO4_OUTPUT_1 = {"__type": "Event", |
51 | | - "source.ip": "2002:3ee0:3972:0001::1", |
52 | | - "source.network": "2002::/16", |
53 | | - "source.asn": 6939, |
54 | | - "source.as_name": "HURRICANE, US", |
55 | | - "time.observation": "2015-01-01T00:00:00+00:00", |
56 | | - } |
57 | 44 | OVERWRITE_OUT = {"__type": "Event", |
58 | 45 | "source.ip": "78.104.144.2", |
59 | 46 | "source.geolocation.cc": "AA", |
@@ -98,20 +85,21 @@ def test_empty_result(self): |
98 | 85 | def test_6to4_result(self): |
99 | 86 | """ |
100 | 87 | Test the whois for an IPv6 to IPv4 network range. |
101 | | - The result can vary, so we test for two possible expected results. |
| 88 | + The result can vary, so we only tests if values exist. |
102 | 89 | """ |
103 | 90 | self.input_message = EXAMPLE_6TO4_INPUT |
104 | 91 | self.run_bot() |
105 | | - try: |
106 | | - self.assertMessageEqual(0, EXAMPLE_6TO4_OUTPUT) |
107 | | - except AssertionError: |
108 | | - self.assertMessageEqual(0, EXAMPLE_6TO4_OUTPUT_1) |
| 92 | + actual = json.loads(self.get_output_queue()[0]) |
| 93 | + self.assertDictContainsSubset(EXAMPLE_6TO4_INPUT, actual) |
| 94 | + self.assertIn("source.asn", actual) |
| 95 | + self.assertIn("source.as_name", actual) |
| 96 | + self.assertIn("source.network", actual) |
109 | 97 |
|
110 | 98 | def test_overwrite(self): |
111 | 99 | self.input_message = EXAMPLE_INPUT.copy() |
112 | 100 | self.input_message["source.geolocation.cc"] = "AA" |
113 | 101 | self.input_message["source.registry"] = "LACNIC" |
114 | | - self.run_bot(parameters={'overwrite' : False}) |
| 102 | + self.run_bot(parameters={'overwrite': False}) |
115 | 103 | self.assertMessageEqual(0, OVERWRITE_OUT) |
116 | 104 |
|
117 | 105 |
|
|
0 commit comments