-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
66 lines (49 loc) · 2.09 KB
/
tests.py
File metadata and controls
66 lines (49 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import gitloc
import json
import requests
import unittest
class ParseUrlTests(unittest.TestCase):
def setUp(self):
gitloc.app.config['TESTING'] = True
self.app = gitloc.app.test_client()
def test_missing_url(self):
response = self.app.get('/repo')
json_response = json.loads(response.data.decode('utf-8'))
self.assertEqual(json_response, {'error': 'missing_parameters'})
def test_invalid_url(self):
response = self.app.get('/repo?url=github.com%2F404')
json_response = json.loads(response.data.decode('utf-8'))
self.assertEqual(json_response, {'error': 'invalid_url'})
class GetZipTests(unittest.TestCase):
def setUp(self):
gitloc.app.config['TESTING'] = True
self.app = gitloc.app.test_client()
def test_successful_download(self):
self.assertEqual(len(gitloc._get_zip('octocat', 'Hello-World')), 351)
def test_invalid_repo(self):
try:
gitloc._get_zip('fakeuser', 'fakerepo')
self.assertFail()
except requests.exceptions.HTTPError as e:
self.assertEqual(e.response.status_code, 404)
class GithubLocTests(unittest.TestCase):
def setUp(self):
gitloc.app.config['TESTING'] = True
self.app = gitloc.app.test_client()
def test_invalid_repo(self):
response = self.app.get('loc/github?owner=fakeowner&repo=fakerepo')
json_response = json.loads(response.data.decode('utf-8'))
self.assertEqual(json_response, {'error': 'invalid_repo'})
def test_missing_parameters(self):
response = self.app.get('loc/github?repo=fakerepo')
json_response = json.loads(response.data.decode('utf-8'))
self.assertEqual(json_response, {'error': 'missing_parameters'})
def test_loc(self):
response = self.app.get('loc/github?owner=octocat&repo=Spoon-Knife')
json_response = json.loads(response.data.decode('utf-8'))
self.assertCountEqual(
json_response["languages"].keys(),
['html', 'css']
)
if __name__ == '__main__':
unittest.main(warnings='ignore')