Skip to content

Commit 67d5153

Browse files
committed
Found new attributes on Blobs. Start git tests.
1 parent 95498db commit 67d5153

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

github3/git.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ class Blob(GitHubObject):
1616
"""The :class:`Blob <Blob>` object."""
1717
def __init__(self, blob):
1818
super(Blob, self).__init__(blob)
19+
self._api = blob.get('url')
1920
self._content = blob.get('content')
2021
self._enc = blob.get('encoding')
2122
if self._enc == 'base64':
2223
self._decoded = b64decode(self._content)
2324
else:
2425
self._decoded = self._content
26+
self._size = blob.get('size')
27+
self._sha = blob.get('sha')
2528

2629
def __repr__(self):
27-
return '<Blob [{0:.10}]>'.format(self._decoded)
30+
return '<Blob [{0:.10}]>'.format(self._sha)
2831

2932
@property
3033
def content(self):
@@ -41,6 +44,16 @@ def encoding(self):
4144
"""Encoding of the raw content."""
4245
return self._enc
4346

47+
@property
48+
def sha(self):
49+
"""SHA1 of the blob"""
50+
return self._sha
51+
52+
@property
53+
def size(self):
54+
"""Size of the blob in bytes"""
55+
return self._size
56+
4457

4558
class GitData(GitHubCore):
4659
"""The :class:`GitData <GitData>` object. This isn't directly returned to

tests/test_git.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import base
2+
from expecter import expect
3+
import github3
4+
from github3 import Commit, Blob, Reference, Tag, Tree, Hash, GitObject
5+
6+
7+
class TestGit(base.BaseTest):
8+
def setUp(self):
9+
super(TestGit, self).setUp()
10+
self.todor = self.g.repository(self.sigm, self.todo)
11+
12+
def test_blob(self):
13+
r = self.todor
14+
blob = r.blob('f737918b90118a6aea991f89f444b150a2360393')
15+
expect(blob).isinstance(Blob)
16+
self.assertAreNotNone(blob, 'content', 'decoded', 'encoding', 'sha',
17+
'sized')
18+
19+
with expect.raises(github3.GitHubError):
20+
r.create_blob('Foo bar bogus', 'utf-8')
21+
22+
def test_commit(self):
23+
r = self.todor
24+
commit = r.commit('04d55444a3ec06ca8d2aa0a5e333cdaf27113254')
25+
expect(commit).isinstance(Commit)
26+
self.assertAreNotNone(commit, 'author', 'committer', 'tree',
27+
'message', 'parents', 'sha')
28+
29+
def test_tag(self):
30+
r = self.todor
31+
tag = r.tag('6a53c72920c15e196d9a91302bdee2acbe6b44c')
32+
expect(tag).isinstance(Tag)
33+
self.assertAreNotNone(tag, 'message', 'object', 'tag', 'tagger',
34+
'sha')
35+
36+
def test_tree_and_hash(self):
37+
r = self.todor
38+
tree = r.tree('31e862095dffa60744f1ce16a431ea040381f053')
39+
expect(tree).isinstance(Tree)
40+
self.assertAreNotNone(tree, 'sha', 'message', 'object', 'tag',
41+
'tagger')
42+
expect(tree.object).isinstance(GitObject)
43+
hashes = tree.tree # Odd access, right?
44+
for h in hashes:
45+
expect(h).isinstance(Hash)
46+
47+
def test_refs(self):
48+
r = self.todor
49+
ref = r.ref('heads/development')
50+
expect(ref).isinstance(Reference)

0 commit comments

Comments
 (0)