comparison venv/lib/python2.7/site-packages/github/tests/Gist.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 # -*- coding: utf-8 -*-
2
3 # ########################## Copyrights and license ############################
4 # #
5 # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> #
6 # Copyright 2012 Zearin <zearin@gonk.net> #
7 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
8 # #
9 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ #
10 # #
11 # PyGithub is free software: you can redistribute it and/or modify it under #
12 # the terms of the GNU Lesser General Public License as published by the Free #
13 # Software Foundation, either version 3 of the License, or (at your option) #
14 # any later version. #
15 # #
16 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
18 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
19 # details. #
20 # #
21 # You should have received a copy of the GNU Lesser General Public License #
22 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
23 # #
24 # ##############################################################################
25
26 import Framework
27
28 import github
29 import datetime
30
31
32 class Gist(Framework.TestCase):
33 def testAttributes(self):
34 gist = self.g.get_gist("6296732")
35 self.assertEqual(gist.comments, 0)
36 self.assertEqual(gist.created_at, datetime.datetime(2013, 8, 21, 16, 28, 24))
37 self.assertEqual(gist.description, "Github API")
38 self.assertEqual(gist.files.keys(), ["GithubAPI.lua"])
39 self.assertEqual(gist.files["GithubAPI.lua"].size, 21229)
40 self.assertEqual(gist.files["GithubAPI.lua"].filename, "GithubAPI.lua")
41 self.assertEqual(gist.files["GithubAPI.lua"].language, "Lua")
42 self.assertEqual(gist.files["GithubAPI.lua"].content[:10], "-- GithubA")
43 self.assertEqual(gist.files["GithubAPI.lua"].raw_url, "https://gist.githubusercontent.com/jacquev6/6296732/raw/88aafa25fb28e17013054a117354a37f0d78963c/GithubAPI.lua")
44 self.assertEqual(gist.forks, [])
45 self.assertEqual(gist.git_pull_url, "https://gist.github.com/6296732.git")
46 self.assertEqual(gist.git_push_url, "https://gist.github.com/6296732.git")
47 self.assertEqual(len(gist.history), 1)
48 self.assertEqual(gist.history[0].change_status.additions, 793)
49 self.assertEqual(gist.history[0].change_status.deletions, 0)
50 self.assertEqual(gist.history[0].change_status.total, 793)
51 self.assertEqual(gist.history[0].committed_at, datetime.datetime(2013, 8, 21, 16, 12, 27))
52 self.assertEqual(gist.history[0].url, "https://api.github.com/gists/6296732/c464aecd7fea16684e935607eeea7ae4f8caa0e2")
53 self.assertEqual(gist.history[0].user, None)
54 self.assertEqual(gist.history[0].owner.login, "jacquev6")
55 self.assertEqual(gist.history[0].version, "c464aecd7fea16684e935607eeea7ae4f8caa0e2")
56 self.assertEqual(gist.html_url, "https://gist.github.com/6296732")
57 self.assertEqual(gist.id, "6296732")
58 self.assertTrue(gist.public)
59 self.assertEqual(gist.updated_at, datetime.datetime(2013, 8, 21, 16, 28, 24))
60 self.assertEqual(gist.url, "https://api.github.com/gists/6296732")
61 self.assertEqual(gist.user, None)
62 self.assertEqual(gist.owner.login, "jacquev6")
63 self.assertEqual(gist.git_pull_url, "https://gist.github.com/6296732.git")
64 self.assertEqual(gist.git_push_url, "https://gist.github.com/6296732.git")
65 self.assertEqual(gist.html_url, "https://gist.github.com/6296732")
66 self.assertEqual(gist.url, "https://api.github.com/gists/6296732")
67
68 def testEditWithoutParameters(self):
69 gist = self.g.get_gist("2729810")
70 gist.edit()
71 self.assertEqual(gist.description, "Gist created by PyGithub")
72 self.assertEqual(gist.updated_at, datetime.datetime(2012, 5, 19, 7, 0, 58))
73
74 def testEditWithAllParameters(self):
75 gist = self.g.get_gist("2729810")
76 gist.edit("Description edited by PyGithub", {"barbaz.txt": github.InputFileContent("File also created by PyGithub")})
77 self.assertEqual(gist.description, "Description edited by PyGithub")
78 self.assertEqual(gist.updated_at, datetime.datetime(2012, 5, 19, 7, 6, 10))
79 self.assertEqual(set(gist.files.keys()), set(["foobar.txt", "barbaz.txt"]))
80
81 def testDeleteFile(self):
82 gist = self.g.get_gist("5339374")
83 self.assertEqual(sorted(gist.files.keys()), ["bar.txt", "foo.txt"])
84 gist.edit(files={"foo.txt": None})
85 self.assertEqual(gist.files.keys(), ["bar.txt"])
86
87 def testRenameFile(self):
88 gist = self.g.get_gist("5339374")
89 self.assertEqual(gist.files.keys(), ["bar.txt"])
90 gist.edit(files={"bar.txt": github.InputFileContent(gist.files["bar.txt"].content, new_name="baz.txt")})
91 self.assertEqual(gist.files.keys(), ["baz.txt"])
92
93 def testCreateComment(self):
94 gist = self.g.get_gist("2729810")
95 comment = gist.create_comment("Comment created by PyGithub")
96 self.assertEqual(comment.id, 323629)
97
98 def testGetComments(self):
99 gist = self.g.get_gist("2729810")
100 self.assertListKeyEqual(gist.get_comments(), lambda c: c.id, [323637])
101
102 def testStarring(self):
103 gist = self.g.get_gist("2729810")
104 self.assertFalse(gist.is_starred())
105 gist.set_starred()
106 self.assertTrue(gist.is_starred())
107 gist.reset_starred()
108 self.assertFalse(gist.is_starred())
109
110 def testFork(self):
111 gist = self.g.get_gist("6296553") # Random gist
112 myGist = gist.create_fork()
113 self.assertEqual(myGist.id, "6296732")
114 self.assertEqual(myGist.fork_of, None) # WTF
115 sameGist = self.g.get_gist("6296732")
116 self.assertEqual(sameGist.fork_of.id, "6296553")
117
118 def testDelete(self):
119 gist = self.g.get_gist("2729810")
120 gist.delete()