def test_message_override(self): e = DoesNotExist() e.message = 'The limit does not exist' self.objects_mock.get.side_effect = e response = self.fetch('/api/v1/commands/id') output = json.loads(response.body.decode('utf-8')) self.assertEqual(404, response.code) self.assertIsNotNone(output.get('message')) self.assertNotEqual(e.message, output.get('message'))
def drop(self, name, force=False, version=-1): """ Drop the object :param name: The name of the object :param force: If True ignores DoesNotExist exception, defaults to False meaning this raises a DoesNotExist exception of the name does not exist :return: True if object was deleted, False if not. If force is True and the object does not exist it will still return True """ meta = self.metadata(name, version=version) if meta is None and not force: raise DoesNotExist() collection = self.collection(name) if collection: self.mongodb.drop_collection(collection.name) if meta: if meta.collection: self.mongodb.drop_collection(meta.collection) self._drop_metadata(name) return True if meta and meta.gridfile is not None: meta.gridfile.delete() self._drop_metadata(name) return True return False
def get(self, **kwargs): """ Retrieves an embedded document determined by the given keyword arguments. :param kwargs: The keyword arguments corresponding to the fields to search on. *Multiple arguments are treated as if they are ANDed together.* :return: The embedded document matched by the given keyword arguments. Raises ``DoesNotExist`` if the arguments used to query an embedded document returns no results. ``MultipleObjectsReturned`` if more than one result is returned. """ values = self.__only_matches(self, kwargs) if len(values) == 0: raise DoesNotExist( '%s matching query does not exist.' % self._name ) elif len(values) > 1: raise MultipleObjectsReturned( '%d items returned, instead of 1' % len(values) ) return values[0]
def fetch(self, force=False): if not self._cached_doc or force: self._cached_doc = self.document_type.objects.get(pk=self.pk) if not self._cached_doc: raise DoesNotExist( 'Trying to dereference unknown document %s' % (self)) return self._cached_doc
def get_account(account: int): """ Returns an account object based on user ID """ try: account = Account.objects().get(id=account).to_mongo().to_dict() return account except: raise DoesNotExist("Account does not exists")
def get(self, **lookup): for item in self.items: if all([ getattr(item, key, None) == value for key, value in lookup.items() ]): return item raise DoesNotExist()
def save(self, **kwargs): self.validated_data['user_details'] = self._context['request'].user user = self.validated_data['user_details'] try: email_list = User.objects.get(username=user) except ObjectDoesNotExist: raise DoesNotExist("User email Not Exist") return super().save(**kwargs)
def get_bot(id: str): """ fetches bot details :param id: bot id :return: bot details """ try: return Bot.objects().get(id=id).to_mongo().to_dict() except: raise DoesNotExist("Bot does not exists!")
def get_user(email: str): """ fetch user details :param email: user login id :return: user details """ try: return User.objects().get(email=email).to_mongo().to_dict() except: raise DoesNotExist("User does not exist!")
def get_account(account: int): """ fetch account object :param account: account id :return: account details """ try: account = Account.objects().get(id=account).to_mongo().to_dict() return account except: raise DoesNotExist("Account does not exists")
def get_user(email: str): """ fetch user details :param email: user login id :return: user details """ try: return User.objects(email__iexact=email, status=True).get().to_mongo().to_dict() except Exception as e: logging.error(e) raise DoesNotExist("User does not exist!")
def get_task(id, context): if not isinstance(id, str): raise TypeError('Type of id must be str') if not isinstance(context, dict): raise TypeError('Type of context must be dict') if 'user_id' in context and context['user_id']: user_id = context['user_id'] query = Q(id=id) & Q(owner=user_id) meta = TaskMetadata.from_id(query) else: raise DoesNotExist('task does not exists for None user') return meta
def update(self, mongoid, update_data): if not isinstance(update_data, dict): raise TypeError( '*** Update data should be dict type not: {}'.format( type(update_data))) query_dict = dict(id=mongoid) self.add_default_filters(query_dict) model_dict = self.main_model.objects(**query_dict).first() if model_dict: # Frontend tarafından gelebilecek olan `$` ile başlayan alanları sil print("update_data: {}".format(update_data)) HttpHelper.clear_invalid_values(update_data) self.add_default_update_data(update_dict=update_data) # Assign update_data values to document for key, value in update_data.items(): lookup_field = self.lookup_model_field(key) if self.is_reference_field( lookup_field) or self.is_object_id_field(lookup_field): value = ObjectId(value) model_dict[key] = value return model_dict.save() raise DoesNotExist('Kayıt bulunamadı veya erişim yetkiniz yok')
def get_tasks(context, filter=None): if not isinstance(context, dict): raise TypeError('Type of context must be dict') if not isinstance(filter, (dict, type(None))): raise TypeError('Type of context must be dict') if 'user_id' not in context and not context['user_id']: raise DoesNotExist('task does not exists for None user') user_id = context['user_id'] query = Q(owner=user_id) metas = TaskMetadata.objects(query) if filter: if 'from' in filter: from_ = filter['from'] metas = metas.skip(from_) if 'number' in filter: number = filter['number'] metas = metas.limit(number) return metas
def get_user(email: str): """ Returns the user object based on input email """ try: return User.objects().get(email=email).to_mongo().to_dict() except: raise DoesNotExist("User does not exist!")
def get_bot(id: str): """ Loads the bot based on user ID """ try: return Bot.objects().get(id=id).to_mongo().to_dict() except: raise DoesNotExist("Bot does not exists!")
def get_bot(name: str): try: return Bot.objects(status=True).get(name=name).to_mongo().to_dict() except: raise DoesNotExist("Bot does not exists!")
def get_user(email: str): try: return User.objects().get(email=email).to_mongo().to_dict() except: raise DoesNotExist("User does not exists!")
def get_bot(id: str): try: return Bot.objects().get(id=id).to_mongo().to_dict() except: raise DoesNotExist("Bot does not exists!")
def get_account(account: int): try: return Account.objects().get(id=account).to_mongo().to_dict() except: raise DoesNotExist("Account does not exists")
except Exception, ex: raise ParseError("Invalid json data: %s" % attendance_data) try: group = Group.objects.get(id=group_id) except DoesNotExist: raise ValidationError("Group Id is invalid: %s" % group_id) attendance_objs = [] for student_id, is_present in attendance_data.items(): if is_present not in VALID_ATTENDANCE_TYPES: raise ValidationError("Invalid attendance type : %s " %(attendance_data)) try: student = User.objects.get(id=student_id) except DoesNotExist, ex: raise DoesNotExist("Student id does not exist: %s" % student_id) attendance_objs.append(Attendance(student=student, present=int(is_present))) for parent_id in student.parent_ids: QueueRequests.enqueue(NOTIFICATION_QUEUE, {'id': parent_id, 'name': student.name}) try: Attendance.objects.insert(attendance_objs) except Exception, ex: logger.error("Error occurred while saving the attendance doc: %s, data: %s, group_id:%s" % (str(ex), attendance_data, group_id)) raise APIException("Error while saving data") return JSONResponse({"stat": "ok"}) class GroupView(APIView):
def delete(self, document_id, delete_args): record = self.main_model.objects(id=document_id).first() if not record: raise DoesNotExist('Kayıt bulunamadı veya erişim yetkiniz yok') return record.delete(signal_kwargs=delete_args)