Example #1
1
    def test_twitter_login_registration(self, verify_credentials):
        twitter_data = TWITTER_DATA.copy()
        twitter_data["id"] = uuid.uuid4().hex
        verify_credentials.return_value = type("U", (object,), {"AsDict": lambda s: twitter_data})()

        with self.app.test_client() as client:
            token_key, token_secret = "kkkkkkkk", "sssssss"
            for registered in True, False:
                r = client.post(
                    "/ws/login/external/",
                    headers=[get_client_auth_header()],
                    data=dict(external_system="twitter", external_token=token_key + ":" + token_secret),
                )
                self.assertEquals(200, r.status_code)
                creds = json.loads(r.data)
                self.assertEquals(creds["registered"], registered)

            r = client.get(
                creds["resource_url"], headers=[("Authorization", creds["token_type"] + " " + creds["access_token"])]
            )
            data = json.loads(r.data)
            self.assertEquals(data["username"], TWITTER_DATA["screen_name"])
            self.assertEquals(data["display_name"], TWITTER_DATA["name"])
            self.assertTrue(data["avatar_thumbnail_url"])

            token = ExternalToken.query.filter_by(user=creds["user_id"]).one()
            self.assertEquals(token.external_uid, twitter_data["id"])
            self.assertIn("read", token.permissions)
Example #2
0
def decodejson(content):
        print "decode"
	decoded=json.loads(template_json)
        decoded.update(json.loads(str(content)))
	if decoded['v']>2:
		print decoded
        return decoded
Example #3
0
File: api.py Project: heshunwq/hue
def export_result(request):
  response = {'status': -1, 'message': _('Exporting result failed.')}

  # Passed by check_document_access_permission but unused by APIs
  notebook = json.loads(request.POST.get('notebook', '{}'))
  snippet = json.loads(request.POST.get('snippet', '{}'))
  data_format = json.loads(request.POST.get('format', 'hdfs-file'))
  destination = json.loads(request.POST.get('destination', ''))
  overwrite = json.loads(request.POST.get('overwrite', False))

  api = get_api(request, snippet)

  if data_format == 'hdfs-file':
    if overwrite and request.fs.exists(destination):
      if request.fs.isfile(destination):
        request.fs.do_as_user(request.user.username, request.fs.rmtree, destination)
      else:
        raise ValidationError(_("The target path is a directory"))
    response['watch_url'] = api.export_data_as_hdfs_file(snippet, destination, overwrite)
    response['status'] = 0
  elif data_format == 'hive-table':
    notebook_id = notebook['id'] or request.GET.get('editor', request.GET.get('notebook'))
    response['watch_url'] = reverse('notebook:execute_and_watch') + '?action=save_as_table&notebook=' + str(notebook_id) + '&snippet=0&destination=' + destination
    response['status'] = 0
  elif data_format == 'hdfs-directory':
    notebook_id = notebook['id'] or request.GET.get('editor', request.GET.get('notebook'))
    response['watch_url'] = reverse('notebook:execute_and_watch') + '?action=insert_as_query&notebook=' + str(notebook_id) + '&snippet=0&destination=' + destination
    response['status'] = 0

  return JsonResponse(response)
Example #4
0
    def test_13_admin_user_add_del(self):
        """Test ADMIN add/del user to admin group works"""
        self.register()
        self.signout()
        self.register(fullname="Juan Jose", name="juan",
                      email="juan@juan.com", password="juan")
        self.signout()
        # Signin with admin user
        self.signin()
        # Add user.id=1000 (it does not exist)
        res = self.app.get("/admin/users/add/1000", follow_redirects=True)
        err = json.loads(res.data)
        assert res.status_code == 404, res.status_code
        assert err['error'] == "User not found", err
        assert err['status_code'] == 404, err


        # Add user.id=2 to admin group
        res = self.app.get("/admin/users/add/2", follow_redirects=True)
        assert "Current Users with Admin privileges" in res.data
        err_msg = "User.id=2 should be listed as an admin"
        assert "Juan Jose" in res.data, err_msg
        # Remove user.id=2 from admin group
        res = self.app.get("/admin/users/del/2", follow_redirects=True)
        assert "Current Users with Admin privileges" not in res.data
        err_msg = "User.id=2 should be listed as an admin"
        assert "Juan Jose" not in res.data, err_msg
        # Delete a non existant user should return an error
        res = self.app.get("/admin/users/del/5000", follow_redirects=True)
        err = json.loads(res.data)
        assert res.status_code == 404, res.status_code
        assert err['error'] == "User.id not found", err
        assert err['status_code'] == 404, err
