def create_client(data): validated_data = data.copy() client = Client.objects.create( client_name=validated_data.get('client_name')) validated_data.pop('client_name') validated_data['client_id'] = client.id create_user(data=validated_data, role=2) return client
def test_creating_user_with_proper_data_is_working(self): self.assertEqual(0, BaseUser.objects.count()) user_data = { 'email': fake.email(), 'password': fake.password() } create_user(**user_data) self.assertEqual(1, BaseUser.objects.count()) self.assertTrue( BaseUser.objects.filter(email=user_data['email']).exists() )
def create_client(data): validated_data = data.copy() user = get_user_by(email=data.get('email'), raise_exception=False) if user: raise DuplicateEntry(entry=user.email, key='email') client_name = validated_data.get('client_name') client = get_client_by(client_name=client_name, raise_exception=False) if client: raise DuplicateEntry(entry=client_name, key='client_name') client = Client.objects.create(client_name=client_name, address=validated_data.get('address')) validated_data.pop('client_name') validated_data.pop('address') validated_data['client_id'] = client.id create_user(data=validated_data, role=2) return client
def register_user(request): response = UsersService.create_user(request.data) if response["status"]: return Response(response, status=status.HTTP_201_CREATED) else: return Response(response, status=status.HTTP_200_OK)
def setUp(self): self.user = create_user("*****@*****.**", "test123", "user") start = datetime.date.today() + datetime.timedelta(days=10) end = datetime.date.today() + datetime.timedelta(days=12) self.user.save() self.trip = Trip(user=self.user, destination="Test", comment="test", start_date=start, end_date=end) self.trip.save()
def test_create_user(): correo = "*****@*****.**" is_created, user = create_user( correo=correo, password="******", nombre="TestMan", apellido="Sanchez", rut="191366360", numero_serie_carnet="123456789", ) assert is_created assert user == User.objects.get(correo=correo)
def setUp(self): self.user = create_user("*****@*****.**", "test123", "user") self.user.save()
def user(event_loop): from users import services user = event_loop.run_until_complete(services.create_user('test', '1234')) user.raw_password = '******' return user
def create(self, validated_data): return services.create_user( **validated_data )