def authorization_add(request, radius_username, account): """ Add a new authorization to the specified user. Required user level: Manager Returns the authorization on success. radius_username -- RADIUS username to search for. account -- Bank account number. Example return value: { "account": "NL13TEST0123456789", "id": 1, "end_date": null, "start_date": "2014-09-21T14:16:06+00:00", "user": "******" } Raises error -32602 (Invalid params) if the radius_username does not exist. """ try: user = User.objects.get(authenticationdata__backend=RADIUS_BACKEND_NAME, authenticationdata__username=radius_username) except User.DoesNotExist: raise InvalidParametersError('User with provided radius_username does not exits') authorization = Authorization(user=user, organization=request.organization, account=account) authorization.save() return format_authorization(authorization)
def authorization_add(request, radius_username, account): """ Add a new authorization to the specified user. Required user level: Manager Returns the authorization on success. radius_username -- RADIUS username to search for. account -- Bank account number. Example return value: { "account": "NL13TEST0123456789", "id": 1, "end_date": null, "start_date": "2014-09-21T14:16:06+00:00", "user": "******" } Raises error -32602 (Invalid params) if the radius_username does not exist. """ try: user = User.objects.get( authenticationdata__backend=RADIUS_BACKEND_NAME, authenticationdata__username=radius_username) except User.DoesNotExist: raise InvalidParametersError( 'User with provided radius_username does not exits') authorization = Authorization(user=user, organization=request.organization, account=account) authorization.save() return format_authorization(authorization)
def test_order_unsynchronized(self): starts_at = timezone.make_aware(datetime.datetime(2014, 9, 21, 14, 16, 6), timezone.utc) ends_at = starts_at + datetime.timedelta(hours=1) placed_at = starts_at + datetime.timedelta(minutes=30) placed_at_string = '2014-09-21T14:46:06+00:00' pricegroup = PriceGroup(organization=self.data['organization1'], name='Price group') pricegroup.save() event = Event(organizer=self.data['organization1'], name='Test event', starts_at=starts_at, ends_at=ends_at, pricegroup=pricegroup, kegs=1) event.save() productgroup = ProductGroup(organization=self.data['organization1'], name='Product group') productgroup.save() product1 = PermanentProduct(productgroup=productgroup, organization=self.data['organization1'], position=0) product1.save() product2 = TemporaryProduct(event=event, price=2.33) product2.save() authorization = Authorization(user=self.data['user1'], organization=self.data['organization1'], start_date=starts_at) authorization.save() order = Order(event=event, authorization=authorization, placed_at=placed_at, added_by=self.data['user1']) order.save() Purchase(order=order, product=product1, amount=1, price=0.50).save() Purchase(order=order, product=product2, amount=2, price=4.66).save() order.save() order_json = { 'id': order.id, 'rfid': None, 'event': { 'id': event.id, 'name': 'Test event', }, 'authorization': format_authorization(authorization), 'synchronized': False, 'placed_at': placed_at_string, 'purchases': [ { 'product': { 'id': product1.id, 'name': '', }, 'amount': 1, 'price': '0.50', }, { 'product': { 'id': product2.id, 'name': '', }, 'amount': 2, 'price': '4.66', } ], } self.convertAndAssertJSONEqual(format_order(order), order_json)
def test_order_unsynchronized(self): starts_at = timezone.make_aware( datetime.datetime(2014, 9, 21, 14, 16, 6), timezone.utc) ends_at = starts_at + datetime.timedelta(hours=1) placed_at = starts_at + datetime.timedelta(minutes=30) placed_at_string = '2014-09-21T14:46:06+00:00' pricegroup = PriceGroup(organization=self.data['organization1'], name='Price group') pricegroup.save() event = Event(organizer=self.data['organization1'], name='Test event', starts_at=starts_at, ends_at=ends_at, pricegroup=pricegroup, kegs=1) event.save() productgroup = ProductGroup(organization=self.data['organization1'], name='Product group') productgroup.save() product1 = PermanentProduct(productgroup=productgroup, organization=self.data['organization1'], position=0) product1.save() product2 = TemporaryProduct(event=event, price=2.33) product2.save() authorization = Authorization(user=self.data['user1'], organization=self.data['organization1'], start_date=starts_at) authorization.save() order = Order(event=event, authorization=authorization, placed_at=placed_at, added_by=self.data['user1']) order.save() Purchase(order=order, product=product1, amount=1, price=0.50).save() Purchase(order=order, product=product2, amount=2, price=4.66).save() order.save() order_json = { 'id': order.id, 'rfid': None, 'event': { 'id': event.id, 'name': 'Test event', }, 'authorization': format_authorization(authorization), 'synchronized': False, 'placed_at': placed_at_string, 'purchases': [{ 'product': { 'id': product1.id, 'name': '', }, 'amount': 1, 'price': '0.50', }, { 'product': { 'id': product2.id, 'name': '', }, 'amount': 2, 'price': '4.66', }], } self.convertAndAssertJSONEqual(format_order(order), order_json)