Skip to content

Commit

Permalink
[backends] Add metadata_id() method
Browse files Browse the repository at this point in the history
  • Loading branch information
sduenas committed Mar 14, 2016
1 parent ccd3e01 commit 9d00cbf
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 9 deletions.
6 changes: 6 additions & 0 deletions perceval/backends/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ def __fetch_and_parse_bug_activity(self, bug_id):
activity = self.parse_bug_activity(raw_activity)
return [event for event in activity]

@staticmethod
def metadata_id(item):
"""Extracts the identifier from a Bugzilla item."""

return item['bug_id'][0]['__text__']

@staticmethod
def metadata_updated_on(item):
"""Extracts and coverts the update time from a Bugzilla item.
Expand Down
6 changes: 6 additions & 0 deletions perceval/backends/gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def _get_reviews(self, last_item):
time.time()-task_init))
return reviews

@staticmethod
def metadata_id(item):
"""Extracts the identifier from a Gerrit item."""

return item['id']

@staticmethod
def metadata_updated_on(item):
"""Extracts and converts the update time from a Gerrit item.
Expand Down
6 changes: 6 additions & 0 deletions perceval/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def __create_and_update_git_repository(self):

return repo

@staticmethod
def metadata_id(item):
"""Extracts the identifier from a Git item."""

return item['commit']

@staticmethod
def metadata_updated_on(item):
"""Extracts the update time from a Git item.
Expand Down
6 changes: 6 additions & 0 deletions perceval/backends/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ def __build_issues(self, issues):
self._users[issue[field]['login']]
yield issue

@staticmethod
def metadata_id(item):
"""Extracts the identifier from a GitHub item."""

return str(item['id'])

@staticmethod
def metadata_updated_on(item):
"""Extracts the update time from a GitHub item.
Expand Down
6 changes: 6 additions & 0 deletions perceval/backends/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ def fetch_from_cache(self):
for issue in issues:
yield issue

@staticmethod
def metadata_id(item):
"""Extracts the identifier from a Jira item."""

return str(item['id'])

@staticmethod
def metadata_updated_on(item):
"""Extracts the update time from a issue item.
Expand Down
6 changes: 6 additions & 0 deletions perceval/backends/mbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def _casedict_to_dict(self, message):

return msg

@staticmethod
def metadata_id(item):
"""Extracts the identifier from a Git item."""

return item[MBox.MESSAGE_ID_FIELD]

@staticmethod
def metadata_updated_on(item):
"""Extracts the update time from a message item.
Expand Down
6 changes: 6 additions & 0 deletions perceval/backends/stackexchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ def fetch_from_cache(self):
for question in questions:
yield question

@staticmethod
def metadata_id(item):
"""Extracts the identifier from a Git item."""

return str(item['question_id'])

