Esempio n. 1
0
 def test_config_inits_from_file(self):
     c = Config(config_file='test/resources/run1.json')
     self.assertEqual({'type': 'LocalFetcher', 'src': 'testcases'},
                      c.get_fetcher())
     self.assertEqual({'type': 'CaddyPublisher',
                       'url': 'http://127.0.0.1:8080/uploads'},
                      c.get_publisher())
Esempio n. 2
0
 def test_config_inits_from_dict(self):
     c = Config(data=example_mixed)
     self.assertEqual({'type': 'LocalFetcher', 'src': 'testcases'},
                      c.get_fetcher())
     self.assertEqual({'type': 'CaddyPublisher',
                       'url': 'http://127.0.0.1:8080/uploads'},
                      c.get_publisher())
Esempio n. 3
0
 def _get_config(self):
     if not self.parameters.config_file:
         self.params_to_dict('Publisher')
         self.params_to_dict('Fetcher')
         self.add_rf_settings()
         return Config(data=self.config)
     return Config(config_file=self.parameters.config_file)
Esempio n. 4
0
 def test_has_requirements(self):
     c = Config(data={
         "fetcher": {
             "type": "LocalFetcher",
             "src": "test/resources/testcases"
         }
     })
     r = Runner(c)
     self.assertTrue(r.has_requirements())
     r.cleanup()
     c = Config(data={"fetcher": {"type": "LocalFetcher", "src": "test"}})
     r = Runner(c)
     self.assertFalse(r.has_requirements())
     r.cleanup()
Esempio n. 5
0
 def test_find_requirements(self):
     c = Config(data={
         "fetcher": {
             "type": "LocalFetcher",
             "src": "test/resources/testcases"
         }
     })
     r = Runner(c)
     self.assertTrue('requirements.txt' in r.get_requirements())
Esempio n. 6
0
 def test_runner_runs2(self, fetcher_update, publisher_publish,
                       executor_execute):
     c = Config('test/resources/run2.json')
     r = Runner(c)
     r.run()
     fetcher_update.assert_called_once()
     executor_execute.assert_called_once_with(include_tags=['smoke'],
                                              exclude_tags=None)
     publisher_publish.assert_called_once()
     r.cleanup()
Esempio n. 7
0
 def test_runner_install_dependencies(self, pip_install):
     c = Config(data={
         "fetcher": {
             "type": "LocalFetcher",
             "src": "test/resources/testcases"
         }
     })
     r = Runner(c)
     pip_install.assert_called_once()
     r.cleanup()
Esempio n. 8
0
 def test_pip_install(self):
     c = Config(data={
         "fetcher": {
             "type": "LocalFetcher",
             "src": "test/resources/testcases"
         }
     })
     r = Runner(c)
     self.assertTrue('Could not find a version that satisfies' in str(
         r.pip_install_requirements()))
     r.cleanup()
Esempio n. 9
0
 def test_find_requirements2(self):
     c = Config(
         data={
             "fetcher": {
                 "type": "ZipFetcher",
                 "url":
                 "https://github.com/devopsspiral/rf-service/archive/master.zip",
                 "path": "rf-service-master/test/resources/testcases"
             }
         })
     r = Runner(c)
     self.assertTrue(
         'rf-service-master/test/resources/testcases/requirements.txt' in
         r.get_requirements())
Esempio n. 10
0
    def test_config_registers_publisher_callback(self):
        c = Config()
        called = False

        def callback():
            nonlocal called
            called = True
        c.register_publisher_callback(callback)
        data = {'type': 'LocalPublisher', 'dest': 'somecontext'}
        c.load_publisher(data)
        self.assertTrue(called)
Esempio n. 11
0
 def test_runner_gets_fetcher_and_publisher(self, create_context,
                                            fetcher_update):
     c = Config()
     r = Runner(c)
     p_config = {'type': 'LocalPublisher', 'dest': 'testcases'}
     c.load_publisher(p_config)
     f_config = {'type': 'LocalFetcher', 'src': 'testcases'}
     c.load_fetcher(f_config)
     self.assertEqual({'src': 'str'}, r.fetcher.meta())
     self.assertEqual({'dest': 'str'}, r.publisher.meta())
     create_context.assert_called_once()
     fetcher_update.assert_called_once()