Example #5
0
	def request(self, connection, url, headers, data=None, timeout=0):
		result = response = None
		try:
			if data: connection.request('POST', url, data, headers)
			else: connection.request('GET', url, headers=headers)
			response = self.timeout_response(connection, timeout)
			if not response:
				return None
			if response.status == httplib.UNAUTHORIZED:
				say_line('Wrong username or password for %s', self.server().name)
				self.authorization_failed = True
				raise NotAuthorized()
			r = self.max_redirects
			while response.status == httplib.TEMPORARY_REDIRECT:
				response.read()
				url = response.getheader('Location', '')
				if r == 0 or url == '': raise HTTPException('Too much or bad redirects')
				connection.request('GET', url, headers=headers)
				response = self.timeout_response(connection, timeout)
				r -= 1
			self.long_poll_url = response.getheader('X-Long-Polling', '')
			self.switch.update_time = bool(response.getheader('X-Roll-NTime', ''))
			hostList = response.getheader('X-Host-List', '')
			self.stratum_header = response.getheader('x-stratum', '')
			if (not self.options.nsf) and hostList: self.switch.add_servers(loads(hostList))
			result = loads(response.read())
			if result['error']:
				say_line('server error: %s', result['error']['message'])
				raise RPCError(result['error']['message'])
			return (connection, result)
		finally:
			if not result or not response or (response.version == 10 and response.getheader('connection', '') != 'keep-alive') or response.getheader('connection', '') == 'close':
				connection.close()
				connection = None
Example #6
0
def get_free_movies():
	html2 = make_request(url)
	html = json.loads(html2)
	content_id=''
	for r in html['contents']:
		if '1' in r['content_type_id']:
			content_id = r['content_id']
			name = r['title']
	if content_id:
		userurl = 'https://erosnow.com/secured/dologin'
		req = make_request_post(userurl)
		movieurl2 = 'http://erosnow.com/profiles/'+str(content_id)+'?platform=2&q=auto'
		html3 = make_request(movieurl2)
		html4 = json.loads(html3)
		req2 = json.loads(req)
		item2 = xbmcgui.ListItem(name)
		if (str(req2['success']['plan']) == 'False'):
			movie_link = html4['profiles']['ADAPTIVE_SD'][0]
		else:
			movie_link = html4['profiles']['ADAPTIVE_ALL'][0]
			subYes = Addon.getSetting('subType')
			if (subYes=='true') and (html4.get('subtitles')):
				closedcaption=[]
				closedcaption.append(html4['subtitles']['eng']['url'])
				subpath = convert_subtitles(closedcaption)
				item2.setSubtitles([subpath])
		
		item2.setProperty('IsPlayable', 'true')
		item2.setPath(movie_link['url'])
		xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item2)
	else:
		dialog.notification('Error', 'Movie may not be released yet.', xbmcgui.NOTIFICATION_INFO, 6000)
Example #7
0
    def test_ng_delete(self):
        # CRUDTestViewWithFK
        request = self.factory.delete('/crud/?pk=1')
        response = CRUDTestViewWithFK.as_view()(request)
        data = json.loads(response.content.decode('utf-8'))
        deleted_name = data['name']

        request2 = self.factory.get('/crud/')
        response2 = CRUDTestViewWithFK.as_view()(request2)
        data2 = json.loads(response2.content.decode('utf-8'))
        for obj in data2:
            self.assertTrue(deleted_name != obj['name'])

        # CRUDTestViewWithSlug delete is not different from CRUDTestViewWithFK only testing error status codes
        request3 = self.factory.delete('/crud/?email=Anne@example.com')  # Missing pk
        response3 = CRUDTestViewWithSlug.as_view()(request3)
        self.assertEqual(response3.status_code, 400)

        request4 = self.factory.delete('/crud/?pk=100')  # Invalid pk
        response4 = CRUDTestViewWithSlug.as_view()(request4)
        self.assertEqual(response4.status_code, 404)

        # Testing with m2m relationship
        request5 = self.factory.delete('/crud/?pk=%s' % self.m2m_model.pk)
        response5 = CRUDTestViewWithM2M.as_view()(request5)
        self.assertEqual(response5.status_code, 200)
