def _set_up_seller(): comission_plan = ComissionPlan(lower_percentage=2.5, upper_percentage=10.5, min_value=5000.0) comission_plan.save() seller_address = Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") seller_address.save() seller = Seller(cpf="12345678910", name="José", last_name="Vendedor", age=30, email="*****@*****.**", phone="48012345678", address=seller_address, comission_plan=comission_plan) seller.save() return seller
def setUp(self): self.comission_plan = ComissionPlan(lower_percentage=2.5, upper_percentage=10.5, min_value=5000.0) self.comission_plan.save() self.seller_address = Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller_address.save() self.seller = Seller(cpf="12345678910", name="José", last_name="Vendedor", age=30, email="*****@*****.**", phone="48012345678", address=self.seller_address, comission_plan=self.comission_plan) self.seller.save() Vendas(month=1, seller=self.seller, amount=1000.0).save() Vendas(month=2, seller=self.seller, amount=500.0).save() Vendas(month=3, seller=self.seller, amount=1100.0).save()
def setUp(self): self.comission_plan = ComissionPlan(lower_percentage=5, upper_percentage=10, min_value=2000.0) self.comission_plan.save() self.seller_address = Address(pk=None, street="Rua tal", number="10", city="sao paulo", state="SP", country="Brasil") self.seller_address.save() self.seller = Seller(cpf="12345612396", name="Rob", last_name="Vendedor", age=29, email="*****@*****.**", phone="11970750623", address=self.seller_address, comission_plan=self.comission_plan) self.seller.save()
class CheckComissionAPITest(TestCase): def setUp(self): self.comission_plan = ComissionPlan(lower_percentage=2.5, upper_percentage=10.5, min_value=5000.0) self.comission_plan.save() self.seller_address = Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller_address.save() self.seller = Seller(cpf="12345678910", name="José", last_name="Vendedor", age=30, email="*****@*****.**", phone="48012345678", address=self.seller_address, comission_plan=self.comission_plan) self.seller.save() Vendas(month=1, seller=self.seller, amount=1000.0).save() Vendas(month=2, seller=self.seller, amount=500.0).save() Vendas(month=3, seller=self.seller, amount=1100.0).save() def test_check_comission_without_notification(self): current_sales = { 'seller': self.seller.id, 'amount': 970.0, } response = self.client.post('/check_commision/', current_sales) self.assertEqual(response.status_code, status.HTTP_200_OK) # Parses response body and check data. body = response.json() self.assertFalse(body['should_notify']) self.assertEqual(len(mail.outbox), 0) def test_check_comission_with_notification(self): current_sales = { 'seller': self.seller.id, 'amount': 966.0, } response = self.client.post('/check_commision/', current_sales) self.assertEqual(response.status_code, status.HTTP_200_OK) # Parses response body and check data. body = response.json() self.assertTrue(body['should_notify']) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, ['*****@*****.**']) def test_check_comission_without_notification_more_months(self): Vendas(month=4, seller=self.seller, amount=700.0).save() Vendas(month=5, seller=self.seller, amount=650.0).save() Vendas(month=6, seller=self.seller, amount=800.0).save() current_sales = { 'seller': self.seller.id, 'amount': 841.0, } response = self.client.post('/check_commision/', current_sales) self.assertEqual(response.status_code, status.HTTP_200_OK) # Parses response body and check data. body = response.json() self.assertFalse(body['should_notify']) self.assertEqual(len(mail.outbox), 0) def test_check_comission_with_notification_more_months(self): Vendas(month=4, seller=self.seller, amount=700.0).save() Vendas(month=5, seller=self.seller, amount=650.0).save() Vendas(month=6, seller=self.seller, amount=800.0).save() current_sales = { 'seller': self.seller.id, 'amount': 839.0, } response = self.client.post('/check_commision/', current_sales) self.assertEqual(response.status_code, status.HTTP_200_OK) # Parses response body and check data. body = response.json() self.assertTrue(body['should_notify']) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, ['*****@*****.**'])
def setUp(self): self.comission_plan = ComissionPlan(lower_percentage=2.5, upper_percentage=10.5, min_value=5000.0) self.comission_plan.save() self.seller_address = models.Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller_address.save() self.seller = models.Seller(cpf="12345678910", name="José", last_name="Vendedor", age=30, email="*****@*****.**", phone="48012345678", address=self.seller_address, comission_plan=self.comission_plan) self.seller.save() self.seller2_address = models.Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller2_address.save() self.seller2 = models.Seller(cpf="12345612396", name="Joao", last_name="Vendedor", age=27, email="*****@*****.**", phone="48012345678", address=self.seller2_address, comission_plan=self.comission_plan) self.seller2.save() self.seller3_address = models.Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller3_address.save() self.seller3 = models.Seller(cpf="74185296346", name="Luis", last_name="Vendedor", age=27, email="*****@*****.**", phone="48012345678", address=self.seller3_address, comission_plan=self.comission_plan) self.seller3.save() Sales(month=1, seller=self.seller, amount=1000.0, comission=25).save() Sales(month=2, seller=self.seller, amount=500.0, comission=12).save() Sales(month=3, seller=self.seller, amount=1100.0, comission=27).save() Sales(month=1, seller=self.seller2, amount=500.0, comission=12).save() Sales(month=2, seller=self.seller2, amount=1100.0, comission=27).save() Sales(month=3, seller=self.seller2, amount=1000.0, comission=25).save() Sales(month=1, seller=self.seller3, amount=1100.0, comission=27).save() Sales(month=2, seller=self.seller3, amount=1000.0, comission=25).save() Sales(month=3, seller=self.seller3, amount=500.0, comission=12).save()
class SellerAPITest(APITestCase): def setUp(self): self.comission_plan = ComissionPlan(lower_percentage=2.5, upper_percentage=10.5, min_value=5000.0) self.comission_plan.save() self.seller_address = models.Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller_address.save() self.seller = models.Seller(cpf="12345678910", name="José", last_name="Vendedor", age=30, email="*****@*****.**", phone="48012345678", address=self.seller_address, comission_plan=self.comission_plan) self.seller.save() self.seller2_address = models.Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller2_address.save() self.seller2 = models.Seller(cpf="12345612396", name="Joao", last_name="Vendedor", age=27, email="*****@*****.**", phone="48012345678", address=self.seller2_address, comission_plan=self.comission_plan) self.seller2.save() self.seller3_address = models.Address(pk=None, street="Rua abcd", number="123", city="Brasília", state="DF", country="BR") self.seller3_address.save() self.seller3 = models.Seller(cpf="74185296346", name="Luis", last_name="Vendedor", age=27, email="*****@*****.**", phone="48012345678", address=self.seller3_address, comission_plan=self.comission_plan) self.seller3.save() Sales(month=1, seller=self.seller, amount=1000.0, comission=25).save() Sales(month=2, seller=self.seller, amount=500.0, comission=12).save() Sales(month=3, seller=self.seller, amount=1100.0, comission=27).save() Sales(month=1, seller=self.seller2, amount=500.0, comission=12).save() Sales(month=2, seller=self.seller2, amount=1100.0, comission=27).save() Sales(month=3, seller=self.seller2, amount=1000.0, comission=25).save() Sales(month=1, seller=self.seller3, amount=1100.0, comission=27).save() Sales(month=2, seller=self.seller3, amount=1000.0, comission=25).save() Sales(month=3, seller=self.seller3, amount=500.0, comission=12).save() def test_create_seller(self): comission_plan = { 'lower_percentage': 2.5, 'min_value': 15000.00, 'upper_percentage': 15.0 } response = self.client.post('/comissions/', comission_plan, format='json') seller = { 'cpf': '12345679855', 'name': 'Joao', 'last_name': 'da Silva', 'age': 27, 'email': '*****@*****.**', 'phone': '81989429086', 'address': { 'street': 'Rua Doutor Newton Braga', 'number': '38', 'complement': 'Casa 02', 'city': 'Olinda', 'state': 'Pernambuco', 'country': 'Brasil' }, 'comission_plan': 1 } response = self.client.post('/sellers/', seller, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) # Parses response body and check data. body = response.json() self.assertTrue(type(body['id']) == int) def test_retrieve_sellers_month(self): response = self.client.get('/best_sellers/0/2') body = response.json() print(body)
class SalesAPITest(TestCase): def setUp(self): self.comission_plan = ComissionPlan(lower_percentage=5, upper_percentage=10, min_value=2000.0) self.comission_plan.save() self.seller_address = Address(pk=None, street="Rua tal", number="10", city="sao paulo", state="SP", country="Brasil") self.seller_address.save() self.seller = Seller(cpf="12345612396", name="Rob", last_name="Vendedor", age=29, email="*****@*****.**", phone="11970750623", address=self.seller_address, comission_plan=self.comission_plan) self.seller.save() def test_submit_month_comission_low(self): sale = { 'amount': 1000, 'seller': self.seller.id, 'comission': self.seller.comission_plan.id, 'month': 1, 'year': 2018 } response = self.client.post('/month_comission/', sale) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # Parses response body and check data. body = response.json() self.assertEqual(body['id'], 1) self.assertEqual(body['comission'], 50) def test_submit_month_comission_up(self): sale = { 'amount': 2000, 'seller': self.seller.id, 'comission': self.seller.comission_plan.id, 'month': 1, 'year': 2018 } response = self.client.post('/month_comission/', sale) self.assertEqual(response.status_code, status.HTTP_201_CREATED) # Parses response body and check data. body = response.json() self.assertEqual(body['id'], 1) self.assertEqual(body['comission'], 200) def test_submit_month_comission_invalid_year(self): sale = { 'amount': 2000, 'seller': self.seller.id, 'comission': self.seller.comission_plan.id, 'month': 1, 'year': 2020 } response = self.client.post('/month_comission/', sale) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)