mirror of
				https://github.com/github/octodns.git
				synced 2024-05-11 05:55:00 +00:00 
			
		
		
		
	Allow/reject use sets and now have tests
This commit is contained in:
		| @@ -5,14 +5,14 @@ | ||||
| from __future__ import absolute_import, division, print_function, \ | ||||
|     unicode_literals | ||||
| 
 | ||||
| from . import BaseProcessor | ||||
| from .base import BaseProcessor | ||||
| 
 | ||||
| 
 | ||||
| class TypeAllowlistFilter(BaseProcessor): | ||||
| 
 | ||||
|     def __init__(self, name, allowlist): | ||||
|         super(TypeAllowlistFilter, self).__init__(name) | ||||
|         self.allowlist = allowlist | ||||
|         self.allowlist = set(allowlist) | ||||
| 
 | ||||
|     def _process(self, zone, *args, **kwargs): | ||||
|         ret = self._clone_zone(zone) | ||||
| @@ -30,7 +30,7 @@ class TypeRejectlistFilter(BaseProcessor): | ||||
| 
 | ||||
|     def __init__(self, name, rejectlist): | ||||
|         super(TypeRejectlistFilter, self).__init__(name) | ||||
|         self.rejectlist = rejectlist | ||||
|         self.rejectlist = set(rejectlist) | ||||
| 
 | ||||
|     def _process(self, zone, *args, **kwargs): | ||||
|         ret = self._clone_zone(zone) | ||||
							
								
								
									
										92
									
								
								tests/test_octodns_processor_filter.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								tests/test_octodns_processor_filter.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| # | ||||
| # | ||||
| # | ||||
|  | ||||
| from __future__ import absolute_import, division, print_function, \ | ||||
|     unicode_literals | ||||
|  | ||||
| from logging import getLogger | ||||
| from six import StringIO, text_type | ||||
| from unittest import TestCase | ||||
|  | ||||
| from octodns.processor.filter import TypeAllowlistFilter, TypeRejectlistFilter | ||||
| from octodns.record import Record | ||||
| from octodns.zone import Zone | ||||
|  | ||||
| zone = Zone('unit.tests.', []) | ||||
| for record in [ | ||||
|     Record.new(zone, 'a', { | ||||
|         'ttl': 30, | ||||
|         'type': 'A', | ||||
|         'value': '1.2.3.4', | ||||
|     }), | ||||
|     Record.new(zone, 'aaaa', { | ||||
|         'ttl': 30, | ||||
|         'type': 'AAAA', | ||||
|         'value': '::1', | ||||
|     }), | ||||
|     Record.new(zone, 'txt', { | ||||
|         'ttl': 30, | ||||
|         'type': 'TXT', | ||||
|         'value': 'Hello World!', | ||||
|     }), | ||||
|     Record.new(zone, 'a2', { | ||||
|         'ttl': 30, | ||||
|         'type': 'A', | ||||
|         'value': '2.3.4.5', | ||||
|     }), | ||||
|     Record.new(zone, 'txt2', { | ||||
|         'ttl': 30, | ||||
|         'type': 'TXT', | ||||
|         'value': 'That will do', | ||||
|     }), | ||||
| ]: | ||||
|     zone.add_record(record) | ||||
|  | ||||
|  | ||||
| class TestTypeAllowListFilter(TestCase): | ||||
|  | ||||
|     def test_basics(self): | ||||
|         filter_a = TypeAllowlistFilter('only-a', set(('A'))) | ||||
|  | ||||
|         got = filter_a.process_source_zone(zone) | ||||
|         self.assertEquals(['a', 'a2'], sorted([r.name for r in got.records])) | ||||
|  | ||||
|         filter_aaaa = TypeAllowlistFilter('only-aaaa', ('AAAA',)) | ||||
|         got = filter_aaaa.process_source_zone(zone) | ||||
|         self.assertEquals(['aaaa'], sorted([r.name for r in got.records])) | ||||
|  | ||||
|         filter_txt = TypeAllowlistFilter('only-txt', ['TXT']) | ||||
|         got = filter_txt.process_source_zone(zone) | ||||
|         self.assertEquals(['txt', 'txt2'], | ||||
|                           sorted([r.name for r in got.records])) | ||||
|  | ||||
|         filter_a_aaaa = TypeAllowlistFilter('only-aaaa', set(('A', 'AAAA'))) | ||||
|         got = filter_a_aaaa.process_source_zone(zone) | ||||
|         self.assertEquals(['a', 'a2', 'aaaa'], | ||||
|                           sorted([r.name for r in got.records])) | ||||
|  | ||||
|  | ||||
| class TestTypeRejectListFilter(TestCase): | ||||
|  | ||||
|     def test_basics(self): | ||||
|         filter_a = TypeRejectlistFilter('not-a', set(('A'))) | ||||
|  | ||||
|         got = filter_a.process_source_zone(zone) | ||||
|         self.assertEquals(['aaaa', 'txt', 'txt2'], | ||||
|                           sorted([r.name for r in got.records])) | ||||
|  | ||||
|         filter_aaaa = TypeRejectlistFilter('not-aaaa', ('AAAA',)) | ||||
|         got = filter_aaaa.process_source_zone(zone) | ||||
|         self.assertEquals(['a', 'a2', 'txt', 'txt2'], | ||||
|                           sorted([r.name for r in got.records])) | ||||
|  | ||||
|         filter_txt = TypeRejectlistFilter('not-txt', ['TXT']) | ||||
|         got = filter_txt.process_source_zone(zone) | ||||
|         self.assertEquals(['a', 'a2', 'aaaa'], | ||||
|                           sorted([r.name for r in got.records])) | ||||
|  | ||||
|         filter_a_aaaa = TypeRejectlistFilter('not-a-aaaa', set(('A', 'AAAA'))) | ||||
|         got = filter_a_aaaa.process_source_zone(zone) | ||||
|         self.assertEquals(['txt', 'txt2'], | ||||
|                           sorted([r.name for r in got.records])) | ||||
		Reference in New Issue
	
	Block a user