Exemplo n.º 1
0
    def test_manager_without_owner_email_address(self):
        from pillar.api.utils.authentication import force_cli_user
        from flamenco.setup import create_manager

        with self.app.test_request_context():
            force_cli_user()

            with self.assertRaises(ValueError):
                create_manager('', 'Unit test mānāgèr', '¡Awesome in Space!')
Exemplo n.º 2
0
    def test_manager_without_owner_email_address(self):
        from pillar.api.utils.authentication import force_cli_user
        from flamenco.setup import create_manager

        with self.app.test_request_context():
            force_cli_user()

            with self.assertRaises(ValueError):
                create_manager('', 'Unit test mānāgèr', '¡Awesome in Space!')
Exemplo n.º 3
0
    def test_two_managers_with_same_owner(self):
        from pillar.api.utils.authentication import force_cli_user
        from flamenco.setup import create_manager

        self.create_user(email='*****@*****.**')

        with self.app.test_request_context():
            force_cli_user()
            mngr_doc1, account1, token1 = create_manager('*****@*****.**', 'mānāgèr 1', 'Awe!')
            mngr_doc2, account2, token2 = create_manager('*****@*****.**', 'mānāgèr 2', 'som!')

        self.assertAllowsAccess(token1, account1['_id'])
        self.assertAllowsAccess(token2, account2['_id'])
Exemplo n.º 4
0
    def test_two_managers_with_same_owner(self):
        from pillar.api.utils.authentication import force_cli_user
        from flamenco.setup import create_manager

        self.create_user(email='*****@*****.**')

        with self.app.test_request_context():
            force_cli_user()
            mngr_doc1, account1, token1 = create_manager(
                '*****@*****.**', 'mānāgèr 1', 'Awe!')
            mngr_doc2, account2, token2 = create_manager(
                '*****@*****.**', 'mānāgèr 2', 'som!')

        self.assertAllowsAccess(token1, account1['_id'])
        self.assertAllowsAccess(token2, account2['_id'])
Exemplo n.º 5
0
    def create_manager_service_account(self,
                                       owner_email=ctd.EXAMPLE_USER['email'],
                                       name='tēst mānēgūr',
                                       *,
                                       assign_to_project_id: ObjectId = None):
        from flamenco.setup import create_manager
        from pillar.api.utils.authentication import force_cli_user

        # Main project will have a manager, job, and tasks.
        with self.app.test_request_context():
            force_cli_user()

            # Make sure there is an owner for this manager.
            users_coll = self.app.db('users')
            count = users_coll.find({'email': owner_email}).count()
            if count == 0:
                self.create_user(user_id=ObjectId(), email=owner_email)
            elif count > 1:
                self.fail(
                    f'Found {count} users with email address {owner_email}')

            mngr_doc, account, token = create_manager(owner_email, name,
                                                      'descr')

            if assign_to_project_id:
                self.assign_manager_to_project(mngr_doc['_id'],
                                               assign_to_project_id)

        return mngr_doc, account, token
Exemplo n.º 6
0
    def test_create_manager(self):
        from pillar.api.utils.authentication import force_cli_user
        from flamenco.setup import create_manager

        # Make sure the owner of the manager exists.
        owner_id = self.create_user(email='*****@*****.**')

        with self.app.test_request_context():
            force_cli_user()
            mngr_doc, account, token = create_manager(
                '*****@*****.**', 'Unit test mānāgèr', '¡Awesome in Space!')

        self.assertEqual('Unit test mānāgèr', mngr_doc['name'])

        self.assertEqual(f'SRV-{account["_id"]}', account['full_name'])
        self.assertEqual(f'SRV-{account["_id"]}', account['username'])
        self.assertEqual(['flamenco_manager', 'service'], account['roles'])
        self.assertEqual([], account['auth'])
        self.assertEqual({'flamenco_manager': {}}, account['service'])

        self.assertIn('owner', mngr_doc)
        self.assertTrue(mngr_doc['owner'])

        # Check that the group exists, and that it refers to the manager in its name.
        with self.app.test_request_context():
            groups_coll = self.app.db().groups
            group = groups_coll.find_one(mngr_doc['owner'])
            self.assertIn(str(mngr_doc['_id']), group['name'])

        self.assertAllowsAccess(token, account['_id'])

        # Check that the owner is now member of the owner group.
        owner = self.fetch_user_from_db(owner_id)
        self.assertIn(mngr_doc['owner'], owner['groups'])
Exemplo n.º 7
0
    def test_create_manager(self):
        from pillar.api.utils.authentication import force_cli_user
        from flamenco.setup import create_manager

        # Make sure the owner of the manager exists.
        owner_id = self.create_user(email='*****@*****.**')

        with self.app.test_request_context():
            force_cli_user()
            mngr_doc, account, token = create_manager('*****@*****.**',
                                                      'Unit test mānāgèr',
                                                      '¡Awesome in Space!')

        self.assertEqual('Unit test mānāgèr', mngr_doc['name'])

        self.assertEqual(f'SRV-{account["_id"]}', account['full_name'])
        self.assertEqual(f'SRV-{account["_id"]}', account['username'])
        self.assertEqual(['flamenco_manager', 'service'], account['roles'])
        self.assertEqual([], account['auth'])
        self.assertEqual({'flamenco_manager': {}}, account['service'])

        self.assertIn('owner', mngr_doc)
        self.assertTrue(mngr_doc['owner'])

        # Check that the group exists, and that it refers to the manager in its name.
        with self.app.test_request_context():
            groups_coll = self.app.db().groups
            group = groups_coll.find_one(mngr_doc['owner'])
            self.assertIn(str(mngr_doc['_id']), group['name'])

        self.assertAllowsAccess(token, account['_id'])

        # Check that the owner is now member of the owner group.
        owner = self.fetch_user_from_db(owner_id)
        self.assertIn(mngr_doc['owner'], owner['groups'])