4
4
import unittest2 as unittest
5
5
except ImportError :
6
6
import unittest
7
+
7
8
if os .environ .get ('TRAVIS' ) is None :
8
9
from db_connector import DBConnector , GitHubData , PackageManagerData
9
10
from config import Config
10
11
from github import GitHub
11
12
from package_managers import PackageManagers
12
13
from sendgrid_email import SendGrid
14
+ import vcr
13
15
try :
14
16
basestring
15
17
except NameError :
@@ -45,40 +47,68 @@ def test_initialization(self):
45
47
self .assertTrue (isinstance (self .config .email_subject , basestring ))
46
48
self .assertTrue (isinstance (self .config .email_body , basestring ))
47
49
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
+
48
75
49
76
class TestDBConnector (unittest .TestCase ):
77
+
50
78
def setUp (self ):
51
79
if os .environ .get ('TRAVIS' ) == None :
52
80
self .db = DBConnector ()
53
81
54
- def test_add_and_delete_data (self ):
82
+ def test_add_and_delete_github_data (self ):
55
83
if os .environ .get ('TRAVIS' ) == None :
56
84
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
+ )
69
97
res = self .db .add_data (github_data_import )
70
98
self .assertTrue (isinstance (res , GitHubData ))
71
99
res = self .db .delete_data (res .id , 'github_data' )
72
100
self .assertTrue (res )
73
101
102
+ def test_add_and_delete_package_data (self ):
103
+ if os .environ .get ('TRAVIS' ) == None :
74
104
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
+ )
82
112
res = self .db .add_data (packagedata )
83
113
self .assertTrue (isinstance (res , PackageManagerData ))
84
114
res = self .db .delete_data (res .id , 'package_manager_data' )
@@ -100,8 +130,9 @@ def setUp(self):
100
130
101
131
def test_update_library_data (self ):
102
132
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 ])
105
136
self .assertTrue (isinstance (res , GitHubData ))
106
137
res = self .db .delete_data (res .id , 'github_data' )
107
138
self .assertTrue (res )
0 commit comments