def test_customer_disabled(self): self.customer.is_active = False self.customer.save(update_fields=["is_active"]) # self.customer.refresh_from_db() customer_service = CustomerService.get_user_credentials_by_ip( ip_addr="10.11.12.2") self.assertIsNone(customer_service)
def test_customer_with_onu_device(self): # customer for tests customer_onu = Customer.objects.create_user(telephone="+79782345679", username="******", password="******") customer_onu.device = self.device_onu customer_onu.add_balance(self.admin, 10000, "test") customer_onu.save() customer_onu.refresh_from_db() customer_onu.pick_service(self.service, customer_onu) self.customer_onu = customer_onu self.lease = CustomerIpLeaseModel.objects.create( ip_address="10.11.12.3", mac_address="1:2:3:4:5:6", pool=self.ippool, customer=customer_onu, is_dynamic=True, ) self.assertIsNotNone(self.lease) # lease must be contain ip_address=10.11.12.3' customer_service = CustomerService.get_user_credentials_by_ip( ip_addr="10.11.12.3", ) self.assertIsNotNone(customer_service) self.assertEqual(customer_service.service.speed_in, 10.0) self.assertEqual(customer_service.service.speed_out, 10.0) self.assertEqual(customer_service.service.speed_burst, 1) self.assertEqual(customer_service.service.cost, 10.0) self.assertEqual(customer_service.service.calc_type, SERVICE_CHOICE_DEFAULT)
def test_get_user_credentials_by_ip(self): customer_service = CustomerService.get_user_credentials_by_ip( ip_addr="10.11.12.2") self.assertIsNotNone(customer_service) self.assertEqual(customer_service.service.speed_in, 10.0) self.assertEqual(customer_service.service.speed_out, 10.0) self.assertEqual(customer_service.service.speed_burst, 1) self.assertEqual(customer_service.service.cost, 10.0) self.assertEqual(customer_service.service.calc_type, SERVICE_CHOICE_DEFAULT)
def get_service(self, request): data = self._check_data(request.data) customer_ip = data.get("customer_ip") # password = data.get('password') customer_service = CustomerService.get_user_credentials_by_ip( ip_addr=customer_ip) if customer_service is None: return Response({"Reply-Message": "Customer service not found"}, status=status.HTTP_404_NOT_FOUND) sess_time = customer_service.calc_session_time() return Response({ "ip": customer_ip, "session_time": int(sess_time.total_seconds()), "speed_in": customer_service.service.speed_in, "speed_out": customer_service.service.speed_out, })
def auth(self, request, vendor_name=None): vendor_manager = VendorManager(vendor_name=vendor_name) self.vendor_manager = vendor_manager agent_remote_id, agent_circuit_id = vendor_manager.get_opt82( data=request.data) if not all([agent_remote_id, agent_circuit_id]): return _bad_ret("Bad opt82") dev_mac, dev_port = vendor_manager.build_dev_mac_by_opt82( agent_remote_id=agent_remote_id, agent_circuit_id=agent_circuit_id) if dev_mac is None: return _bad_ret("Failed to parse option82") customer_mac = vendor_manager.get_customer_mac(request.data) if customer_mac is None: return _bad_ret("Customer mac is required") # radius_username = vendor_manager.get_radius_username(request.data) # radius_unique_id = vendor_manager.get_radius_unique_id(request.data) customer = CustomerIpLeaseModel.find_customer_by_device_credentials( device_mac=dev_mac, device_port=dev_port) if customer is None: # If customer not found then assign guest session return self.assign_guest(customer_mac=customer_mac, data=request.data) if customer.current_service_id is None: # if customer has not service then assign guest # session with attached customer. r = self.assign_guest( customer_mac=customer_mac, data=request.data, customer_id=customer.pk, ) _update_lease_send_ws_signal(customer.pk) return r customer_service = CustomerService.find_customer_service_by_device_credentials( customer_id=customer.pk, current_service_id=int(customer.current_service_id)) if customer_service is None: # if customer has not service then assign guest # session with attached customer. r = self.assign_guest( customer_mac=customer_mac, data=request.data, customer_id=customer.pk, ) _update_lease_send_ws_signal(customer.pk) return r vid = vendor_manager.get_vlan_id(request.data) try: subscriber_lease = CustomerRadiusSession.objects.fetch_subscriber_lease( customer_mac=customer_mac, customer_id=customer.pk, customer_group=customer.group_id, is_dynamic=True, vid=vid, pool_kind=NetworkIpPoolKind.NETWORK_KIND_INTERNET, ) if subscriber_lease is None: r = self.assign_guest( customer_mac=customer_mac, data=request.data, customer_id=customer.pk, ) _update_lease_send_ws_signal(customer.pk) return r response = vendor_manager.get_auth_session_response( subscriber_lease=subscriber_lease, customer_service=customer_service, customer=customer, request_data=request.data, ) _update_lease_send_ws_signal(customer.pk) return Response(response) except LogicError as err: return _bad_ret(str(err))
def test_customer_does_not_have_service(self): self.customer.stop_service(self.customer) customer_service = CustomerService.get_user_credentials_by_ip( ip_addr="10.11.12.2") self.assertIsNone(customer_service)
def test_if_ip_is_bad(self): customer_service = CustomerService.get_user_credentials_by_ip( ip_addr="10.11.12.12.13") self.assertIsNone(customer_service)
def test_if_ip_is_none(self): customer_service = CustomerService.get_user_credentials_by_ip( ip_addr=None) self.assertIsNone(customer_service)
def test_not_exists_lease(self): customer_service = CustomerService.get_user_credentials_by_ip( ip_addr="10.11.12.12") self.assertIsNone(customer_service)