Beispiel #1
0
    def test_roles_add_duplicated_to_db_directly(self):
        self.env.create_release()
        resp = self.app.get(
            reverse('ReleaseCollectionHandler'),
            headers=self.default_headers
        )
        release_json = json.loads(resp.body)[0]
        old_roles = list(release_json["roles"])

        role = Role(name=old_roles[0],
                    release_id=release_json["id"])
        added = True
        try:
            db().add(role)
            db().commit()
        except IntegrityError:
            db.rollback()
            added = False
        self.assertFalse(added)

        resp = self.app.get(
            reverse('ReleaseCollectionHandler'),
            headers=self.default_headers
        )
        release_json = json.loads(resp.body)[0]
        new_roles = list(release_json["roles"])
        self.assertEqual(old_roles, new_roles)
 def test_task_with_wrong_type_fail(self):
     deployment_graph_id = self._insert_deployment_graph()
     with self.assertRaisesRegexp(
             DataError,
             'invalid input value for enum deployment_graph_tasks_type'):
         db.execute(
             self.meta.tables['deployment_graph_tasks'].insert(), {
                 'deployment_graph_id': deployment_graph_id,
                 'type': 'NOT EXISTING TYPE'
             })
     db.rollback()
Beispiel #3
0
def test_db_driver(handler):
    try:
        return handler()
    except web.HTTPError:
        if str(web.ctx.status).startswith(("4", "5")):
            db.rollback()
        raise
    except Exception:
        db.rollback()
        raise
    finally:
        db.commit()
Beispiel #4
0
def test_db_driver(handler):
    try:
        return handler()
    except web.HTTPError:
        if str(web.ctx.status).startswith(("4", "5")):
            db.rollback()
        raise
    except Exception:
        db.rollback()
        raise
    finally:
        db.commit()
 def test_task_with_wrong_type_fail(self):
     deployment_graph_id = self._insert_deployment_graph()
     with self.assertRaisesRegexp(
         DataError,
         'invalid input value for enum deployment_graph_tasks_type'
     ):
         db.execute(
             self.meta.tables['deployment_graph_tasks'].insert(),
             {
                 'deployment_graph_id': deployment_graph_id,
                 'type': 'NOT EXISTING TYPE'
             })
     db.rollback()
Beispiel #6
0
 def test_not_nullable_required_component_types(self):
     with self.assertRaisesRegexp(
             IntegrityError,
             'null value in column "required_component_types" '
             'violates not-null constraint'):
         db.execute(
             self.meta.tables['releases'].insert(), {
                 'name': 'test_release',
                 'version': '2015.1-10.0',
                 'operating_system': 'ubuntu',
                 'state': 'available',
                 'roles_metadata': '{}',
                 'is_deployable': True,
                 'required_component_types': None
             })
     db.rollback()
 def test_not_nullable_required_component_types(self):
     with self.assertRaisesRegexp(
             IntegrityError,
             'null value in column "required_component_types" '
             'violates not-null constraint'
     ):
         db.execute(
             self.meta.tables['releases'].insert(),
             {
                 'name': 'test_release',
                 'version': '2015.1-10.0',
                 'operating_system': 'ubuntu',
                 'state': 'available',
                 'roles_metadata': '{}',
                 'is_deployable': True,
                 'required_component_types': None
             })
     db.rollback()
 def test_task_with_missing_required_fields_fail(self):
     deployment_graph_id = self._insert_deployment_graph()
     with self.assertRaisesRegexp(
             IntegrityError,
             'null value in column "type" violates not-null constraint'):
         db.execute(
             self.meta.tables['deployment_graph_tasks'].insert(), {
                 'deployment_graph_id': deployment_graph_id,
                 'task_name': 'minimal task'
             })
     db.rollback()
     with self.assertRaisesRegexp(
             IntegrityError,
             'null value in column "task_name" violates not-null constraint'
     ):
         db.execute(self.meta.tables['deployment_graph_tasks'].insert(), {
             'deployment_graph_id': deployment_graph_id,
             'type': 'puppet'
         })
     db.rollback()
Beispiel #9
0
def load_db_driver(handler):
    """Wrap all handlers calls in a special construction, that's call
    rollback if something wrong or commit changes otherwise. Please note,
    only HTTPError should be rised up from this function. All another
    possible errors should be handle.
    """
    try:
        # execute handler and commit changes if all is ok
        response = handler()
        db.commit()
        return response

    except web.HTTPError:
        # a special case: commit changes if http error ends with
        # 200, 201, 202, etc
        if web.ctx.status.startswith('2'):
            db.commit()
        else:
            db.rollback()
        raise

    except (sa_exc.IntegrityError, sa_exc.DataError) as exc:
        # respond a "400 Bad Request" if database constraints were broken
        db.rollback()
        raise BaseHandler.http(400, exc.message)

    except Exception:
        db.rollback()
        raise

    finally:
        db.remove()
 def test_task_with_missing_required_fields_fail(self):
     deployment_graph_id = self._insert_deployment_graph()
     with self.assertRaisesRegexp(
         IntegrityError,
         'null value in column "type" violates not-null constraint'
     ):
         db.execute(
             self.meta.tables['deployment_graph_tasks'].insert(),
             {
                 'deployment_graph_id': deployment_graph_id,
                 'task_name': 'minimal task'
             })
     db.rollback()
     with self.assertRaisesRegexp(
         IntegrityError,
         'null value in column "task_name" violates not-null constraint'
     ):
         db.execute(
             self.meta.tables['deployment_graph_tasks'].insert(),
             {
                 'deployment_graph_id': deployment_graph_id,
                 'type': 'puppet'
             })
     db.rollback()
Beispiel #11
0
 def tearDown(self):
     db.rollback()
 def tearDown(self):
     db.rollback()