Skip to content
This repository
Browse code

github3.repos @ 94%

  • Loading branch information...
commit 34603ac5656dd9e1717f041076299001cab99c97 1 parent 0268b21
Ian Cordasco authored January 20, 2013
2  github3/repos.py
@@ -1390,7 +1390,7 @@ def saveas(self, path=''):
1390 1390
             else:
1391 1391
                 file_like = False
1392 1392
                 fd = open(path, 'wb')
1393  
-            for chunk in resp.iter_content():
  1393
+            for chunk in resp.iter_content(512):
1394 1394
                 fd.write(chunk)
1395 1395
             if not file_like:
1396 1396
                 fd.close()
65  tests/test_repos.py
@@ -361,8 +361,9 @@ def test_create_status(self):
361 361
 
362 362
         self.login()
363 363
         expect(self.repo.create_status(None, None)).is_None()
364  
-        expect(self.repo.create_status('fakesha', 'success')).isinstance(
365  
-            github3.repos.Status)
  364
+        s = self.repo.create_status('fakesha', 'success')
  365
+        expect(s).isinstance(github3.repos.Status)
  366
+        expect(repr(s)) > ''
366 367
         self.mock_assertions()
367 368
 
368 369
     def test_create_tag(self):
@@ -997,3 +998,63 @@ def test_repr(self):
997 998
 
998 999
     def test_str(self):
999 1000
         expect(str(self.contents)) == self.contents.decoded
  1001
+
  1002
+
  1003
+class TestDownload(BaseCase):
  1004
+    def __init__(self, methodName='runTest'):
  1005
+        super(TestDownload, self).__init__(methodName)
  1006
+        self.dl = github3.repos.Download(load('download'))
  1007
+        self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/"
  1008
+                    "downloads/338893")
  1009
+
  1010
+    def setUp(self):
  1011
+        super(TestDownload, self).setUp()
  1012
+        self.dl = github3.repos.Download(self.dl.to_json(), self.g)
  1013
+
  1014
+    def test_repr(self):
  1015
+        expect(repr(self.dl)) == '<Download [kr.png]>'
  1016
+
  1017
+    def test_delete(self):
  1018
+        self.response('', 204)
  1019
+        self.delete(self.api)
  1020
+
  1021
+        with expect.githuberror():
  1022
+            self.dl.delete()
  1023
+        self.not_called()
  1024
+
  1025
+        self.login()
  1026
+        expect(self.dl.delete()).is_True()
  1027
+        self.mock_assertions()
  1028
+
  1029
+    def test_saveas(self):
  1030
+        self.response('archive', 200)
  1031
+        self.get(self.dl.html_url)
  1032
+
  1033
+        o = mock_open()
  1034
+        with patch('{0}.open'.format(__name__), o, create=True):
  1035
+            with open('archive', 'wb+') as fd:
  1036
+                expect(self.dl.saveas(fd)).is_True()
  1037
+
  1038
+        o.assert_called_once_with('archive', 'wb+')
  1039
+        fd = o()
  1040
+        fd.write.assert_called_once_with(b'archive_data')
  1041
+        self.mock_assertions()
  1042
+
  1043
+        self.request.return_value.raw.seek(0)
  1044
+        self.request.return_value._content_consumed = False
  1045
+
  1046
+        self.dl.saveas()
  1047
+        expect(os.path.isfile(self.dl.name)).is_True()
  1048
+        os.unlink(self.dl.name)
  1049
+        expect(os.path.isfile(self.dl.name)).is_False()
  1050
+
  1051
+        self.request.return_value.raw.seek(0)
  1052
+        self.request.return_value._content_consumed = False
  1053
+
  1054
+        self.dl.saveas('tmp')
  1055
+        expect(os.path.isfile('tmp')).is_True()
  1056
+        os.unlink('tmp')
  1057
+        expect(os.path.isfile('tmp')).is_False()
  1058
+
  1059
+        self.response('', 404)
  1060
+        expect(self.dl.saveas()).is_False()

0 notes on commit 34603ac

Please sign in to comment.
Something went wrong with that request. Please try again.