def send_to_users(cls, userids, pl_type, payload): """ :param userids: list of userids to send the data to :param pl_type: Type of the payload as an arbitrary string :param payload: dictionary that will be json encoded and send to each user :return: """ cls.connect() data = {"users": userids, "type": pl_type, "payload": payload} cls.r.publish('notifications', json_stringify(data))
def send_to_users(cls, userids, data): """ :param userids: list of userids to send the data to :param data: dictionary that will be json encoded and send to each user :return: """ cls.connect() cls.r.publish( 'notifications', '{{"users" : [{}], "data": {}}}'.format( ','.join(map(str, userids)), json_stringify(data)))
def when_calling_endpoint(self): method = self.request_data['method'].lower() path = self.request_data['endpoint'] data = self.request_data.get('body') api = getattr(self._client, method) try: self.actual_response = api( path=path, data=json_stringify(data), content_type='application/json', ) except Exception as e: self.actual_exception = TracebackException.from_exception(e)
def when_calling_endpoint(self): method = self.request_data['method'].lower() path = self.request_data['endpoint'] data = self.request_data.get('body') api = getattr(self._client, method) try: self.actual_response = api( path=path, data=json_stringify(data), content_type='application/json', ) except Exception as e: self.actual_exception = e
def send_to_users(cls, userids, data): """ :param userids: list of userids to send the data to :param data: dictionary that will be json encoded and send to each user :return: """ cls.connect() cls.r.publish('notifications', '{{"users" : [{}], "data": {}}}'.format(','.join(map(str, userids)), json_stringify(data)))
def post(self, path, data=None, **kwargs): return super().post( path=path, data=json_stringify(data), content_type='application/json; charset=utf-8', )
def given_json_response(self, content): self.given_raw_response(json_stringify(content))
def test_json_stringify_creates_json_from_dict(self): result = json_stringify({'a': 1, 'b': [2, 3], 'c': {'d': 4}}) self.assertEqual(result, b'{"a":1,"b":[2,3],"c":{"d":4}}')
def test_json_stringify_creates_none_from_none(self): result = json_stringify(None) self.assertEqual(result, None)