Browse Source

Urlfwd isn't a RFC type so it shouldn't have rr text support

pull/930/head
Ross McFarland 3 years ago
parent
commit
1cbcfbf1d3
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 0 additions and 117 deletions
  1. +0
    -42
      octodns/record/__init__.py
  2. +0
    -75
      tests/test_octodns_record.py

+ 0
- 42
octodns/record/__init__.py View File

@ -2282,46 +2282,12 @@ class UrlfwdValue(EqualityTupleMixin, dict):
VALID_MASKS = (0, 1, 2)
VALID_QUERY = (0, 1)
@classmethod
def parse_rr_text(self, value):
try:
code, masking, query, path, target = value.split(' ')
except ValueError:
raise RrParseError()
try:
code = int(code)
except ValueError:
pass
try:
masking = int(masking)
except ValueError:
pass
try:
query = int(query)
except ValueError:
pass
return {
'code': code,
'masking': masking,
'query': query,
'path': path,
'target': target,
}
@classmethod
def validate(cls, data, _type):
if not isinstance(data, (list, tuple)):
data = (data,)
reasons = []
for value in data:
if isinstance(value, str):
# it's hopefully RR formatted, give parsing a try
try:
value = cls.parse_rr_text(value)
except RrParseError as e:
reasons.append(str(e))
# not a dict so no point in continuing
continue
try:
code = int(value['code'])
if code not in cls.VALID_CODES:
@ -2356,8 +2322,6 @@ class UrlfwdValue(EqualityTupleMixin, dict):
return [UrlfwdValue(v) for v in values]
def __init__(self, value):
if isinstance(value, str):
value = self.parse_rr_text(value)
super().__init__(
{
'path': value['path'],
@ -2408,12 +2372,6 @@ class UrlfwdValue(EqualityTupleMixin, dict):
def query(self, value):
self['query'] = value
@property
def rr_text(self):
return (
f'{self.code} {self.masking} {self.query} {self.path} {self.target}'
)
def _equality_tuple(self):
return (self.path, self.target, self.code, self.masking, self.query)


+ 0
- 75
tests/test_octodns_record.py View File

@ -1809,81 +1809,6 @@ class TestRecord(TestCase):
# __repr__ doesn't blow up
a.__repr__()
def test_urlfwd_value_rr_text(self):
# empty string won't parse
with self.assertRaises(RrParseError):
UrlfwdValue.parse_rr_text('')
# single word won't parse
with self.assertRaises(RrParseError):
UrlfwdValue.parse_rr_text('nope')
# 2nd word won't parse
with self.assertRaises(RrParseError):
UrlfwdValue.parse_rr_text('one two')
# 3rd word won't parse
with self.assertRaises(RrParseError):
UrlfwdValue.parse_rr_text('one two three')
# 4th word won't parse
with self.assertRaises(RrParseError):
UrlfwdValue.parse_rr_text('one two three four')
# 6th word won't parse
with self.assertRaises(RrParseError):
UrlfwdValue.parse_rr_text('one two three four five size')
# non-ints
self.assertEqual(
{
'code': 'one',
'masking': 'two',
'query': 'three',
'path': 'four',
'target': 'five',
},
UrlfwdValue.parse_rr_text('one two three four five'),
)
# valid
self.assertEqual(
{
'code': 301,
'masking': 0,
'query': 1,
'path': 'four',
'target': 'five',
},
UrlfwdValue.parse_rr_text('301 0 1 four five'),
)
# make sure that validate is using parse_rr_text when passed string
# value(s)
reasons = UrlfwdRecord.validate(
'urlfwd', 'urlfwd.unit.tests.', {'ttl': 32, 'value': ''}
)
self.assertEqual(['failed to parse string value as RR text'], reasons)
reasons = UrlfwdRecord.validate(
'urlfwd',
'urlfwd.unit.tests.',
{'ttl': 32, 'value': '301 0 1 four five'},
)
self.assertFalse(reasons)
# make sure that the cstor is using parse_rr_text
zone = Zone('unit.tests.', [])
a = UrlfwdRecord(
zone, 'urlfwd', {'ttl': 32, 'value': '301 0 1 four five'}
)
self.assertEqual(301, a.values[0].code)
self.assertEqual(0, a.values[0].masking)
self.assertEqual(1, a.values[0].query)
self.assertEqual('four', a.values[0].path)
self.assertEqual('five', a.values[0].target)
self.assertEqual('301 0 1 four five', a.values[0].rr_text)
def test_record_new(self):
txt = Record.new(
self.zone, 'txt', {'ttl': 44, 'type': 'TXT', 'value': 'some text'}


Loading…
Cancel
Save