Beispiel #1
0
 def setUpClass(cls):
     cls.db = db()
     cls.app = TestApp(build_app().wsgifunc())
     syncdb()
Beispiel #2
0
 def test_index(self):
     middleware = []
     testApp = TestApp(app.wsgifunc(*middleware))
     r = testApp.get('/')
     assert_equal(r.status, 200)
     r.mustcontain('Hello, World!')
Beispiel #3
0
 def setUp(self):
     self.headers = getDefaultHTTPHeaders(YOMP.app.config)
     self.app = TestApp(settings_api.app.wsgifunc())
Beispiel #4
0
 def setUp(self):
     TestWSGIController.setUp(self)
     app = SetupCacheGlobal(ControllerWrap(ValidatingController),
                            self.environ)
     app = RegistryManager(app)
     self.app = TestApp(app)
Beispiel #5
0
    def setUpClass(cls):
        """
    Setup steps for all test cases.
    Focus for these is to cover all API checks for ModelDataHandler.
    Hence, this does all setup creating metric, waiting for
    metricData across all testcases, all API call for querying metricData
    will be against single metric created in setup
    Setup Process
    1) Update conf with aws credentials, ManagedTempRepository will not
       work in this test
    2) Select test instance such that its running from longer time,
       We are using instance older than 15 days
    3) Create Metric, wait for min metricData rows to become available
       Set to 100, configurable
    4) Pick testRowId, set it lower value this will make sure to have
       Non NULL value for anomaly_score field for given row while invoking
       GET with consitions, set to 5
    5) Decide queryParams for anomalyScore, to and from timestamp
    """
        cls.headers = getDefaultHTTPHeaders(grok.app.config)

        # All other sevices needs AWS credentials to work
        # Set AWS credentials
        grok.app.config.loadConfig()

        # Select test instance such that its running from longer time
        g_logger.info("Getting long-running EC2 Instances")
        instances = aws_utils.getLongRunningEC2Instances(
            "us-west-2", grok.app.config.get("aws", "aws_access_key_id"),
            grok.app.config.get("aws", "aws_secret_access_key"), 15)
        testInstance = instances[randrange(1, len(instances))]

        createModelData = {
            "region": "us-west-2",
            "namespace": "AWS/EC2",
            "datasource": "cloudwatch",
            "metric": "CPUUtilization",
            "dimensions": {
                "InstanceId": testInstance.id
            }
        }

        # Number of minimum rows
        cls.minDataRows = 100

        cls.app = TestApp(models_api.app.wsgifunc())

        # create test metric
        g_logger.info("Creating test metric; modelSpec=%s", createModelData)
        response = cls.app.put("/",
                               utils.jsonEncode(createModelData),
                               headers=cls.headers)
        postResult = utils.jsonDecode(response.body)
        maxWaitTime = 600
        waitTimeMetricData = 0
        waitAnomalyScore = 0

        # Wait for enough metric data to be available
        cls.uid = postResult[0]["uid"]
        engine = repository.engineFactory()
        with engine.connect() as conn:
            cls.metricData = [
                row for row in repository.getMetricData(conn, cls.uid)
            ]
        with engine.connect() as conn:
            cls.testMetric = repository.getMetric(conn, cls.uid)

        # Confirm that we have enough metricData
        g_logger.info("Waiting for metric data")
        while (len(cls.metricData) < cls.minDataRows
               and waitTimeMetricData < maxWaitTime):
            g_logger.info(
                "not ready, waiting for metric data: got %d of %d ...",
                len(cls.metricData), cls.minDataRows)
            time.sleep(5)
            waitTimeMetricData += 5
            with engine.connect() as conn:
                cls.metricData = [
                    row for row in repository.getMetricData(conn, cls.uid)
                ]

        # taking lower value for testRowId, this will make sure to have
        # Non NULL value for anomaly_score field for given row
        cls.testRowId = 5

        with engine.connect() as conn:
            cls.testMetricRow = (repository.getMetricData(
                conn, cls.uid, rowid=cls.testRowId).fetchone())

        # Make sure we did not receive None etc for anomaly score
        g_logger.info("cls.testMetricRow.anomaly_score=%r",
                      cls.testMetricRow.anomaly_score)
        g_logger.info("waitAnomalyScore=%r", waitAnomalyScore)
        while (cls.testMetricRow.anomaly_score is None
               and waitAnomalyScore < maxWaitTime):
            g_logger.info("anomaly_score not ready, sleeping...")
            time.sleep(5)
            waitAnomalyScore += 5
            with engine.connect() as conn:
                cls.testMetricRow = (repository.getMetricData(
                    conn, cls.uid, rowid=cls.testRowId).fetchone())

        # Decide queryParams for anomalyScore, to and from timestamp
        cls.testAnomalyScore = cls.testMetricRow.anomaly_score
        cls.testTimeStamp = cls.testMetricRow.timestamp