Esempio n. 12
0
 def test_runner_discovers_tests(self):
     c = Config('test/resources/run_k8s.json')
     r = Runner(c)
     tests = r.discover_tests()
     self.assertEqual('Rf-Service-Master', tests[0]['name'])
     self.assertEqual('Test', tests[0]['children'][0]['name'])
     self.assertEqual('Resources',
                      tests[0]['children'][0]['children'][0]['name'])
     self.assertEqual(
         'Testcases',
         tests[0]['children'][0]['children'][0]['children'][0]['name'])
     self.assertEqual(
         'Activate Skynet', tests[0]['children'][0]['children'][0]
         ['children'][0]['children'][0]['name'])
     self.assertEqual(
         'Should Activate Skynet', tests[0]['children'][0]['children'][0]
         ['children'][0]['children'][0]['children'][0]['name'])
     r.cleanup()
Esempio n. 13
0
 def test_runner_inits(self, fetcher_update):
     c = Config()
     r = Runner(c)
     self.assertEqual(None, r.fetcher)
     self.assertEqual(None, r.publisher)
     fetcher_update.assert_not_called()
     p_config = {'type': 'LocalPublisher', 'dest': 'testcases'}
     c.load_publisher(p_config)
     f_config = {'type': 'LocalFetcher', 'src': 'testcases'}
     c.load_fetcher(f_config)
     fetcher_update.assert_called_once()
     self.assertEqual(f_config, r.config.get_fetcher())
     self.assertEqual(p_config, r.config.get_publisher())
     r.cleanup()
Esempio n. 14
0
    def test_config_callback_on_data_config(self):
        c = Config(data=example_mixed)
        called_fetcher = False

        def callback_fetcher():
            nonlocal called_fetcher
            called_fetcher = True

        called_publisher = False

        def callback_publisher():
            nonlocal called_publisher
            called_publisher = True
        c.register_fetcher_callback(callback_fetcher)
        self.assertTrue(called_fetcher)
        c.register_fetcher_callback(callback_publisher)
        self.assertTrue(called_publisher)
Esempio n. 15
0
    def test_config_callback_on_file_config(self):
        c = Config(config_file='test/resources/run1.json')
        called_fetcher = False

        def callback_fetcher():
            nonlocal called_fetcher
            called_fetcher = True

        called_publisher = False

        def callback_publisher():
            nonlocal called_publisher
            called_publisher = True
        c.register_fetcher_callback(callback_fetcher)
        self.assertTrue(called_fetcher)
        c.register_fetcher_callback(callback_publisher)
        self.assertTrue(called_publisher)
Esempio n. 16
0
 def test_runner_discovers_tests_when_not_initialized(self):
     c = Config()
     r = Runner(c)
     self.assertEqual([], r.discover_tests())
Esempio n. 17
0
 def test_config_inits(self):
     c = Config()
     self.assertEqual({}, c.get_fetcher())
     self.assertEqual({}, c.get_publisher())
     self.assertIsNone(c.fetcher_callback)
     self.assertIsNone(c.publisher_callback)
Esempio n. 18
0
 def test_config_rf_settings_has_defaults(self):
     c = Config(config_file='test/resources/run2.json')
     self.assertIsNone(c.get_rf_settings()['exclude_tags'])
Esempio n. 19
0
 def test_config_loads_fetcher(self):
     c = Config()
     data = {'type': 'LocalFetcher', 'src': 'somecontext'}
     c.load_fetcher(data)
     self.assertEqual(data, c.get_fetcher())
Esempio n. 20
0
from flask import Flask, jsonify
from flask import request
from flask_cors import CORS
from rf_runner.publisher_factory import PublisherFactory
from rf_runner.fetcher_factory import FetcherFactory
from rf_runner.config import Config
from rf_runner.runner import Runner

# logging.basicConfig(level=logging.DEBUG)
# logging.basicConfig()
# logger = logging.getLogger("fetcher")
# logger.setLevel(logging.DEBUG)

app = Flask(__name__)
CORS(app)
config = Config()
runner = Runner(config)


@app.route('/api/publishers', methods=['GET'])
def publishers():
    return jsonify(PublisherFactory.get_meta())


@app.route('/api/publishers_conf', methods=['GET', 'POST'])
def publishers_conf():
    if request.method == 'POST':
        config.load_publisher(request.json)
        return {'success': True}, 200
    if request.method == 'GET':
        return jsonify(config.get_publisher())
Esempio n. 21
0
 def test_config_gets_rf_settings(self):
     c = Config(config_file='test/resources/run1.json')
     self.assertEqual('smoke',
                      c.get_rf_settings()['include_tags'][0])