Exemplo n.º 1
0
 def restore_config(self):
     # The save method of the previous config manager will be called as an atexit handler.
     # Invalidate its config file path so it fails to save the old config.
     hca.config._config._user_config_home = "/tmp"
     # Reload config after changes made.
     hca.config._config = pickle.loads(self.backup)
     hca.get_config().save()
Exemplo n.º 2
0
 def _setup_tweak_config(self):
     config = hca.get_config()
     config.upload = {
         'areas': {},
         'bucket_name_template': self.UPLOAD_BUCKET_NAME_TEMPLATE
     }
     config.save()
Exemplo n.º 3
0
    def test_list_areas_lists_areas_when_there_are_some(self):
        a_uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
        b_uuid = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
        config = hca.get_config()
        config.upload = {
            'areas': {
                a_uuid: {
                    'uri': "s3://foo/{}/".format(a_uuid)
                },
                b_uuid: {
                    'uri': "s3://foo/{}/".format(b_uuid)
                },
            },
            'current_area': a_uuid
        }
        config.save()

        areas = upload.list_areas()

        sorted_areas = sorted(areas, key=lambda k: k['uuid'])
        self.assertEqual(sorted_areas, [{
            'uuid': a_uuid,
            'is_selected': True
        }, {
            'uuid': b_uuid,
            'is_selected': False
        }])
Exemplo n.º 4
0
 def setUpClass(cls):
     """
     These tests rely on a logged in env, ensure that the current stage is not dss-prod
     """
     config = hca.get_config()
     if "https://dss.data.humancellatlas.org" in config['DSSClient']['swagger_url']:
         raise ValueError('Please change the DSS swagger endpoint in the HCA config file away from `dss-prod`\n'
                          'For more information see: `https://github.com/HumanCellAtlas/dcp-cli#development`')
Exemplo n.º 5
0
    def test_when_given_an_unrecognized_uri_it_stores_it_in_upload_area_list_and_sets_it_as_current_area(
            self):
        upload.select_area(uri=self.uri)

        config = hca.get_config()
        self.assertIn(self.area_uuid, config.upload.areas)
        self.assertEqual(self.uri, config.upload.areas[self.area_uuid]['uri'])
        self.assertEqual(self.area_uuid, config.upload.current_area)
Exemplo n.º 6
0
    def test_when_given_an_alias_that_matches_one_area_it_selects_it(self):
        a_uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
        b_uuid = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
        config = hca.get_config()
        config.upload = {
            'areas': {
                a_uuid: {'uri': "s3://org-humancellatlas-upload-bogo/%s/" % (a_uuid,)},
                b_uuid: {'uri': "s3://org-humancellatlas-upload-bogo/%s/" % (b_uuid,)},
            }
        }
        config.save()

        with CapturingIO('stdout') as stdout:
            args = Namespace(uri_or_alias='bbb')
            SelectCommand(args)

        config = hca.get_config()
        self.assertEqual(b_uuid, config.upload.current_area)
Exemplo n.º 7
0
    def test_when_given_an_unrecognized_urn_it_stores_it_in_upload_area_list_and_sets_it_as_current_area(self):
        with CapturingIO('stdout') as stdout:
            args = Namespace(uri_or_alias=self.uri)
            SelectCommand(args)

        config = hca.get_config()
        self.assertIn(self.area_uuid, config.upload.areas)
        self.assertEqual(self.uri, config.upload.areas[self.area_uuid]['uri'])
        self.assertEqual(self.area_uuid, config.upload.current_area)
Exemplo n.º 8
0
 def test_list_areas_doesnt_error_when_the_upload_tweak_config_is_not_setup(
         self):
     config = hca.get_config()
     if 'upload' in config:
         del config['upload']
     try:
         hca.upload.list_areas()
     except Exception as e:
         self.fail("Expected no exception, got %s" % (e, ))
Exemplo n.º 9
0
    def test_when_given_a_uuid_of_an_existing_area_it_selects_that_area(self):
        a_uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
        b_uuid = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
        config = hca.get_config()
        config.upload = {
            'areas': {
                a_uuid: {
                    'uri': "s3://foo/{}/".format(a_uuid)
                },
                b_uuid: {
                    'uri': "s3://foo/{}/".format(b_uuid)
                },
            },
        }
        config.save()

        upload.select_area(uuid=b_uuid)

        config = hca.get_config()
        self.assertEqual(b_uuid, config.upload.current_area)