Beispiel #6
0
    def test_create_and_list_subscription_by_id(self):
        """ SUBSCRIPTION (REST): Test the creation of a new subscription and get by subscription id """
        mw = []

        headers1 = {
            'X-Rucio-Account': 'root',
            'X-Rucio-Username': '******',
            'X-Rucio-Password': '******'
        }
        headers1.update(self.vo_header)
        res1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass',
                                                   headers=headers1,
                                                   expect_errors=True)

        assert_equal(res1.status, 200)
        token = str(res1.header('X-Rucio-Auth-Token'))

        subscription_name = uuid()
        headers2 = {'X-Rucio-Auth-Token': str(token)}
        data = dumps({
            'options': {
                'filter': {
                    'project': self.projects,
                    'datatype': [
                        'AOD',
                    ],
                    'excluded_pattern': self.pattern1,
                    'account': [
                        'tier0',
                    ]
                },
                'replication_rules': [{
                    'lifetime': 86400,
                    'rse_expression': 'MOCK|MOCK2',
                    'copies': 2,
                    'activity': 'Data Brokering'
                }],
                'lifetime':
                100000,
                'retroactive':
                0,
                'dry_run':
                0,
                'comments':
                'blahblah'
            }
        })
        res2 = TestApp(subs_app.wsgifunc(*mw)).post('/root/%s' %
                                                    (subscription_name),
                                                    headers=headers2,
                                                    params=data,
                                                    expect_errors=True)
        assert_equal(res2.status, 201)

        subscription_id = res2.body
        res3 = TestApp(subs_app.wsgifunc(*mw)).get('/Id/%s' %
                                                   (subscription_id),
                                                   headers=headers2,
                                                   expect_errors=True)
        assert_equal(res3.status, 200)
        assert_equal(
            loads(loads(res3.body)['filter'])['project'][0], 'data12_900GeV')
