Tradir.io Onboarding Journey

This morning, I have decided that I will procrastinate learning PyTest because it’s projected to take a very long time — the pdf manual of PyTest alone is 400 pages and I also have to read PyTest-Django package manual and DRF’s own testing modules manuals. My boss told me I shouldn’t spend too much time learning those. And thus my decision to go back to using TestCase from pure Django. Once I will have created some basic unit tests for ‘user’, ‘contacts’, and ‘deal’ apps in the project, I will then move on to start delving into PyTest and other auxiliary packages.
Now my unit tests look less cryptic.
import pytest
import json
from django.urls import reverse
from django.contrib.auth.models import User
from django.test import Client, TestCase
from mixer.backend.django import mixer
from user.models import SocialLoginPlatform, Team
from contacts.models import Country
pytestmark = pytest.mark.django_db
client = Client()
HEADER = {'content-type': 'application/json' }
CONTENT_TYPE = 'application/json'
class UserTestCase(TestCase):
def setUp(self):
for i in range(50):
mixer.blend(Country)
SocialLoginPlatform.objects.create(name="none")
SocialLoginPlatform.objects.create(name="google")
User.objects.create(first_name="Nick", last_name="An",
username="nickanism")
Team.objects.create(company_name="Random Company")
def tearDown(self):
User.objects.all().delete()
SocialLoginPlatform.objects.all().delete()
Country.objects.all().delete()
def testUserCreated(self):
user = User.objects.get(last_name='An')
assert user.first_name == "Nick"
def testProfileIsCreated(self):
user = User.objects.get(last_name='An')
assert user.profile != None
def testUserTeamCreated(self):
team = Team.objects.get(company_name="Random Company")
assert team != None
def testCountryListView(self):
response = self.client.get("/api/country/list/")
response_content = json.loads(response.content)
assert response.status_code == 200
assert response_content["country_list"] != None
def testAdminSignUpLoginView(self):
data = {
"company_name": "Random_Company_02",
"country_id": 14,
"email": "lnrdwd@goreadit.site",
"language": "en",
"name": "Rand Minit",
"password": "12345678"
}
data = json.dumps(data)
response = self.client.post('/api/user/signup/admin/',
data=data,
content_type=CONTENT_TYPE)
assert response.status_code == 200
assert json.loads(response.content)['Authorization'] != None
data2 = {
"email": "lnrdwd@goreadit.site",
"password": "12345678"
}
data = json.dumps(data)
response = self.client.post('/api/user/login/',
data=data2,
content_type=CONTENT_TYPE)
assert response.status_code == 200
def testUserProfileChange(self):
user = User.objects.get(last_name="An")
assert user != None
profile = user.profile
assert profile != None
assert profile.name == None
profile.name = "bodega"
profile.save()
assert profile.name == "bodega"
team = Team.objects.get(company_name="Random Company")
profile.team = team
profile.save()
assert profile.team != None
assert profile.timezone == "Asia/Seoul"
assert profile.language == "en"
assert profile.auth == 3
The First step to a successful onboarding is figuring out the models. Of course, I needed to ask the backend engineer what models the project is currently using and what models it doesn’t. It’s quite import to rule out the deprecated tables because they are essential a waste of time.