|
12 | 12 | import port_for |
13 | 13 |
|
14 | 14 | from scrapyrt.utils import is_python2 |
15 | | -from . import TESTS_PATH |
16 | | -from .utils import get_testenv |
| 15 | +from . import SAMPLE_DATA |
| 16 | +from .utils import get_testenv, generate_project |
17 | 17 |
|
18 | 18 | DEVNULL = open(os.devnull, 'wb') |
19 | | -SAMPLE_DATA = os.path.join(TESTS_PATH, 'sample_data') |
20 | 19 |
|
21 | 20 |
|
22 | 21 | class BaseTestServer(object): |
@@ -116,20 +115,7 @@ def __init__(self, site=None, *args, **kwargs): |
116 | 115 | self.stderr = PIPE |
117 | 116 | self.tmp_dir = tempfile.mkdtemp() |
118 | 117 | self.cwd = os.path.join(self.tmp_dir, 'testproject') |
119 | | - |
120 | | - source = os.path.join(SAMPLE_DATA, 'testproject') |
121 | | - shutil.copytree( |
122 | | - source, self.cwd, ignore=shutil.ignore_patterns('*.pyc')) |
123 | | - # Pass site url to spider doing start requests |
124 | | - spider_name = "testspider_startrequests.py" |
125 | | - spider_filename = os.path.join(self.cwd, "testproject", "spider_templates", spider_name) |
126 | | - spider_target_place = os.path.join(self.cwd, "testproject", "spiders", spider_name) |
127 | | - if not site: |
128 | | - return |
129 | | - with open(spider_filename) as spider_file: |
130 | | - spider_string = spider_file.read().format(site.url("page1.html"), site.url("page2.html")) |
131 | | - with open(spider_target_place, "wb") as file_target: |
132 | | - file_target.write(spider_string.encode('utf8')) |
| 118 | + generate_project(self.cwd, site=site) |
133 | 119 |
|
134 | 120 | def stop(self): |
135 | 121 | super(ScrapyrtTestServer, self).stop() |
|
0 commit comments