Lenovo Yoga 7i 2in1 14IML9 0WID Intel Core Ultra 5Lenovo Yoga 7 2-in-1 14IML9 83DJ000WID ULTRA 5-125H/16GB/512GB/TS 14.0 OLED/WIN11+OHS2021/TIDAL TEAL - Yoga 7 2-in-1 14IML9 - Part Number : 83DJ000WID - PERFORMANCE: Processor Intel® Core™ Ultra 5 125H, 14C (4P + 8E + 2LPE) / 18T, Max Turbo up to 4.5GHz, 18MB - Graphics Integrated Intel® Arc™ Graphics - Chipset Intel® SoC Platform - Memory 16GB Soldered LPDDR5x-7467 Free Klik Disini ! |
Pada tutorial service OTP bagian ke-dua kita telah belajar tentang sequence diagram, dari sequence diagram kita telah mendapatkan garis besar service OTP yang akan kita buat.
Dibagian kedua ini kita akan mempelajari beberapa hal :
class Otpservice(CreateUpdate):
phone_number = models.CharField(max_length=35)
otp_number = models.IntegerField()
expired_unixtime = models.IntegerField()
validate = models.BooleanField(default=False)
Dari class model Otpservice(), dapat kita pelajari bahwa kita akan membuat table dengan field phone_number, otp_number, expired_unixtime, validate
class CreateOTPSerializer(serializers.Serializer):
phone_number = serializers.CharField(max_length=50)
class ValidateOTPSerializer(serializers.Serializer):
phone_number = serializers.CharField(max_length=50)
otp_number = serializers.CharField(max_length=50)
def create_expired_unixtime(expired=None):
if expired == None:
expired = 5
curent_time = datetime.now()
curent_unix_time = curent_time.timestamp()
expired_time = curent_unix_time + (expired * 60)
return expired_timedef generate_random_otp():
fixed_digits = 6
return random.randrange(111111, 999999, fixed_digits)
Code sample:
def test_create_otp_failed(self):
status, message = create_otp({})
self.assertEqual(status, False)
self.assertRaisesMessage(Exception, message)
Video makemigrations dan unit test:
github: https://github.com/halovina/otpservice/tree/model-serializers
Baca artikel lainya: