def post(self): request.get_json(force=True) args = customers_parser.parse_args() logger.debug(args) customer = Customer(**args) customer.save() return None
def test0200_create_rental(self): customer = Customer(name='Raven', phone='010-9508-1111') customer.save() book = Book(title="ABC", author='Julia', publisher='WinWin') book.save() rental = Rental(book=book, customer=customer) rental.rental_start = datetime.datetime(2020, 8, 15, 00, 00, 00) rental.save() result = Rental.objects().fields(id=0).first() print(result.to_json(follow_reference=True))
def test0110_find_customer(self): customer_1 = Customer(name='Raven', phone='010-9508-1111') customer_1.save() customer_2 = Customer(name='Julia', phone='010-9508-1112') customer_2.save() # results = Customer.objects({}).exclude('id').as_pymongo() results = Customer.objects().fields(id=0).to_json() # results = Customer.objects().fields(id=0).to_mongo().to_dict() print(results)
def test0120_patch_model_customer(self): customer = Customer(name='Raven', phone='010-9508-1111') customer.save() Customer.objects().update(name="Julia") customer.reload() # fresh_pers = Customer.objects().exclude('id').first() self.assertEqual(customer.name, 'Julia') self.assertEqual(customer.phone, '010-9508-1111')
def post(self): request.get_json(force=True) args = customers_parser.parse_args() customer = Customer(**args) db_session.add(customer) db_session.commit() return None
def get(self): args = customers_parser.parse_args() queries = dict() for arg in args: queries[f'{arg}__icontains'] = args[arg] values = Customer.objects(**queries).to_json() return json.loads(values)
def get(self): args = rental_parser.parse_args() queries = dict() logger.debug(args) # WHERE if args.setdefault('book_id', None): book = Book.objects(book_id=args['book_id']).first() queries[f'book'] = book if args.setdefault('customer_id', None): customer = Customer.objects(customer_id=args['customer_id']).first() queries[f'customer'] = customer # DATE TIME if args.setdefault('rental_start', None): dt = datetime.datetime.fromisoformat(args['rental_start']) queries[f'rental_start__lte'] = dt if args.setdefault('rental_end', None): if args['rental_end']: dt = datetime.datetime.fromisoformat(args['rental_end']) queries[f'rental_end__gte'] = dt else: queries[f'rental_end__gte'] = None # OFFSET/LIMIT offset = args.setdefault('offset', None) limit = args.setdefault('limit', None) values = Rental.objects(**queries)[offset:limit].to_json() return json.loads(values)
def post(self): request.get_json(force=True) logger.debug(request) args = rental_parser.parse_args() customer = Customer.objects(customer_id=args['customer_id']).first() book = Book.objects(book_id=args['book_id']).first() rental = Rental(customer=customer, book=book) rental.save() return None
def test106_customers_filter(self): name = 'Raven' phone = '010-9508-0875' c = Customer(name, phone) self.session.add(c) self.session.commit() r = self.session.query(Customer) \ .filter_by(name=name) \ .first() self.assertEqual(name, r.name) self.assertEqual(phone, r.phone)
def test0130_delete_model_customer(self): customer = Customer(name='Raven', phone='010-9508-1111') customer.save() result = Customer.objects(customer_id=1).delete() print(result) result = Customer.objects(customer_id=1) print(result)
def test0100_check_model_customer(self): customer = Customer(name='Raven', phone='010-9508-1111') customer.save() # fresh_pers = Customer.objects().exclude('id').first() self.assertEqual(customer.name, 'Raven')
def test105_customers_new(self): name = 'Raven' phone = '010-9508-0875' c = Customer(name, phone) self.assertEqual(name, c.name) self.assertEqual(phone, c.phone)
def add_customers(self): for customer in USERS: self.session.add(Customer(*customer)) self.session.commit()
def delete(self, customer_id): Customer.objects(customer_id=customer_id).delete() return None
def patch(self, customer_id): args = customers_parser.parse_args() Customer.objects(customer_id=customer_id).update(**args) return None
def get_customer(self, customer_id): customer = Customer.objects(customer_id=customer_id).fields(id=0).first() if not customer: raise ValueError('The index of the item is not existed.') return customer