Traffic.py
1 ############################ Copyrights and license ############################ 2 # # 3 # Copyright 2018 Justin Kufro <jkufro@andrew.cmu.edu> # 4 # Copyright 2018 Ivan Minno <iminno@andrew.cmu.edu> # 5 # Copyright 2018 Zilei Gu <zileig@andrew.cmu.edu> # 6 # Copyright 2018 Yves Zumbach <yzumbach@andrew.cmu.edu> # 7 # Copyright 2018 Leying Chen <leyingc@andrew.cmu.edu> # 8 # # 9 # This file is part of PyGithub. # 10 # http://pygithub.readthedocs.io/ # 11 # # 12 # PyGithub is free software: you can redistribute it and/or modify it under # 13 # the terms of the GNU Lesser General Public License as published by the Free # 14 # Software Foundation, either version 3 of the License, or (at your option) # 15 # any later version. # 16 # # 17 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # 18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # 19 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # 20 # details. # 21 # # 22 # You should have received a copy of the GNU Lesser General Public License # 23 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # 24 # # 25 ################################################################################ 26 27 from datetime import datetime, timezone 28 29 from . import Framework 30 31 32 class Traffic(Framework.TestCase): 33 def setUp(self): 34 super().setUp() 35 self.user = self.g.get_user() 36 self.repo = self.user.get_repo("PyGithub") 37 38 def testGetReferrers(self): 39 referrerResponse = self.repo.get_top_referrers() 40 self.assertGreaterEqual(len(referrerResponse), 1) 41 self.assertEqual(referrerResponse[0].uniques, 1) 42 self.assertEqual(referrerResponse[0].referrer, "github.com") 43 self.assertEqual(referrerResponse[0].count, 5) 44 self.assertEqual( 45 repr(referrerResponse[0]), 46 'Referrer(uniques=1, referrer="github.com", count=5)', 47 ) 48 49 def testGetPaths(self): 50 pathsResponse = self.repo.get_top_paths() 51 self.assertEqual(len(pathsResponse), 10) 52 self.assertEqual(pathsResponse[0].uniques, 4) 53 self.assertEqual(pathsResponse[0].count, 23) 54 self.assertEqual(pathsResponse[0].path, "/jkufro/PyGithub") 55 self.assertEqual( 56 pathsResponse[0].title, 57 "jkufro/PyGithub: Typed interactions with the GitHub API v3", 58 ) 59 self.assertEqual( 60 repr(pathsResponse[0]), 61 'Path(uniques=4, title="jkufro/PyGithub: Typed interactions with the GitHub API v3", path="/jkufro/PyGithub", count=23)', 62 ) 63 64 def testGetViews(self): 65 viewsResponse = self.repo.get_views_traffic() 66 self.assertEqual(viewsResponse["count"], 93) 67 self.assertEqual(viewsResponse["uniques"], 4) 68 self.assertEqual(len(viewsResponse["views"]), 5) 69 view_obj = viewsResponse["views"][0] 70 self.assertEqual(view_obj.uniques, 4) 71 self.assertEqual( 72 view_obj.timestamp, 73 datetime(2018, 11, 27, 0, 0, tzinfo=timezone.utc), 74 ) 75 self.assertEqual(view_obj.count, 56) 76 self.assertEqual( 77 repr(view_obj), 78 "View(uniques=4, timestamp=2018-11-27 00:00:00+00:00, count=56)", 79 ) 80 81 def testGetClones(self): 82 clonesResponse = self.repo.get_clones_traffic() 83 self.assertEqual(clonesResponse["count"], 4) 84 self.assertEqual(clonesResponse["uniques"], 4) 85 self.assertEqual(len(clonesResponse["clones"]), 1) 86 clone_obj = clonesResponse["clones"][0] 87 self.assertEqual(clone_obj.uniques, 4) 88 self.assertEqual( 89 clone_obj.timestamp, 90 datetime(2018, 11, 27, 0, 0, tzinfo=timezone.utc), 91 ) 92 self.assertEqual(clone_obj.count, 4) 93 self.assertEqual( 94 repr(clone_obj), 95 "Clones(uniques=4, timestamp=2018-11-27 00:00:00+00:00, count=4)", 96 )