Exemplo n.º 1
0
    def test_serializeToDictionary_ShouldSerializeObjectToJsonDictionaryObject(self):
        employeeInstance = Employee.createSampleInstance()
        jsonSerializer = Serializer()
        employeeJsonDictionary = jsonSerializer.serialize_to_dictionary(employeeInstance)

        assert employeeJsonDictionary is not None
        assert isinstance(employeeJsonDictionary, dict)
        assert len(employeeJsonDictionary) > 0
Exemplo n.º 2
0
    def test_serializeToString_ShouldSerializeObjectToJsonStringFormat(self):
        employeeInstance = Employee.createSampleInstance()
        jsonSerializer = Serializer()
        employeeJsonString = jsonSerializer.serialize_to_string(employeeInstance)

        assert employeeJsonString is not None
        assert employeeJsonString.strip() != ""
        assert employeeJsonString.strip() != "null"
        assert isinstance(employeeJsonString, str)
Exemplo n.º 3
0
 def _get_document(self, data):
     if not hasattr(data, "_id") or not data._id:
         data._id = ObjectId()
     elif isinstance(data._id, str):
         data._id = ObjectId(data._id)
     json_serializer = Serializer()
     json_serializer.add_handler(datetime, DatetimeBsonSerializeHandler)
     json_serializer.add_handler(ObjectId, ObjectIdBsonSerializeHandler)
     document = json_serializer.serialize_to_dictionary(data)
     data._id = str(data._id)
     return document
Exemplo n.º 4
0
def _response_get(data, meta=None, is_error=False):
    key = "data"
    if is_error:
        key = "errors"
    result = {key: data}
    if meta:
        result["meta"] = meta
    serializer = Serializer()
    dict_result = serializer.serialize_to_dictionary(result, False)
    response = jsonify(dict_result)
    return _response_set_detail_access(response)
Exemplo n.º 5
0
 def execute(self):
     json_serializer = Serializer()
     current_id = str(ObjectId())
     while True:
         time.sleep(5)
         try:
             notifications = Notification.notification_new_updates_by_receiver_id_and_message_type(self.receiver_id, self.message_type, current_id)
             if notifications:
                 current_id = notifications[0]._id
                 serialized_notification = json_serializer.serialize_to_string(notifications)
                 result = "data:{}{}".format(serialized_notification, '\nretry:500\n\n')
                 yield result
         except StopIteration:
             continue
Exemplo n.º 6
0
    def test_se(self):
        ser = Serializer()
        ser.add_handler(datetime, DatetimeBsonSerializeHandler)
        ser.add_handler(ObjectId, ObjectIdBsonSerializeHandler)
        res = ser.serialize_to_dictionary([{
            'body': 'PERSON_EMAIL_EXIST',
            'code': 'err2001',
            'data': '*****@*****.**'
        }, {
            'body': 'PERSON_EMAIL_EXIST',
            'code': 'err2001',
            'data': '*****@*****.**'
        }], False)

        print(res)
Exemplo n.º 7
0
 def claim_edit(self, user_id, claim):
     serializer = Serializer()
     claim_dict = serializer.serialize_to_dictionary(claim)
     self._collection.writer.edit_by_condition(
         {"$and": {"_id": ObjectId(user_id), "claims._id": claim._id}}, {"$set": {"claims.$": claim_dict}}
     )
Exemplo n.º 8
0
 def claim_add(self, user_id, claim):
     serializer = Serializer()
     claim_dict = serializer.serialize_to_dictionary(claim)
     self._collection.writer.edit_by_condition({"_id": ObjectId(user_id)}, {"$push": {"claims": claim_dict}})
Exemplo n.º 9
0
 def encode(self, object):
     json_serializer = Serializer()
     object_json_string = json_serializer.serialize_to_string(object)
     encoded_string = super().encode(object_json_string)
     return encoded_string
Exemplo n.º 10
0
 def createSampleJson():
     json_serializer = Serializer()
     return json_serializer.serialize_to_string(Employee.createSampleInstance())
Exemplo n.º 11
0
 def password_change(self, user_id, new_password):
     serializer = Serializer()
     password_dict = serializer.serialize_to_dictionary(new_password)
     self._collection.writer.edit_by_condition({"_id": ObjectId(user_id)},
                                               {"$set": {"password": password_dict}})