-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
037c2d0
commit d8053c8
Showing
7 changed files
with
56 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,5 @@ dump.rdb | |
# static folder | ||
static_root | ||
static | ||
|
||
.DS_Store |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from faker import Faker | ||
from authentication.models import Customer | ||
import factory | ||
|
||
fake = Faker() | ||
|
||
class CustomerFactory(factory.django.DjangoModelFactory): | ||
username = fake.profile()['username'] | ||
password = fake.password() | ||
email = fake.email() | ||
bio = fake.text() | ||
birth_date = fake.date_object() | ||
address = fake.address() | ||
|
||
class Meta: | ||
model = Customer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.2 on 2023-12-27 09:47 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("authentication", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="customer", | ||
name="address", | ||
field=models.CharField(blank=True, max_length=200, verbose_name="Address"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
from django.contrib.auth.models import User | ||
from authentication.factories.customer_factory import CustomerFactory | ||
from django.test import TestCase | ||
from rest_framework_simplejwt.tokens import RefreshToken | ||
from authentication.models import Customer | ||
from faker import Faker | ||
|
||
fake = Faker() | ||
|
||
class TestCalls(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = User.objects.create_user( | ||
username="nguyen.hung", | ||
password="1234ABbcd!@", | ||
email="[email protected]", | ||
cls.password = fake.password() | ||
cls.username = fake.profile()["username"] | ||
cls.email = fake.email() | ||
cls.customer = User.objects.create_user( | ||
username=cls.username, | ||
password=cls.password, | ||
email=cls.email, | ||
) | ||
|
||
def test_call_register(self): | ||
user_name = fake.profile()["username"] | ||
data = { | ||
"username": "bao.binh", | ||
"password": "1234ABbcd!@", | ||
"email": "[email protected]", | ||
"username": user_name, | ||
"password": fake.password(), | ||
"email": fake.email(), | ||
} | ||
|
||
response = self.client.post( | ||
|
@@ -26,21 +34,20 @@ def test_call_register(self): | |
self.assertEqual(response.status_code, 201) | ||
self.assertIn("username", response.json()) | ||
self.assertIn("email", response.json()) | ||
self.assertEqual(response.json().get("username"), "bao.binh") | ||
self.assertEqual(response.json().get("username"), user_name) | ||
|
||
def test_call_login(self): | ||
data = {"username": "nguyen.hung", "password": "1234ABbcd!@"} | ||
data = {"username": TestCalls.username, "password": TestCalls.password} | ||
|
||
response = self.client.post( | ||
"/api/v1/auth/login/", data, content_type="application/json" | ||
) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("access", response.json()) | ||
self.assertIn("refresh", response.json()) | ||
|
||
def test_call_refresh_token(self): | ||
refresh = RefreshToken.for_user(TestCalls.user) | ||
refresh = RefreshToken.for_user(TestCalls.customer) | ||
data = { | ||
"refresh": str(refresh), | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
-r base.txt | ||
coverage==7.3.2 | ||
factory_boy==3.3.0 | ||
Faker==21.0.0 |