forked from yoannsculo/JobCatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
160 lines (124 loc) · 4.21 KB
/
test.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__authors__ = [
'Yoann Sculo <[email protected]>',
'Bruno Adelé <[email protected]>',
]
__copyright__ = 'Copyright (C) 2013 Yoann Sculo'
__license__ = 'GPLv2'
__version__ = '1.0'
import os
import unittest
import utilities
from config import configstest as configs
import jobcatcher
class TestPackages(unittest.TestCase):
def cleanDatas(self, jobboardname):
"""Clean jobboard datas"""
rootdir = configs['global']['rootdir']
feedsdir = '%s/%s/feeds' % (rootdir, jobboardname)
pagesdir = '%s/%s/pages' % (rootdir, jobboardname)
# remove feeds & pages
utilities.removeFiles(feedsdir, '*.feed')
utilities.removeFiles(pagesdir, '*.page')
def setUp(self):
"""Test & Create database"""
# Remove exist database
if os.path.isfile(configs['global']['database']):
os.remove(configs['global']['database'])
# Check if database not exist
exists = utilities.db_istableexists(configs, 'offers')
self.assertEqual(exists, False)
# Create database & check
utilities.db_create(configs)
exists = utilities.db_istableexists(configs, 'offers')
self.assertEqual(exists, True)
def test_JBEures(self):
""" Test Eures jobboard"""
# Jobboardname
jobboard = 'Eures'
# Clean datas
self.cleanDatas(jobboard)
# Get feed content
plugin = utilities.loadJobBoard(jobboard, configs)
feed = configs[jobboard]['feeds'][0]
filename = plugin.downloadFeed(feed)
self.assertEqual(
filename,
'/tmp/dl/Eures/feeds/f5b201bd055ca4f07076e96cdabdf68d.feed'
)
# Dowload page
urls = plugin.getUrls()
self.assertEqual(len(urls), 5)
plugin.downloadPages(urls)
def test_JBApec(self):
""" Test Apec jobboard"""
# Jobboardname
jobboard = 'Apec'
# Clean datas
self.cleanDatas(jobboard)
# Get feed content
plugin = utilities.loadJobBoard(jobboard, configs)
feed = configs[jobboard]['feeds'][0]
filename = plugin.downloadFeed(feed)
self.assertEqual(
filename,
'/tmp/dl/Apec/feeds/2f18abc46311f962025c1701b6a209e5.feed'
)
# Dowload page
urls = plugin.getUrls()
self.assertEqual(len(urls), 30)
plugin.downloadPages(urls)
def test_JBRegionJob(self):
""" Test RegionJob jobboard"""
# Jobboardname
jobboard = 'RegionJob'
# Clean datas
self.cleanDatas(jobboard)
# Get feed content
plugin = utilities.loadJobBoard(jobboard, configs)
feed = configs[jobboard]['feeds'][0]
filename = plugin.downloadFeed(feed)
self.assertEqual(
filename,
'/tmp/dl/RegionJob/feeds/a98a7cbf97492bc91d81f33aebfb35bf.feed'
)
# Clean datas
self.cleanDatas(jobboard)
# Download all feeds
feeds = configs[jobboard]['feeds']
for url in feeds:
plugin.downloadFeed(url)
# Dowload page
urls = plugin.getUrls()
self.assertEqual(len(urls), 80)
plugin.downloadPages(urls)
def test_JBPoleEmploi(self):
""" Test PoleEmploi jobboard"""
# Jobboardname
jobboard = 'PoleEmploi'
# Clean datas
self.cleanDatas(jobboard)
# Get feed content
plugin = utilities.loadJobBoard(jobboard, configs)
feed = configs[jobboard]['feeds'][0]
filename = plugin.downloadFeed(feed)
self.assertEqual(
filename,
'/tmp/dl/PoleEmploi/feeds/19917e808ace985a5856f37122d76b65.feed'
)
# Clean datas
self.cleanDatas(jobboard)
# Download all feeds
feeds = configs[jobboard]['feeds']
for url in feeds:
plugin.downloadFeed(url)
# Dowload page
urls = plugin.getUrls()
self.assertEqual(len(urls), 20)
plugin.downloadPages(urls)
def test_jobcatcher(self):
"""Execute the jobcatcher functions"""
jobcatcher.executeall(configs)
if __name__ == "__main__":
unittest.main(verbosity=2)