Beispiel #7
0
    def test_list_rules_states(self):
        """ SUBSCRIPTION (REST): Test listing of rule states for subscription """
        tmp_scope = InternalScope('mock_' + uuid()[:8], **self.vo)
        root = InternalAccount('root', **self.vo)
        add_scope(tmp_scope, root)
        mw = []
        site_a = 'RSE%s' % uuid().upper()
        site_b = 'RSE%s' % uuid().upper()

        site_a_id = add_rse(site_a, **self.vo)
        site_b_id = add_rse(site_b, **self.vo)

        # Add quota
        set_account_limit(root, site_a_id, -1)
        set_account_limit(root, site_b_id, -1)

        # add a new dataset
        dsn = 'dataset-%s' % uuid()
        add_did(scope=tmp_scope, name=dsn, type=DIDType.DATASET, account=root)

        subscription_name = uuid()
        subid = add_subscription(name=subscription_name,
                                 account='root',
                                 filter={
                                     'account': [
                                         'root',
                                     ],
                                     'scope': [
                                         tmp_scope.external,
                                     ]
                                 },
                                 replication_rules=[{
                                     'lifetime':
                                     86400,
                                     'rse_expression':
                                     'MOCK|MOCK2',
                                     'copies':
                                     2,
                                     'activity':
                                     'Data Brokering'
                                 }],
                                 lifetime=100000,
                                 retroactive=0,
                                 dry_run=0,
                                 comments='We want a shrubbery',
                                 issuer='root',
                                 **self.vo)

        # Add two rules
        add_rule(dids=[{
            'scope': tmp_scope,
            'name': dsn
        }],
                 account=root,
                 copies=1,
                 rse_expression=site_a,
                 grouping='NONE',
                 weight=None,
                 lifetime=None,
                 locked=False,
                 subscription_id=subid)
        add_rule(dids=[{
            'scope': tmp_scope,
            'name': dsn
        }],
                 account=root,
                 copies=1,
                 rse_expression=site_b,
                 grouping='NONE',
                 weight=None,
                 lifetime=None,
                 locked=False,
                 subscription_id=subid)

        headers1 = {
            'X-Rucio-Account': 'root',
            'X-Rucio-Username': '******',
            'X-Rucio-Password': '******'
        }
        headers1.update(self.vo_header)
        res1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass',
                                                   headers=headers1,
                                                   expect_errors=True)

        assert_equal(res1.status, 200)
        token = str(res1.header('X-Rucio-Auth-Token'))

        headers2 = {'X-Rucio-Auth-Token': str(token)}
        res2 = TestApp(subs_app.wsgifunc(*mw)).get('/%s/%s/Rules/States' %
                                                   ('root', subscription_name),
                                                   headers=headers2,
                                                   expect_errors=True)

        for line in res2.body.split('\n'):
            print(line)
            rs = loads(line)
            if rs[1] == subscription_name:
                break
        assert_equal(rs[3], 2)
Beispiel #8
0
 def setUp(self):
     middleware = []
     self.testApp = TestApp(app.wsgifunc(*middleware))
 def test_location_get(self):
     middleware = []
     testApp = TestApp(app.wsgifunc(*middleware))
     r = testApp.get('/location')
     assert_equal(r.status, 200)
     r.mustcontain('hello world!')
Beispiel #10
0
 def setUpLoggerhead(self, **kw):
     branch_app = BranchWSGIApp(self.tree.branch, '', **kw).app
     return TestApp(HTTPExceptionHandler(branch_app))
Beispiel #11
0
 def setUp(self):
     super(TestWSGICombo, self).setUp()
     self.root = self.makeDir()
     self.app = TestApp(combo_app(self.root))
Beispiel #12
0
    def test_view_folder(self):
        app = TestApp(BranchWSGIApp(self.tree.branch, '').app)

        e = self.assertRaises(HTTPMovedPermanently, app.get,
                              '/view/head:/folder')
        self.assertEqual(e.location(), '/files/head:/folder')
Beispiel #13
0
 def setUpClass(cls):
     cls.app = TestApp(models_api.app.wsgifunc())