Exemplo n.º 10
0
    def test_when_given_an_alias_that_matches_no_areas_it_prints_a_warning(self):

        config = hca.get_config()
        config.upload = {'areas': {}}
        config.save()

        with CapturingIO('stdout') as stdout:
            args = Namespace(uri_or_alias='aaa')
            SelectCommand(args)

        six.assertRegex(self, stdout.captured(), "don't recognize area")
Exemplo n.º 11
0
    def test_cli_login(self):
        """Test that the login command works with a dummy token"""
        access_token = "test_access_token"
        expected = "Storing access credentials\n"
        args = ["dss", "login", "--access-token", access_token]

        with CapturingIO('stdout') as stdout:
            hca.cli.main(args)

        self.assertEqual(stdout.captured(), expected)
        self.assertEqual(hca.get_config().oauth2_token.access_token, access_token)
Exemplo n.º 12
0
    def test_when_given_an_unrecognized_uri_without_slash_it_sets_it_as_current_area(
            self):
        uri_without_slash = "s3://org-humancellatlas-upload-test/{}".format(
            self._area_uuid)
        with CapturingIO('stdout'):
            args = Namespace(uri_or_alias=uri_without_slash)
            SelectCommand(args)

        config = hca.get_config()
        self.assertIn(self._area_uuid, config.upload.areas)
        self.assertEqual(self._uri,
                         config.upload.areas[self._area_uuid]['uri'])
        self.assertEqual(self._area_uuid, config.upload.current_area)
Exemplo n.º 13
0
 def test_remote_login(self):
     """Test that remote logins work for non-interactive systems
         0. Change the skipIf from True to False to allow invocation of test
         1. Follow the link provided by the test
         2. Paste the code value into the test env
         3. Confirm Results
     """
     args = ["dss", "login", "--remote"]
     hca.cli.main(args)
     self.assertTrue(hca.get_config().oauth2_token.access_token)
     args = ['dss', 'get-subscriptions', '--replica', 'aws']
     with CapturingIO('stdout') as stdout:
         hca.cli.main(args)
     results = json.loads(stdout.captured())
     self.assertIn("subscriptions", results)
Exemplo n.º 14
0
    def test_when_given_an_alias_that_matches_more_than_one_area_it_prints_a_warning(self):
        config = hca.get_config()
        config.upload = {
            'areas': {
                'deadbeef-dead-dead-dead-beeeeeeeeeef': {'uri': 's3://bucket/deadbeef-dead-dead-dead-beeeeeeeeeef/'},
                'deafbeef-deaf-deaf-deaf-beeeeeeeeeef': {'uri': 's3://bucket/deafbeef-deaf-deaf-deaf-beeeeeeeeeef/'},
            }
        }
        config.save()

        with CapturingIO('stdout') as stdout:
            args = Namespace(uri_or_alias='dea')
            SelectCommand(args)

        six.assertRegex(self, stdout.captured(), "matches more than one")
Exemplo n.º 15
0
    def test_when_given_a_uri_it_prints_an_alias(self):
        config = hca.get_config()
        config.upload = {
            'areas': {
                'deadbeef-dead-dead-dead-beeeeeeeeeef': {
                    'uri': 's3://bogobucket/deadbeef-dead-dead-dead-beeeeeeeeeef/'
                },
            }
        }
        config.save()
        new_area_uuid = 'deafbeef-deaf-deaf-deaf-beeeeeeeeeef'
        new_area_uri = 's3://bogobucket/{}/'.format(new_area_uuid)

        with CapturingIO('stdout') as stdout:
            args = Namespace(uri_or_alias=new_area_uri)
            SelectCommand(args)

        six.assertRegex(self, stdout.captured(), "alias \"{}\"".format('deaf'))
Exemplo n.º 16
0
    def test_it_lists_areas_when_there_are_some(self):
        a_uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
        b_uuid = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
        config = hca.get_config()
        config.upload = {
            'areas': {
                a_uuid: {
                    'uri': "s3://foo/{}/".format(a_uuid)
                },
                b_uuid: {
                    'uri': "s3://foo/{}/".format(b_uuid)
                },
            },
            'current_area': a_uuid
        }
        config.save()

        with CapturingIO('stdout') as stdout:
            ListAreasCommand(Namespace())

        six.assertRegex(self, stdout.captured(), "%s <- selected" % a_uuid)
        six.assertRegex(self, stdout.captured(), b_uuid)
Exemplo n.º 17
0
 def save_config(self):
     config = hca.get_config()
     self.backup = pickle.dumps(config)