Example #8
0
    def test_ng_save_create(self):
        # CRUDTestViewWithFK
        request = self.factory.post('/crud/',
                                    data=json.dumps({'name': 'Leonard'}),
                                    content_type='application/json')
        response = CRUDTestView.as_view()(request)
        data = json.loads(response.content.decode('utf-8'))
        pk = data['pk']

        request2 = self.factory.get('/crud/?pk={0}'.format(pk))
        response2 = CRUDTestView.as_view()(request2)
        data2 = json.loads(response2.content.decode('utf-8'))
        self.assertEqual(data2['name'], 'Leonard')

        # CRUDTestViewWithSlug
        request3 = self.factory.post('/crud/',
                                    data=json.dumps({'name': 'Leonard', 'email': 'Leonard@example.com'}),
                                    content_type='application/json')
        CRUDTestViewWithSlug.as_view()(request3)

        request4 = self.factory.get('/crud/?email={0}'.format('Leonard@example.com'))
        response4 = CRUDTestViewWithSlug.as_view()(request4)
        data4 = json.loads(response4.content.decode('utf-8'))
        self.assertEqual(data4['name'], 'Leonard')

        request5 = self.factory.post('/crud/',
                                    data=json.dumps({'name': 'Leonard2', 'email': 'Leonard@example.com'}),
                                    content_type='application/json')
        response5 = CRUDTestViewWithSlug.as_view()(request5)
        self.assertGreaterEqual(response5.status_code, 400)
        data5 = json.loads(response5.content.decode('utf-8'))
        self.assertTrue('detail' in data5 and 'email' in data5['detail'] and len(data5['detail']['email']) > 0)
def parse_xobject(xobject, queue_name):
    """
        Parse a queue object from xqueue:
        { 'return_code': 0 (success), 1 (fail)
        'content': Message from xqueue (string)
        }
        """
    try:
        xobject = json.loads(xobject)
        
        header = json.loads(xobject['xqueue_header'])
        header.update({'queue_name': queue_name})
        body = json.loads(xobject['xqueue_body'])
        files = json.loads(xobject['xqueue_files'])
        
        content = {'xqueue_header': json.dumps(header),
            'xqueue_body': json.dumps(body),
            'xqueue_files': json.dumps(files)
        }
    except ValueError:
        error_message = "Unexpected reply from server."
        log.error(error_message)
        return (False, error_message)
    
    return True, content
def lambda_handler(event, context):
    invoking_event = json.loads(event["invokingEvent"])
    configuration_item = invoking_event["configurationItem"]
    rule_parameters = json.loads(event["ruleParameters"])

    result_token = "No token found."
    if "resultToken" in event:
        result_token = event["resultToken"]

    evaluation = evaluate_compliance(configuration_item, rule_parameters)

    config = boto3.client("config")
    config.put_evaluations(
        Evaluations=[
            {
                "ComplianceResourceType":
                    configuration_item["resourceType"],
                "ComplianceResourceId":
                    configuration_item["resourceId"],
                "ComplianceType":
                    evaluation["compliance_type"],
                "Annotation":
                    evaluation["annotation"],
                "OrderingTimestamp":
                    configuration_item["configurationItemCaptureTime"]
            },
        ],
        ResultToken=result_token
    )