Beispiel #14
0
    def test_redirect_metalink_list_replicas(self):
        """ ROOT (REDIRECT REST): Test internal proxy prepend with metalink"""
        mw = []

        # default behaviour - no location -> no proxy
        res = TestApp(redirect_app.wsgifunc(*mw)).get(
            '/mock/half-life_1/metalink', expect_errors=True)
        body = res.body.decode()
        assert_in(
            'root://root.blackmesa.com:1409//training/facility/mock/c9/df/half-life_1',
            body)
        assert_in(
            'root://root.aperture.com:1409//test/chamber/mock/c9/df/half-life_1',
            body)
        assert_not_in('proxy', body)
        res = TestApp(redirect_app.wsgifunc(*mw)).get(
            '/mock/half-life_2/metalink', expect_errors=True)
        body = res.body.decode()
        assert_in(
            'root://root.blackmesa.com:1409//training/facility/mock/c1/8d/half-life_2',
            body)
        assert_in(
            'root://root.aperture.com:1409//test/chamber/mock/c1/8d/half-life_2',
            body)
        assert_not_in('proxy', body)
        res = TestApp(redirect_app.wsgifunc(*mw)).get(
            '/mock/half-life_3/metalink', expect_errors=True)
        body = res.body.decode()
        assert_in(
            'root://root.blackmesa.com:1409//training/facility/mock/16/30/half-life_3',
            body)
        assert_in(
            'root://root.aperture.com:1409//test/chamber/mock/16/30/half-life_3',
            body)
        assert_not_in('proxy', body)

        # site without proxy
        res = TestApp(redirect_app.wsgifunc(*mw)).get(
            '/mock/half-life_1/metalink?%s' %
            urlencode(self.client_location_without_proxy),
            expect_errors=True)
        body = res.body.decode()
        assert_in(
            'root://root.blackmesa.com:1409//training/facility/mock/c9/df/half-life_1',
            body)
        assert_in(
            'root://root.aperture.com:1409//test/chamber/mock/c9/df/half-life_1',
            body)
        assert_not_in('proxy', body)
        res = TestApp(redirect_app.wsgifunc(*mw)).get(
            '/mock/half-life_2/metalink?%s' %
            urlencode(self.client_location_without_proxy),
            expect_errors=True)
        body = res.body.decode()
        assert_in(
            'root://root.blackmesa.com:1409//training/facility/mock/c1/8d/half-life_2',
            body)
        assert_in(
            'root://root.aperture.com:1409//test/chamber/mock/c1/8d/half-life_2',
            body)
        assert_not_in('proxy', body)
        res = TestApp(redirect_app.wsgifunc(*mw)).get(
            '/mock/half-life_3/metalink?%s' %
            urlencode(self.client_location_without_proxy),
            expect_errors=True)
        body = res.body.decode()
        assert_in(
            'root://root.blackmesa.com:1409//training/facility/mock/16/30/half-life_3',
            res)
        assert_in(
            'root://root.aperture.com:1409//test/chamber/mock/16/30/half-life_3',
            res)
        assert_not_in('proxy', res)

        # at location with outgoing proxy, prepend for wan replica
        res = TestApp(redirect_app.wsgifunc(*mw)).get(
            '/mock/half-life_1/metalink?%s' %
            urlencode(self.client_location_with_proxy),
            expect_errors=True)
        body = res.body.decode()
        assert_in(
            'root://proxy.aperture.com:1094//root://root.blackmesa.com:1409//training/facility/mock/c9/df/half-life_1',
            body)
        assert_in(
            'root://root.aperture.com:1409//test/chamber/mock/c9/df/half-life_1',
            body)

        res = TestApp(redirect_app.wsgifunc(*mw)).get(
            '/mock/half-life_2/metalink?%s' %
            urlencode(self.client_location_with_proxy),
            expect_errors=True)
        body = res.body.decode()
        assert_in(
            'root://proxy.aperture.com:1094//root://root.blackmesa.com:1409//training/facility/mock/c1/8d/half-life_2',
            body)
        assert_in(
            'root://root.aperture.com:1409//test/chamber/mock/c1/8d/half-life_2',
            body)

        res = TestApp(redirect_app.wsgifunc(*mw)).get(
            '/mock/half-life_3/metalink?%s' %
            urlencode(self.client_location_with_proxy),
            expect_errors=True)
        body = res.body.decode()
        assert_in(
            'root://proxy.aperture.com:1094//root://root.blackmesa.com:1409//training/facility/mock/16/30/half-life_3',
            body)
        assert_in(
            'root://root.aperture.com:1409//test/chamber/mock/16/30/half-life_3',
            body)
def test_error():
    wrapped = ConfigMiddleware(app_with_exception, {'test': 1})
    test_app = TestApp(wrapped)
    assert_raises(Bug, test_app.get, '/')
Beispiel #16
0
 def get(self, server, url, request_method='GET', expect_errors=False):
     a = TestApp(server._wsgi_func)
     response = a.get(url, expect_errors=expect_errors)
     return self._respond(response, expect_errors)
Beispiel #17
0
def get_app():
    return TestApp('config:%s' % INI)
Beispiel #18
0
 def setUp(self):
   self.app = TestApp(models_api.app.wsgifunc())
   self.headers = getDefaultHTTPHeaders(grok.app.config)
   data = open(os.path.join(grok.app.GROK_HOME,
    "tests/py/data/app/webservices/models_api_integration_test.json")).read()
   self.modelsTestData = json.loads(data)
