Skip to content
This repository was archived by the owner on Aug 28, 2020. It is now read-only.

Commit d7a0772

Browse files
committed
Use Mock Config Object instead of actual config file
This way, changes to the local config won't affect the tests.
1 parent 42126ca commit d7a0772

File tree

1 file changed

+53
-22
lines changed

1 file changed

+53
-22
lines changed

test/test.py

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import unittest2 as unittest
55
except ImportError:
66
import unittest
7+
78
if os.environ.get('TRAVIS') is None:
89
from db_connector import DBConnector, GitHubData, PackageManagerData
910
from config import Config
1011
from github import GitHub
1112
from package_managers import PackageManagers
1213
from sendgrid_email import SendGrid
14+
import vcr
1315
try:
1416
basestring
1517
except NameError:
@@ -45,40 +47,68 @@ def test_initialization(self):
4547
self.assertTrue(isinstance(self.config.email_subject, basestring))
4648
self.assertTrue(isinstance(self.config.email_body, basestring))
4749

50+
# This dummy config prevents changes to the user-defined config
51+
# from changing their results when doing testing.
52+
MOCK_DATA = {
53+
'package_urls': [
54+
"https://www.nuget.org/packages/SendGrid",
55+
"https://www.nuget.org/packages/SendGrid.CSharp.HTTP.Client",
56+
"https://www.npmjs.com/package/sendgrid",
57+
"https://www.npmjs.com/package/sendgrid-rest",
58+
"https://packagist.org/packages/sendgrid/sendgrid",
59+
"https://packagist.org/packages/sendgrid/php-http-client",
60+
"https://pypi.python.org/pypi/sendgrid",
61+
"https://pypi.python.org/pypi/python_http_client",
62+
"https://pypi.python.org/pypi/open_source_library_data_collector",
63+
"https://rubygems.org/gems/sendgrid-ruby",
64+
"https://rubygems.org/gems/ruby_http_client",
65+
],
66+
'github_config': {
67+
'user': 'sendgrid',
68+
'repositories': [
69+
"sendgrid-csharp",
70+
# "smtpapi-csharp"
71+
]
72+
}
73+
}
74+
4875

4976
class TestDBConnector(unittest.TestCase):
77+
5078
def setUp(self):
5179
if os.environ.get('TRAVIS') == None:
5280
self.db = DBConnector()
5381

54-
def test_add_and_delete_data(self):
82+
def test_add_and_delete_github_data(self):
5583
if os.environ.get('TRAVIS') == None:
5684
github_data_import = GitHubData(
57-
date_updated=datetime.datetime.now(),
58-
language='repo_name',
59-
pull_requests=0,
60-
open_issues=0,
61-
number_of_commits=0,
62-
number_of_branches=0,
63-
number_of_releases=0,
64-
number_of_contributors=0,
65-
number_of_watchers=0,
66-
number_of_stargazers=0,
67-
number_of_forks=0
68-
)
85+
date_updated=datetime.datetime.now(),
86+
language='repo_name',
87+
pull_requests=0,
88+
open_issues=0,
89+
number_of_commits=0,
90+
number_of_branches=0,
91+
number_of_releases=0,
92+
number_of_contributors=0,
93+
number_of_watchers=0,
94+
number_of_stargazers=0,
95+
number_of_forks=0
96+
)
6997
res = self.db.add_data(github_data_import)
7098
self.assertTrue(isinstance(res, GitHubData))
7199
res = self.db.delete_data(res.id, 'github_data')
72100
self.assertTrue(res)
73101

102+
def test_add_and_delete_package_data(self):
103+
if os.environ.get('TRAVIS') == None:
74104
packagedata = PackageManagerData(
75-
date_updated=datetime.datetime.now(),
76-
csharp_downloads=0,
77-
nodejs_downloads=0,
78-
php_downloads=0,
79-
python_downloads=0,
80-
ruby_downloads=0
81-
)
105+
date_updated=datetime.datetime.now(),
106+
csharp_downloads=0,
107+
nodejs_downloads=0,
108+
php_downloads=0,
109+
python_downloads=0,
110+
ruby_downloads=0
111+
)
82112
res = self.db.add_data(packagedata)
83113
self.assertTrue(isinstance(res, PackageManagerData))
84114
res = self.db.delete_data(res.id, 'package_manager_data')
@@ -100,8 +130,9 @@ def setUp(self):
100130

101131
def test_update_library_data(self):
102132
if os.environ.get('TRAVIS') == None:
103-
res = self.github.update_library_data(self.config.github_user,
104-
self.config.github_repos[0])
133+
config = MOCK_DATA['github_config']
134+
res = self.github.update_library_data(config['user'],
135+
config['repositories'][0])
105136
self.assertTrue(isinstance(res, GitHubData))
106137
res = self.db.delete_data(res.id, 'github_data')
107138
self.assertTrue(res)

0 commit comments

Comments
 (0)