|
1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
|
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
|
3
|
|
|
# this work for additional information regarding copyright ownership. |
|
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
|
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
|
6
|
|
|
# the License. You may obtain a copy of the License at |
|
7
|
|
|
# |
|
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
9
|
|
|
# |
|
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13
|
|
|
# See the License for the specific language governing permissions and |
|
14
|
|
|
# limitations under the License. |
|
15
|
|
|
|
|
16
|
|
|
import os |
|
17
|
|
|
import inspect |
|
18
|
|
|
|
|
19
|
|
|
from unittest2 import TestCase |
|
20
|
|
|
|
|
21
|
|
|
__all__ = [ |
|
22
|
|
|
'BasePackResourceTestCase' |
|
23
|
|
|
] |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class BasePackResourceTestCase(TestCase): |
|
27
|
|
|
""" |
|
28
|
|
|
Base test class for all the pack resource test classes. |
|
29
|
|
|
|
|
30
|
|
|
Contains some utility methods for loading fixtures from disk, etc. |
|
31
|
|
|
""" |
|
32
|
|
|
|
|
33
|
|
|
def get_fixture_content(self, fixture_path): |
|
34
|
|
|
""" |
|
35
|
|
|
Return raw fixture content for the provided fixture path. |
|
36
|
|
|
|
|
37
|
|
|
:param fixture_path: Fixture path relative to the tests/fixtures/ directory. |
|
38
|
|
|
:type fixture_path: ``str`` |
|
39
|
|
|
""" |
|
40
|
|
|
base_pack_path = self._get_base_pack_path() |
|
41
|
|
|
fixtures_path = os.path.join(base_pack_path, 'tests/fixtures/') |
|
42
|
|
|
fixture_path = os.path.join(fixtures_path, fixture_path) |
|
43
|
|
|
|
|
44
|
|
|
with open(fixture_path, 'r') as fp: |
|
45
|
|
|
content = fp.read() |
|
46
|
|
|
|
|
47
|
|
|
return content |
|
48
|
|
|
|
|
49
|
|
|
def _get_base_pack_path(self): |
|
50
|
|
|
test_file_path = inspect.getfile(self.__class__) |
|
51
|
|
|
base_pack_path = os.path.join(os.path.dirname(test_file_path), '..') |
|
52
|
|
|
base_pack_path = os.path.abspath(base_pack_path) |
|
53
|
|
|
return base_pack_path |
|
54
|
|
|
|