Beispiel #19
0
    def test_create_existing_subscription(self):
        """ SUBSCRIPTION (REST): Test the creation of a existing subscription """
        mw = []

        headers1 = {
            'X-Rucio-Account': 'root',
            'X-Rucio-Username': '******',
            'X-Rucio-Password': '******'
        }
        headers1.update(self.vo_header)
        res1 = TestApp(auth_app.wsgifunc(*mw)).get('/userpass',
                                                   headers=headers1,
                                                   expect_errors=True)

        assert_equal(res1.status, 200)
        token = str(res1.header('X-Rucio-Auth-Token'))

        subscription_name = uuid()
        headers2 = {'X-Rucio-Auth-Token': str(token)}
        data = dumps({
            'options': {
                'name':
                subscription_name,
                'filter': {
                    'project': self.projects,
                    'datatype': [
                        'AOD',
                    ],
                    'excluded_pattern': self.pattern1,
                    'account': [
                        'tier0',
                    ]
                },
                'replication_rules': [{
                    'lifetime': 86400,
                    'rse_expression': 'MOCK|MOCK2',
                    'copies': 2,
                    'activity': 'Data Brokering'
                }],
                'lifetime':
                100000,
                'retroactive':
                0,
                'dry_run':
                0,
                'comments':
                'We are the knights who say Ni !'
            }
        })
        res2 = TestApp(subs_app.wsgifunc(*mw)).post('/root/' +
                                                    subscription_name,
                                                    headers=headers2,
                                                    params=data,
                                                    expect_errors=True)
        assert_equal(res2.status, 201)

        res3 = TestApp(subs_app.wsgifunc(*mw)).post('/root/' +
                                                    subscription_name,
                                                    headers=headers2,
                                                    params=data,
                                                    expect_errors=True)
        assert_equal(res3.header('ExceptionClass'), 'SubscriptionDuplicate')
        assert_equal(res3.status, 409)
Beispiel #20
0
 def setUp(self):
     #self.headers = getDefaultHTTPHeaders(htm.it.app.config)
     self.app = TestApp(webapp.app.wsgifunc())
 def setUp(self):
     self.headers = getDefaultHTTPHeaders(grok.app.config)
     self.app = TestApp(metrics_api.app.wsgifunc())
Beispiel #22
0
 def test_notfound(self):
     middleware = []
     testApp = TestApp(app.wsgifunc(*middleware))
     r = testApp.get('/storage/test', status="*")
     self.assertEqual(r.status, 404)
Beispiel #23
0
 def setUp(self):
     wsgi_app = self._makeWsgiDAVApp(False)
     self.app = TestApp(wsgi_app)
Beispiel #24
0
    def test_bad_json(self):
        return ["this is neat"]

    test_bad_json = jsonify(test_bad_json)

    def test_good_json(self):
        return dict(fred=42)

    test_good_json = jsonify(test_good_json)


environ = {}
app = ControllerWrap(CacheController)
app = sap = SetupCacheGlobal(app, environ)
app = RegistryManager(app)
app = TestApp(app)


class TestJsonifyDecorator(TestWSGIController):
    def setUp(self):
        self.app = app
        TestWSGIController.setUp(self)
        environ.update(self.environ)
        warnings.simplefilter('error', Warning)

    def tearDown(self):
        warnings.simplefilter('always', Warning)

    def test_bad_json(self):
        try:
            response = self.get_response(action='test_bad_json')
Beispiel #25
0
    op = OptionParser(
            "%prog [-h] [...] ENDPOINT_URL BASEDIR")
    op.add_option('-p', '--port', type=int, default=7070,
            help="Port to serve as web app.")
    op.add_option('-l', '--default-locale', default="en")
    op.add_option('-o', '--one-off-url', default=None,
            help="Process given url once and print to stdout ("
                "doesn't start server).")

    opts, args = op.parse_args()
    if len(args) != 2:
        op.print_usage()
        op.exit()

    endpoint_url = args[0]
    basedir = args[1]
    once_url = opts.one_off_url

    access = discover_access(endpoint_url)
    app = WebApp(access, opts.default_locale, basedir)

    if once_url:
        from paste.fixture import TestApp
        print TestApp(app).get(once_url)
    else:
        logging.basicConfig(level=logging.INFO)
        serve_wsgi(app, port=opts.port)


