-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify Message (optional parse_headers) and UnicastPrefixes (optional validation and required_fields) #10
Open
Matvey-Kuk
wants to merge
6
commits into
SNAS:master
Choose a base branch
from
Matvey-Kuk:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a5c5ef
Ability to disable validation
Matvey-Kuk 2f95ad8
Select fields when retreive UnicastPrefixes
Matvey-Kuk cae5c1a
Comments for new features
Matvey-Kuk 7a50909
Merge branch 'master' of github.com:OpenBMP/openbmp-python-api-message
Matvey-Kuk 8e564fc
UnitTests for Message (optional parse_headers) and UnicastPrefixes (o…
Matvey-Kuk df30ccc
Making fixture writer optional
Matvey-Kuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import unittest | ||
|
||
|
||
class FixturesBasedTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
with open('fixtures/unicast_prefixes_message', 'r') as unicast_prefix_message_file: | ||
self.unicast_prefix_message = unicast_prefix_message_file.read() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
V: 1.5 | ||
C_HASH_ID: 9ae8148974c9ca01ec9271753426d214 | ||
L: 290976 | ||
R: 2 | ||
|
||
add 465863 2783130a95f3ee3c238f38eb1b898b81 eee2f394c09f96c2453bf83989eaa1a2 172.20.0.1 d651b1d601e34826247374cb1430c91c 7aefefa6df92a1fccf2fd8a50d8900de 12.12.12.12 1403 2017-06-22 23:33:04.101567 12.12.12.0 20 1 igp 1403 999 777 3 9829 14.14.14.14 0 0 14032:1299 0 1 0 1 1 | ||
add 465864 b1c8a35dcec465d155e6d31f190153fa eee2f394c09f96c2453bf83989eaa1a2 172.20.0.1 d651b1d601e34826247374cb1430c91c 7aefefa6df92a1fccf2fd8a50d8900de 12.12.123.123 1403 2017-06-22 23:33:04.101567 12.12.123.0 22 1 igp 1403 999 777 3 9829 14.14.14.144 0 0 14032:1299 0 1 0 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from FixturesBasedTestCase import FixturesBasedTestCase | ||
|
||
from openbmp.api.parsed.message import Message | ||
|
||
|
||
class MessageTest(FixturesBasedTestCase): | ||
|
||
def test_headers_parsing(self): | ||
""" | ||
Test default Message headers parsing | ||
""" | ||
message = Message(self.unicast_prefix_message) | ||
|
||
self.assertEqual(1.5, message.version) | ||
self.assertEqual("9ae8148974c9ca01ec9271753426d214", message.collector_hash_id) | ||
self.assertEqual(290976, message.length) | ||
self.assertEqual(2, message.records) | ||
|
||
def test_disabled_headers_parsing(self): | ||
""" | ||
Test disabled Message headers parsing | ||
""" | ||
message = Message(self.unicast_prefix_message, parse_headers=False) | ||
|
||
self.assertEqual(0.0, message.version) | ||
self.assertEqual("", message.collector_hash_id) | ||
self.assertEqual(0, message.length) | ||
self.assertEqual(0, message.records) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from FixturesBasedTestCase import FixturesBasedTestCase | ||
|
||
from openbmp.api.parsed.message import Message, UnicastPrefix | ||
|
||
|
||
class UnicastPrefixTest(FixturesBasedTestCase): | ||
|
||
def test_default_parsing(self): | ||
""" | ||
Test default UnicastPrefix parsing | ||
""" | ||
message = Message(self.unicast_prefix_message) | ||
unicast_prefixes = UnicastPrefix(message) | ||
row_map = unicast_prefixes.get_row_map() | ||
|
||
self.assertEqual(2, len(row_map)) | ||
|
||
self.assertEqual("12.12.12.0", row_map[0]['prefix']) | ||
self.assertEqual(20, row_map[0]['prefix_len']) | ||
|
||
self.assertEqual("12.12.123.0", row_map[1]['prefix']) | ||
self.assertEqual(22, row_map[1]['prefix_len']) | ||
|
||
def test_parsing_without_validation(self): | ||
""" | ||
If disable validation, it should still produce the same output but | ||
numerical fields should be serializes as String | ||
""" | ||
message = Message(self.unicast_prefix_message) | ||
unicast_prefixes = UnicastPrefix(message, validate=False) | ||
row_map = unicast_prefixes.get_row_map() | ||
|
||
self.assertEqual("20", row_map[0]['prefix_len']) | ||
|
||
def test_parsing_with_required_fields(self): | ||
""" | ||
Test how UnicastPrefix works with custom required_fields parameter | ||
""" | ||
message = Message(self.unicast_prefix_message) | ||
|
||
# Without validation | ||
unicast_prefixes = UnicastPrefix(message, validate=False, required_fields={11: "my_custom_prefix_name"}) | ||
row_map = unicast_prefixes.get_row_map() | ||
|
||
self.assertEqual('20', row_map[0]['my_custom_prefix_name']) | ||
|
||
# With validation | ||
unicast_prefixes = UnicastPrefix(message, validate=True, required_fields={11: "my_custom_prefix_name"}) | ||
row_map = unicast_prefixes.get_row_map() | ||
|
||
self.assertEqual(20, row_map[0]['my_custom_prefix_name']) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like your conflict merge reverted changes that should be here. Please check your merge conflict changes and correct here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimEvens isn't it what I moved to lines 117-122? I don't see anything missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it's tested in "tests/test_unicast_prefix.py"