示例#1
0
    def test_valid(self, requests_get: MagicMock):
        """ should succeed to get ping data from remove cauldron kernel """

        requests_get.return_value = MockResponse(200)
        url_raw = 'something.com'
        r = support.run_command('connect {}'.format(url_raw))
        self.assertFalse(r.failed, support.Message('Failed', response=r))

        url_clean = r.data['url']
        self.assertTrue(url_clean.startswith('http://'),
                        support.Message('Schema', response=r))
        self.assertLess(0, url_clean.index(url_raw),
                        support.Message('Modified Url', response=r))

        self.assertTrue(environ.remote_connection.active)
        self.assertEqual(environ.remote_connection.url, url_clean)

        support.run_command('disconnect')
示例#2
0
    def test_create_simple_success(self):
        """
        """

        r = support.create_project(self, 'test_create')

        self.assertFalse(
            r.failed, support.Message('Failed to create project', response=r))

        path = os.path.join(r.data['source_directory'], 'cauldron.json')
        self.assertTrue(
            os.path.exists(path),
            support.Message(
                'No project found',
                'Missing cauldron.json file that should exist when a new',
                'project is created',
                response=r,
                path=path))
示例#3
0
    def test_no_url(self):
        """ should fail if no url is provided in the command """

        r = support.run_command('connect')
        self.assertTrue(
            r.failed,
            support.Message(
                'CONNECT-FAIL',
                'Should fail to run connect command when no url is provided',
                response=r))
示例#4
0
    def test_autocomplete(self):
        """

        :return:
        """

        alias = 'ex'
        path = environ.paths.resources('examples')
        support.run_command('alias add "{}" "{}" --temporary'.format(
            alias, path))

        result = support.autocomplete('create my_project @home:')
        self.assertIsNotNone(
            result,
            support.Message('autocomplete result should not be None',
                            result=result))

        # Get all directories in the examples folder
        items = [(e, os.path.join(path, e)) for e in os.listdir(path)]
        items = [e for e in items if os.path.isdir(e[1])]

        result = support.autocomplete('create my_project @ex:')
        self.assertEqual(
            len(result), len(items),
            support.Message('should autocomplete from the examples folder',
                            result=result,
                            items=items))

        hellos = [e for e in items if e[0].startswith('hell')]
        result = support.autocomplete('create my_project @ex:hell')
        self.assertEqual(
            len(result), len(hellos),
            support.Message(
                'should autocomplete examples that start with "hell"',
                result=result,
                items=items))
示例#5
0
    def test_create_twice(self):
        """ """

        r1 = support.create_project(self, 'test_create')
        r1.identifier = 'First {}'.format(r1.identifier)

        r2 = support.create_project(self, 'test_create', confirm=False)
        r2.identifier = 'Second {}'.format(r2.identifier)

        self.assertTrue(
            r2.failed,
            support.Message(
                'No second project',
                'It should not be possible to create a second project in the',
                'same location',
                response=r2))
示例#6
0
    def test_library(self):
        """ should refresh the local project library with the updated value """
        support.create_project(self, 'jack')
        project = cd.project.get_internal_project()

        lib_directory = os.path.join(project.source_directory, 'libs', '_jack')
        os.makedirs(lib_directory)

        path = os.path.join(lib_directory, '__init__.py')
        with open(path, 'w') as fp:
            fp.write('TEST_VALUE = 1\n')

        # TODO: Fix these forced pauses
        time.sleep(1)

        self.assertTrue(os.path.exists(path), 'Library does not exist')

        support.add_step(self,
                         contents='\n'.join([
                             'import cauldron as cd', 'import _jack',
                             'cd.shared.TEST_VALUE = _jack.TEST_VALUE'
                         ]))

        response = support.run_command('run --force')
        self.assertFalse(
            response.failed,
            support.Message(
                'RUN-STEP',
                'should be able to run the step that imports the local library',
                'without failing',
                response=response))
        self.assertEqual(cd.shared.TEST_VALUE, 1)

        # Pause execution to deal with race conditions in modified
        # times that cause this test to fail on certain systems
        time.sleep(1)

        with open(os.path.join(lib_directory, '__init__.py'), 'w') as fp:
            fp.write('TEST_VALUE = 2\n')

        # TODO: Fix these forced pauses
        time.sleep(1)

        support.run_command('run --force')
        self.assertEqual(cd.shared.TEST_VALUE, 2)