Beispiel #26
0
from paste.fixture import TestApp
from paste.gzipper import middleware
import gzip
import six


def simple_app(environ, start_response):
    start_response('200 OK', [('content-type', 'text/plain'),
                              ('content-length', '0')])
    return [b'this is a test'] if environ['REQUEST_METHOD'] != 'HEAD' else []


wsgi_app = middleware(simple_app)
app = TestApp(wsgi_app)


def test_gzip():
    res = app.get('/', extra_environ=dict(HTTP_ACCEPT_ENCODING='gzip'))
    assert int(res.header('content-length')) == len(res.body)
    assert res.body != b'this is a test'
    actual = gzip.GzipFile(fileobj=six.BytesIO(res.body)).read()
    assert actual == b'this is a test'


def test_gzip_head():
    res = app.head('/', extra_environ=dict(HTTP_ACCEPT_ENCODING='gzip'))
    assert int(res.header('content-length')) == 0
    assert res.body == b''
Beispiel #27
0
 def client(self):
     return TestApp(self.app.wsgifunc())
Beispiel #28
0
    def test_PUT(self):
        middleware = []
        testApp = TestApp(app.wsgifunc(*middleware))

        # Return 200 OK for putting a valid setting
        r = testApp.put('/thermostats/100/cool_setPoint',
                        params=json.dumps(cool_setPoint))
        json_data = json.loads(r.body)
        assert_equal(r.status, 200)
        assert_equal(json_data, thermostat_cool_set)

        # Return 403 forbidden for assigning string for int value
        r = testApp.put('/thermostats/100/id',
                        params=json.dumps(cool_setPoint_string),
                        status="*")
        assert_equal(r.status, 403)
        r.mustcontain('forbidden')

        # Return 403 forbidden for read only setting
        r = testApp.put('/thermostats/100/id',
                        params=json.dumps(new_id),
                        status="*")
        assert_equal(r.status, 403)
        r.mustcontain('forbidden')

        # Return 400 bad request if put is attempted without a specific setting
        r = testApp.put('/thermostats/100',
                        params=json.dumps(new_id),
                        status="*")
        assert_equal(r.status, 400)
        r.mustcontain('bad request')

        # Return 400 bad request for non-existent setting
        r = testApp.put('/thermostats/100/clock_display',
                        params=json.dumps(new_temp),
                        status="*")
        assert_equal(r.status, 400)
        r.mustcontain('bad request')

        # Return 400 bad request for setting values higher than bounds
        r = testApp.put('/thermostats/100/cool_setPoint',
                        params=json.dumps(high_temp),
                        status="*")
        assert_equal(r.status, 400)
        r.mustcontain('bad request')

        # Return 400 bad request for setting values lower than bounds
        r = testApp.put('/thermostats/100/cool_setPoint',
                        params=json.dumps(low_temp),
                        status="*")
        assert_equal(r.status, 400)
        r.mustcontain('bad request')

        # Return 400 bad request for setting values out of scope
        r = testApp.put('/thermostats/100/operating_mode',
                        params=json.dumps(operating_mode),
                        status="*")
        assert_equal(r.status, 400)
        r.mustcontain('bad request')

        # Return 404 for non-existent thermostat
        r = testApp.put('/thermostats/108/cool_setPoint',
                        params=json.dumps(cool_setPoint),
                        status="*")
        assert_equal(r.status, 404)
        r.mustcontain('not found')
Beispiel #29
0
 def setUp(self):
   self.app = TestApp(instances_api.app.wsgifunc())
   self.headers = getDefaultHTTPHeaders(config)
 def setUp(self):
     self.test_app = TestApp(core.federer.app.wsgifunc())
     self.fixtures_path = 'core/tests/fixtures/'
     self.event_store = EventStore()