@staticmethod
def metadata_updated_on(item):
"""Extracts the update time from a StackExchange item.
Expand Down
8 changes: 8 additions & 0 deletions tests/test_bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ def request_callback(method, uri, headers):
self.assertEqual(bugs[0]['bug_id'][0]['__text__'], '15')
self.assertEqual(len(bugs[0]['activity']), 0)
self.assertEqual(bugs[0]['__metadata__']['origin'], BUGZILLA_SERVER_URL)
self.assertEqual(bugs[0]['__metadata__']['uuid'], '5a8a1e25dfda86b961b4146050883cbfc928f8ec')
self.assertEqual(bugs[0]['__metadata__']['updated_on'], 1248276445.0)

self.assertEqual(bugs[6]['bug_id'][0]['__text__'], '888')
self.assertEqual(len(bugs[6]['activity']), 14)
self.assertEqual(bugs[6]['__metadata__']['origin'], BUGZILLA_SERVER_URL)
self.assertEqual(bugs[6]['__metadata__']['uuid'], 'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
self.assertEqual(bugs[6]['__metadata__']['updated_on'], 1439404330.0)

# Check requests
Expand Down Expand Up @@ -223,11 +225,13 @@ def request_callback(method, uri, headers):
self.assertEqual(bugs[0]['bug_id'][0]['__text__'], '30')
self.assertEqual(len(bugs[0]['activity']), 14)
self.assertEqual(bugs[0]['__metadata__']['origin'], BUGZILLA_SERVER_URL)
self.assertEqual(bugs[0]['__metadata__']['uuid'], '4b166308f205121bc57704032acdc81b6c9bb8b1')
self.assertEqual(bugs[0]['__metadata__']['updated_on'], 1426868155.0)

self.assertEqual(bugs[1]['bug_id'][0]['__text__'], '888')
self.assertEqual(len(bugs[1]['activity']), 0)
self.assertEqual(bugs[1]['__metadata__']['origin'], BUGZILLA_SERVER_URL)
self.assertEqual(bugs[1]['__metadata__']['uuid'], 'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
self.assertEqual(bugs[1]['__metadata__']['updated_on'], 1439404330.0)

# Check requests
Expand Down Expand Up @@ -352,11 +356,13 @@ def request_callback(method, uri, headers):
self.assertEqual(bugs[0]['bug_id'][0]['__text__'], '30')
self.assertEqual(len(bugs[0]['activity']), 14)
self.assertEqual(bugs[0]['__metadata__']['origin'], BUGZILLA_SERVER_URL)
self.assertEqual(bugs[0]['__metadata__']['uuid'], '4b166308f205121bc57704032acdc81b6c9bb8b1')
self.assertEqual(bugs[0]['__metadata__']['updated_on'], 1426868155.0)

self.assertEqual(bugs[1]['bug_id'][0]['__text__'], '888')
self.assertEqual(len(bugs[1]['activity']), 0)
self.assertEqual(bugs[1]['__metadata__']['origin'], BUGZILLA_SERVER_URL)
self.assertEqual(bugs[1]['__metadata__']['uuid'], 'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
self.assertEqual(bugs[1]['__metadata__']['updated_on'], 1439404330.0)

# Check requests
Expand Down Expand Up @@ -474,11 +480,13 @@ def request_callback(method, uri, headers):
self.assertEqual(cached_bugs[0]['bug_id'][0]['__text__'], '15')
self.assertEqual(len(cached_bugs[0]['activity']), 0)
self.assertEqual(cached_bugs[0]['__metadata__']['origin'], BUGZILLA_SERVER_URL)
self.assertEqual(cached_bugs[0]['__metadata__']['uuid'], '5a8a1e25dfda86b961b4146050883cbfc928f8ec')
self.assertEqual(cached_bugs[0]['__metadata__']['updated_on'], 1248276445.0)

self.assertEqual(cached_bugs[6]['bug_id'][0]['__text__'], '888')
self.assertEqual(len(cached_bugs[6]['activity']), 14)
self.assertEqual(cached_bugs[6]['__metadata__']['origin'], BUGZILLA_SERVER_URL)
self.assertEqual(cached_bugs[6]['__metadata__']['uuid'], 'b4009442d38f4241a4e22e3e61b7cd8ef5ced35c')
self.assertEqual(cached_bugs[6]['__metadata__']['updated_on'], 1439404330.0)

self.assertEqual(len(requests), 13)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
sys.path.insert(0, '..')

from perceval.errors import ParseError, RepositoryError
from perceval.backend import uuid
from perceval.backends.git import (Git,
GitCommand,
GitParser,
Expand Down Expand Up @@ -86,9 +87,11 @@ def test_fetch(self):
self.assertEqual(len(commits), len(expected))

for x in range(len(commits)):
expected_uuid = uuid(self.git_path, expected[x][0])
commit = commits[x]
self.assertEqual(commit['commit'], expected[x][0])
self.assertEqual(commit['__metadata__']['origin'], self.git_path)
self.assertEqual(commit['__metadata__']['uuid'], expected_uuid)
self.assertEqual(commit['__metadata__']['updated_on'], expected[x][1])

shutil.rmtree(new_path)
Expand All @@ -109,9 +112,11 @@ def test_fetch_since_date(self):
self.assertEqual(len(commits), len(expected))

for x in range(len(commits)):
expected_uuid = uuid(self.git_path, expected[x][0])
commit = commits[x]
self.assertEqual(commit['commit'], expected[x][0])
self.assertEqual(commit['__metadata__']['origin'], self.git_path)
self.assertEqual(commit['__metadata__']['uuid'], expected_uuid)
self.assertEqual(commit['__metadata__']['updated_on'], expected[x][1])

# Test it using a datetime that includes the timezone
Expand All @@ -123,9 +128,11 @@ def test_fetch_since_date(self):
self.assertEqual(len(commits), len(expected))

for x in range(len(commits)):
expected_uuid = uuid(self.git_path, expected[x][0])
commit = commits[x]
self.assertEqual(commit['commit'], expected[x][0])
self.assertEqual(commit['__metadata__']['origin'], self.git_path)
self.assertEqual(commit['__metadata__']['uuid'], expected_uuid)
self.assertEqual(commit['__metadata__']['updated_on'], expected[x][1])

shutil.rmtree(new_path)
Expand Down Expand Up @@ -160,9 +167,11 @@ def test_fetch_from_file(self):
self.assertEqual(len(commits), len(expected))

for x in range(len(commits)):
expected_uuid = uuid('http://example.com.git', expected[x][0])
commit = commits[x]
self.assertEqual(commit['commit'], expected[x][0])
self.assertEqual(commit['__metadata__']['origin'], 'http://example.com.git')
self.assertEqual(commit['__metadata__']['uuid'], expected_uuid)
self.assertEqual(commit['__metadata__']['updated_on'], expected[x][1])

def test_git_parser(self):
Expand Down
19 changes: 10 additions & 9 deletions tests/test_mbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,23 @@ def test_fetch(self):
backend = MBox('http://example.com/', self.tmp_path)
messages = [m for m in backend.fetch()]

expected = [('<[email protected]>', 1291210000.0),
('<[email protected]>', 1291210000.0),
('<[email protected]>', 1095843820.0),
('<[email protected]>', 1205746505.0),
('<019801ca633f$f4376140$dca623c0$@[email protected]>', 1257992964.0),
('<[email protected]>', 1043881350.0),
('<[email protected]>', 1291210000.0),
('<[email protected]>', 1030123489.0)]
expected = [('<[email protected]>', '86315b479b4debe320b59c881c1e375216cbf333', 1291210000.0),
('<[email protected]>', '86315b479b4debe320b59c881c1e375216cbf333', 1291210000.0),
('<[email protected]>', 'bd0185317b013beb21ad3ea04635de3db72496ad', 1095843820.0),
('<[email protected]>', '51535703010a3e63d5272202942c283394cdebca', 1205746505.0),
('<019801ca633f$f4376140$dca623c0$@[email protected]>', '302e314c07242bb4750351286862f49e758f3e17', 1257992964.0),
('<[email protected]>', 'ddda42422c55d08d56c017a6f128fcd7447484ea', 1043881350.0),
('<[email protected]>', '86315b479b4debe320b59c881c1e375216cbf333', 1291210000.0),
('<[email protected]>', '4e255acab6442424ecbf05cb0feb1eccb587f7de', 1030123489.0)]

self.assertEqual(len(messages), len(expected))

for x in range(len(messages)):
message = messages[x]
self.assertEqual(message['Message-ID'], expected[x][0])
self.assertEqual(message['__metadata__']['origin'], 'http://example.com/')
self.assertEqual(message['__metadata__']['updated_on'], expected[x][1])
self.assertEqual(message['__metadata__']['uuid'], expected[x][1])
self.assertEqual(message['__metadata__']['updated_on'], expected[x][2])

def test_ignore_messages(self):
"""Test if it ignores some messages without mandatory fields"""
Expand Down

0 comments on commit 9d00cbf

Please sign in to comment.