예제 #1
0
    def test_should_start_background_service(self, mock_sleep, mock_popen, mock_process_iter):
        context = Context()
        context.api = InactiveClientApi()
        context.init = MockInitApi(state_responses=[mock_data.INIT_STATE_PENDING, mock_data.INIT_STATE_SUCCESSFUL])
        context.rendering = JsonWriter()
        context.service_binary = 'test-name'
        context.service_main_class = 'test.name.Main'

        mock_process_iter.return_value = []
        mock_popen.return_value = None
        mock_sleep.return_value = None

        username = '******'
        password = '******'

        runner = Runner(cli)
        result = runner.invoke(
            args=['start', '--username', username, '--password', password],
            obj=context
        )

        self.assertEqual(result.exit_code, 0, result.output)
        self.assertDictEqual(json.loads(result.output), {'successful': True})
        mock_popen.assert_called_once()
        mock_sleep.assert_called_once()
        self.assertEqual(context.init.stats['state'], 2)
        self.assertEqual(context.init.stats['provide_credentials'], 1)
예제 #2
0
    def test_should_not_start_background_service_when_process_already_running(self, mock_process_iter):
        context = Context()
        context.api = InactiveClientApi()
        context.init = MockInitApi()
        context.rendering = JsonWriter()
        context.service_binary = 'test-name'
        context.service_main_class = 'test.name.Main'

        process = MockProcess()

        mock_process_iter.return_value = [process]
        username = '******'
        password = '******'

        runner = Runner(cli)
        result = runner.invoke(args=['start', '--username', username, '--password', password], obj=context)

        self.assertEqual(result.exit_code, 0, result.output)
        self.assertDictEqual(
            json.loads(result.output),
            {'successful': False, 'failure': 'Unexpected background service process(es) found'}
        )
예제 #3
0
    def test_should_fail_all_requests(self):
        api = InactiveClientApi()

        definition = uuid4()
        entry = uuid4()
        operation = uuid4()
        query = 'test.*'
        until = '2020-02-02T02:02:02'
        definition_request = {'a': 1, 'b': 2}

        with self.assertRaises(Abort):
            api.stop()

        with self.assertRaises(Abort):
            api.dataset_metadata(entry=entry)

        with self.assertRaises(Abort):
            api.dataset_metadata_search(search_query=query, until=until)

        with self.assertRaises(Abort):
            api.dataset_definitions()

        with self.assertRaises(Abort):
            api.dataset_entries()

        with self.assertRaises(Abort):
            api.dataset_entries_for_definition(definition=definition)

        with self.assertRaises(Abort):
            api.user()

        with self.assertRaises(Abort):
            api.device()

        with self.assertRaises(Abort):
            api.device_connections()

        with self.assertRaises(Abort):
            api.operations()

        with self.assertRaises(Abort):
            api.operation_progress(operation=operation)

        with self.assertRaises(Abort):
            api.operation_follow(operation=operation)

        with self.assertRaises(Abort):
            api.operation_stop(operation=operation)

        with self.assertRaises(Abort):
            api.backup_rules()

        with self.assertRaises(Abort):
            api.backup_start(definition=definition)

        with self.assertRaises(Abort):
            api.backup_define(request=definition_request)

        with self.assertRaises(Abort):
            api.recover_until(definition=definition, until=until, path_query=query, destination='', discard_paths=True)

        with self.assertRaises(Abort):
            api.recover_from(definition=definition, entry=entry, path_query=query, destination='', discard_paths=True)

        with self.assertRaises(Abort):
            api.recover_from_latest(definition=definition, path_query=query, destination='', discard_paths=True)

        with self.assertRaises(Abort):
            api.schedules_public()

        with self.assertRaises(Abort):
            api.schedules_configured()

        with self.assertRaises(Abort):
            api.schedules_configured_refresh()
예제 #4
0
 def test_should_check_if_api_is_active(self):
     api = InactiveClientApi()
     self.assertFalse(api.is_active())