Example #11
0
    def test_bad_client_id(self, text_id):
        action = consts.MESSAGE_POST
        body = {
            "queue_name": "kinder",
            "messages": [{"ttl": 60,
                          "body": ""}]
        }
        headers = {
            'Client-ID': text_id,
            'X-Project-ID': self.project_id
        }

        send_mock = mock.Mock()
        self.protocol.sendMessage = send_mock

        req = test_utils.create_request(action, body, headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(400, resp['headers']['status'])

        action = consts.MESSAGE_GET
        body = {
            "queue_name": "kinder",
            "limit": 3,
            "echo": True
        }

        req = test_utils.create_request(action, body, headers)
        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(400, resp['headers']['status'])
Example #12
0
    def test_post_optional_ttl(self):
        messages = [{'body': 239},
                    {'body': {'key': 'value'}, 'ttl': 200}]

        action = consts.MESSAGE_POST
        body = {"queue_name": "kitkat",
                "messages": messages}
        req = test_utils.create_request(action, body, self.headers)

        send_mock = mock.Mock()
        self.protocol.sendMessage = send_mock

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(201, resp['headers']['status'])
        msg_id = resp['body']['message_ids'][0]

        action = consts.MESSAGE_GET
        body = {"queue_name": "kitkat", "message_id": msg_id}

        req = test_utils.create_request(action, body, self.headers)

        self.protocol.onMessage(req, False)

        resp = json.loads(send_mock.call_args[0][0].decode())
        self.assertEqual(200, resp['headers']['status'])
        self.assertEqual(self.default_message_ttl,
                         resp['body']['messages']['ttl'])
def get_relation_types():
    relation_arg_count = Counter()
    
    for line in sys.stdin:
        if line[0] == '#':
            continue
        line = line.strip()
        if  line.strip() == "":
            continue
        line = line.split("\t")
        entities = json.loads(line[0])
        relations = json.loads(line[1])
        
        if type(entities) == type([]):
            entity1 = entities[0]
            entity2 = entities[1]
            if entity1[:2] == "m." and  entity2[:2] == "m.":
                for relation in relations:
                    relation = json.dumps(relation);
                    if str(relation).find("date") > -1:
                        continue
                    relation_arg_count["%s # %s # left_arg" %(entity1, relation)] += 1 
                    relation_arg_count["%s # %s # right_arg" %(entity2, relation)] += 1
        if len(relation_arg_count) > 50000:
            relation_arg_count = Counter(dict(relation_arg_count.most_common(30000)))
            # break
        
    relation_counter = Counter()
    for key, value in relation_arg_count.most_common(100):
        relation = key.split(" # ", 1)[1]
        relation_counter[relation] += value
        # print "%s\t%s" %(key, value)
        
    for key, value in relation_counter.most_common(10):
        print "%s\t%s" %(key, value)
Example #14
0
def test_add_switch(host, add_switch, test_file):
	with open(test_file('list/switch_with_make_and_model_output.json')) as output:
		expected_output = output.read()

	result = host.run('stack list switch output-format=json')
	assert result.rc == 0
	assert json.loads(result.stdout) == json.loads(expected_output)
Example #15
0
def fetch_token_header_payload(token):
    """
    Fetch the header and payload out of the JWT token.
    :param token:
    :return: :raise jwt.DecodeError:
    """
    token = token.encode('utf-8')
    try:
        signing_input, crypto_segment = token.rsplit(b'.', 1)
        header_segment, payload_segment = signing_input.split(b'.', 1)
    except ValueError:
        raise jwt.DecodeError('Not enough segments')

    try:
        header = json.loads(jwt.utils.base64url_decode(header_segment).decode('utf-8'))
    except TypeError as e:
        current_app.logger.exception(e)
        raise jwt.DecodeError('Invalid header padding')

    try:
        payload = json.loads(jwt.utils.base64url_decode(payload_segment).decode('utf-8'))
    except TypeError as e:
        current_app.logger.exception(e)
        raise jwt.DecodeError('Invalid payload padding')

    return (header, payload)
Example #16
0
    def test_particles(self):
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        request = {
            'streams': [
                {
                    "node": "XX00X",
                    "stream": "ctdpf_ckl_wfp_instrument_recovered",
                    "subsite": "XX00XXXX",
                    "sensor": "00-CTDPFW100",
                    "method": "recovered",
                    "parameters": [1959]
                }
            ],
            'coefficients': {
                'CC_latitude': [{'value': 1.0, 'deployment': 1}],
                'CC_longitude': [{'value': 1.0, 'deployment': 1}],
            },
            'include_provenance': False,
            'include_annotations': False,
            'qcParameters': {}
        }

        r = self.app.post('/particles', data=json.dumps(request), headers=headers)
        data = json.loads(r.data)
        with open(TEST_DIR + '/test_particles.json', mode='r') as f:
            testdata = json.loads(f.read())
            assert _almost_equal(data, testdata)
Example #17
0
    def put(self, request, pk, subject, record, *args, **kwargs):
        '''
        Updates the subject record. Currently only changing the records label is
        supported.

        If successful the updated external record is returned
        '''
        try:
            pds = ProtocolDataSource.objects.get(pk=pk)
        except ObjectDoesNotExist:
            return Response({'error': 'ProtocolDatasource requested not found'}, status=404)

        if pds.protocol.isUserAuthorized(request.user):
            ex_rec = json.loads(request.body.decode('utf-8'))
            rec = self.er_rh.get(id=ex_rec['id'])
            rec.label_id = ex_rec['label_id']
            rec.modified = datetime.now()
            res = self.er_rh.update(rec)[0]
            if res['success']:
                ex_rec = res['external_record']
                return Response(json.loads(ex_rec.json_from_identity(ex_rec)))
            else:
                return Response({
                    'success': res['success'],
                    'errors': res['errors']},
                    status=422)
        else:
            return Response(
                {"detail": "You are not authorized to view records from this protocol"},
                status=403
            )
Example #18
0
    def test_pubsub(self):

        check_pubsub = self.redis.pubsub()
        check_pubsub.psubscribe("gottwall:*")
        next(check_pubsub.listen())

        cli = RedisClient(
            private_key=private_key,
            public_key=public_key,
            project=project,
            host=HOST)
        ts = datetime.utcnow()

        self.assertEquals("gottwall:{0}:{1}:{2}".format(project, public_key, private_key), cli.channel)
        cli.incr(name="orders", value=2, timestamp=ts, filters={"current_status": "Completed"})

        message = next(check_pubsub.listen())

        self.assertEquals(message['channel'], 'gottwall:{0}:{1}:{2}'.format(project, public_key, private_key))

        notification_message = json.loads(message['data'])
        self.assertEquals(notification_message['type'], 'notification')

        data_dict = json.loads(self.redis.spop(cli.data_key))
        self.assertTrue(data_dict['name'], 'orders')
        self.assertTrue(data_dict['timestamp'], ts.strftime("%Y-%m-%dT%H:%M:%S"))
        self.assertTrue(data_dict['filters']['current_status'], 'Completed')

        self.assertEquals(self.redis.scard(cli.data_key), 0)
Example #19
0
    def test_ng_save_update(self):
        # CRUDTestViewWithFK
        request = self.factory.post('/crud/?pk=1',
                                    data=json.dumps({'pk': 1, 'name': 'John2'}),
                                    content_type='application/json')
        response = CRUDTestView.as_view()(request)
        data = json.loads(response.content.decode('utf-8'))
        self.assertEqual(data['name'], 'John2')

        request2 = self.factory.get('/crud/?pk=1')
        response2 = CRUDTestView.as_view()(request2)
        data2 = json.loads(response2.content.decode('utf-8'))
        self.assertEqual(data2['name'], 'John2')

        # CRUDTestViewWithSlug
        request3 = self.factory.post('/crud/?pk=1',
                                    data=json.dumps({'name': 'John', 'email': 'John2@example.com'}),
                                    content_type='application/json')
        response3 = CRUDTestViewWithSlug.as_view()(request3)
        data3 = json.loads(response3.content.decode('utf-8'))
        self.assertEqual(data3['name'], 'John')
        self.assertEqual(data3['email'], 'John2@example.com')

        request4 = self.factory.get('/crud/?email=John2@example.com')
        response4 = CRUDTestViewWithSlug.as_view()(request4)
        data4 = json.loads(response4.content.decode('utf-8'))
        self.assertEqual(data4['name'], 'John')

        request5 = self.factory.post('/crud/?pk=3',  # Modifying "Chris"
                                    data=json.dumps({'pk': 4, 'name': 'John2', 'email': 'John2@example.com'}),
                                    content_type='application/json')
        response5 = CRUDTestViewWithSlug.as_view()(request5)
        self.assertGreaterEqual(response5.status_code, 400)
        data5 = json.loads(response5.content.decode('utf-8'))
        self.assertTrue('detail' in data5 and 'email' in data5['detail'] and len(data5['detail']['email']) > 0)
 def _call(self, method, params, json_rpc_call_context = None):
     arg_hash = {'method': method,
                 'params': params,
                 'version': '1.1',
                 'id': str(_random.random())[2:]
                 }
     if json_rpc_call_context:
         arg_hash['context'] = json_rpc_call_context
     body = json.dumps(arg_hash, cls=JSONObjectEncoder)
     ret = _requests.post(self.url, data=body, headers=self._headers,
                          timeout=self.timeout,
                          verify=not self.trust_all_ssl_certificates)
     if ret.status_code == _requests.codes.server_error:
         if 'content-type' in ret.headers and ret.headers['content-type'] == 'application/json':
             err = json.loads(ret.text)
             if 'error' in err:
                 raise ServerError(**err['error'])
             else:
                 raise ServerError('Unknown', 0, ret.text)
         else:
             raise ServerError('Unknown', 0, ret.text)
     if ret.status_code != _requests.codes.OK:
         ret.raise_for_status()
     resp = json.loads(ret.text)
     if 'result' not in resp:
         raise ServerError('Unknown', 0, 'An unknown server error occurred')
     return resp['result']
Example #21
0
	def test_view_get_report_data(self):
		url = reverse('activities.views.get_report_data')

		self.client.login(username='test1', password='test1')

		resp = self.client.get(url, {"startdate": 1325376000000, "enddate": 13885344000000})
		response = json.loads(resp.content)
		self.assertEqual(response, {})

		resp = self.client.get(url, {"startdate": 1325376000000, "enddate": 1388534400000, "mode": "sports", "param": "eyJldmVudHMiOiBbM10sICJzcG9ydHMiOiBbMiwgM119"})
		response = json.loads(resp.content)
		self.assertIn('Laufen', response)
		self.assertIn('Rennrad', response)
		self.assertIn('Schwimmen', response)
		self.assertEquals(response['Schwimmen'], {u'total_time': 0, u'total_calories': 0, u'color': u'#66ccff', u'num_activities': 0, u'total_time_str': u'0:00:00', u'total_distance': 0.0, u'total_elev_gain': 0})
		self.assertEquals(response['Laufen'], {u'total_time': 11018, u'total_calories': 2493, u'color': u'#cc6600', u'num_activities': 2, u'total_time_str': u'3:03:38', u'total_distance': 37.808, u'total_elev_gain': 896})

		resp = self.client.get(url, {"startdate": 1325376000000, "enddate": 1388534400000, "mode": "weeks"})
		response = json.loads(resp.content)
		self.assertEqual(response, {u'count': [], u'distance': [], u'calories': [], u'time': []})

		resp = self.client.get(url, {"startdate": 1325376000000, "enddate": 1388534400000, "mode": "weeks", "param": "eyJldmVudHMiOiBbM10sICJzcG9ydHMiOiBbMiwgM119"})
		response = json.loads(resp.content)
		resp_time_bike = response["time"][1]  # by-week list of bike times
		self.assertEqual(len(resp_time_bike["data"]), 106)  # covering 106 weeks
		self.assertEqual(resp_time_bike["data"][0][1], 0)   # no activity in week 0
		self.assertEqual(resp_time_bike["data"][87][1], 80)  # activity in week 87
Example #22
0
def _post_process(snapshot, bots_active, bots_inactive, tasks_active):
  """Completes the _Snapshot instance with additional data."""
  for dimensions_json, tasks in tasks_active.iteritems():
    snapshot.get_dimensions(dimensions_json).tasks_active = len(tasks)

  snapshot.bot_ids = sorted(bots_active)
  snapshot.bot_ids_bad = sorted(bots_inactive)
  for bot_id, dimensions in bots_active.iteritems():
    # Looks at the current buckets, do not create one.
    for bucket in snapshot.buckets:
      # If this bot matches these dimensions, mark it as a member of this group.
      if task_to_run.match_dimensions(
          json.loads(bucket.dimensions), dimensions):
        # This bot could be used for requests on this dimensions filter.
        if not bot_id in bucket.bot_ids:
          bucket.bot_ids.append(bot_id)
          bucket.bot_ids.sort()

  for bot_id, dimensions in bots_inactive.iteritems():
    # Looks at the current buckets, do not create one.
    for bucket in snapshot.buckets:
      # If this bot matches these dimensions, mark it as a member of this group.
      if task_to_run.match_dimensions(
          json.loads(bucket.dimensions), dimensions):
        # This bot could be used for requests on this dimensions filter.
        if not bot_id in bucket.bot_ids_bad:
          bucket.bot_ids_bad.append(bot_id)
          bucket.bot_ids_bad.sort()
def test_list_inconsistent_obj(ctx, manager, osd_remote, pg, acting, osd_id,
                               obj_name, obj_path):
    mon = manager.controller
    pool = 'rbd'
    omap_key = 'key'
    omap_val = 'val'
    manager.do_rados(mon, ['-p', pool, 'setomapval', obj_name,
                           omap_key, omap_val])
    messup = MessUp(manager, osd_remote, pool, osd_id, obj_name, obj_path,
                    omap_key, omap_val)
    for test in [messup.rm_omap, messup.add_omap, messup.change_omap,
                 messup.append, messup.truncate, messup.change_obj,
                 messup.remove]:
        with test() as checks:
            deep_scrub(manager, pg)
            cmd = 'rados list-inconsistent-pg {pool} ' \
                  '--format=json'.format(pool=pool)
            with contextlib.closing(StringIO()) as out:
                mon.run(args=cmd.split(), stdout=out)
                pgs = json.loads(out.getvalue())
            assert pgs == [pg]

            cmd = 'rados list-inconsistent-obj {pg} ' \
                  '--format=json'.format(pg=pg)
            with contextlib.closing(StringIO()) as out:
                mon.run(args=cmd.split(), stdout=out)
                objs = json.loads(out.getvalue())
            assert len(objs['inconsistents']) == 1

            checker = InconsistentObjChecker(osd_id, acting, obj_name)
            inc_obj = objs['inconsistents'][0]
            log.info('inc = %r', inc_obj)
            checker.basic_checks(inc_obj)
            for check in checks:
                checker.run(check, inc_obj)
 def loadCanopyList(self): #loads the canopy list once per mapper
     for line in open('C:\Users\Peter\workspace\mrjobTest\src\clusters\part-00000').readlines():
         lineArr = line.strip().split('\t')
         valuesList = json.loads(lineArr[1])
         colList = json.loads(lineArr[0])
         sprsCanopy = coo_matrix((array(valuesList), (zeros(len(colList)), array(colList))), shape=(1,self.options.numitems))
         self.canopyList.append(sprsCanopy)
def get_servlet_stats(base_url, url, user, password):
    monitor_status = json.loads(retrieve_status_page(
                                user, password, base_url+url))
    serv_stats = {}

    attribute_array = monitor_status.get("attributes")
    servlet_url = servlet_get_url(attribute_array, "ResponseTimeDetails")
    servlet_status = json.loads(retrieve_status_page(
                                user, password, base_url+servlet_url))

    serv_stats["reqCount"] = servlet_status.get("value").get("count")
    serv_stats["responseMean"] = servlet_status.get("value").get("mean")
    serv_stats["responseMax"] = servlet_status.get("value").get("maximumValue")
    serv_stats["responseMin"] = servlet_status.get("value").get("minimumValue")

    servlet_url = servlet_get_url(attribute_array, "ServletName")
    servlet_status = json.loads(retrieve_status_page(
                                user, password, base_url + servlet_url))
    serv_stats["name"] = servlet_status.get("value")

    servlet_url = servlet_get_url(attribute_array, "AppName")
    servlet_status = json.loads(retrieve_status_page(
                                user, password, base_url + servlet_url))
    serv_stats["appName"] = servlet_status.get("value")
    return serv_stats
Example #26
0
def urls(request):
    if request.method == "GET":
        urls = list(URL.objects.values())
        urls_json = json.dumps(urls)
        return HttpResponse(urls_json, content_type="application/json")
    elif request.method == "POST":
        try:
            payload = json.loads(request.body)
        except:
            return mock_server_error("Fail to unmarshal json string")
        if "name" not in payload or "pattern" not in payload:
            return mock_server_error("Lacking required field")
        try:
            re.compile(payload["pattern"])
        except:
            return mock_server_error("invalid regular expression")
        url = URL(name=payload["name"], pattern=payload["pattern"])
        url.save()
        return mock_server_success()
    elif request.method == "DELETE":
        try:
            payload = json.loads(request.body)
        except:
            return mock_server_error("Fail to unmarshal json string")
        if "id" not in payload:
            return mock_server_error("Lacking required field:id")
        try:
            url = URL.objects.get(id=int(payload["id"]))
        except:
            return mock_server_error("URL not found")
        url.delete()
        return mock_server_success()
    else:
        return mock_server_error("HTTP method not supported.")
Example #27
0
File: api.py Project: heshunwq/hue
def get_logs(request):
  response = {'status': -1}

  notebook = json.loads(request.POST.get('notebook', '{}'))
  snippet = json.loads(request.POST.get('snippet', '{}'))

  startFrom = request.POST.get('from')
  startFrom = int(startFrom) if startFrom else None

  size = request.POST.get('size')
  size = int(size) if size else None

  db = get_api(request, snippet)

  logs = db.get_log(notebook, snippet, startFrom=startFrom, size=size)

  jobs = json.loads(request.POST.get('jobs', '[]'))

  # Get any new jobs from current logs snippet
  new_jobs = db.get_jobs(notebook, snippet, logs)

  # Append new jobs to known jobs and get the unique set
  if new_jobs:
    all_jobs = jobs + new_jobs
    jobs = dict((job['name'], job) for job in all_jobs).values()

  # Retrieve full log for job progress parsing
  full_log = request.POST.get('full_log', logs)

  response['logs'] = logs
  response['progress'] = db.progress(snippet, full_log) if snippet['status'] != 'available' and snippet['status'] != 'success' else 100
  response['jobs'] = jobs
  response['status'] = 0

  return JsonResponse(response)
    def post(self, match_key):
        self._require_admin()
        alliances_json = self.request.get("alliances_json")
        alliances = json.loads(alliances_json)
        youtube_videos = json.loads(self.request.get("youtube_videos"))
        team_key_names = list()

        for alliance in alliances:
            team_key_names.extend(alliances[alliance].get('teams', None))

        match = Match(
            id=match_key,
            event=Event.get_by_id(self.request.get("event_key_name")).key,
            set_number=int(self.request.get("set_number")),
            match_number=int(self.request.get("match_number")),
            comp_level=self.request.get("comp_level"),
            team_key_names=team_key_names,
            alliances_json=alliances_json,
            # no_auto_update = str(self.request.get("no_auto_update")).lower() == "true", #TODO
        )
        match = MatchManipulator.createOrUpdate(match)
        match.youtube_videos = youtube_videos
        match.dirty = True  # hacky
        MatchManipulator.createOrUpdate(match)

        self.redirect("/admin/match/" + match.key_name)
Example #29
0
    def test_where_3_way_logic(self):
        #             This column
        #                 ⇓
        #  ___________________
        # |     | col1 | col2 |
        #  -------------------
        # | r1  |  1   |      | ⇐ This row
        #  -------------------
        # | r2  |  1   |  2   |
        #  -------------------

        response = requests.get(self.dataset_url)
        datasets = json.loads(response.content)
        self.assertEqual(response.status_code, 200,
            msg="Couldn't get the list of datasets")
        self.assertEqual(datasets['status']['rowCount'], 2,
            msg="2 rows should be in the dataset. r1 and r2")

        params = {
            "select":'col1',
            "where":"'col2' < 2"
        }

        response = requests.get(self.dataset_url + '/query', params=params)
        content = json.loads(response.content)
        self.assertEqual(len(content), 0,
            msg="The query should have returned no results")
Example #30
0
    def pretty_log(self, args, kwargs, resp, body):
        if not _logger.isEnabledFor(logging.DEBUG):
            return

        string_parts = ['curl -i']
        for element in args:
            if element in ('GET', 'POST'):
                string_parts.append(' -X %s' % element)
            else:
                string_parts.append(' %s' % element)

        for element in kwargs['headers']:
            header = ' -H "%s: %s"' % (element, kwargs['headers'][element])
            string_parts.append(header)

        curl_cmd = "".join(string_parts)
        _logger.debug("REQUEST:")
        if 'body' in kwargs:
            _logger.debug("%s -d '%s'" % (curl_cmd, kwargs['body']))
            try:
                req_body = json.dumps(json.loads(kwargs['body']),
                                      sort_keys=True, indent=4)
            except:
                req_body = kwargs['body']
            _logger.debug("BODY: %s\n" % (req_body))
        else:
            _logger.debug(curl_cmd)

        try:
            resp_body = json.dumps(json.loads(body), sort_keys=True, indent=4)
        except:
            resp_body = body
        _logger.debug("RESPONSE HEADERS: %s" % resp)
        _logger.debug("RESPONSE BODY   : %s" % resp_body)