Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desafio QA - Israel #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README_Israel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Desafio Concrete

Olá! Esse fork possui as especificações do aplicativo Whatsapp (arquivos .spec) e também arquivos referentes ao exercício 09 do CodeKata.

## Whatsapp specs
As especificações do Whatsapp foram escritas seguindo o framework Gauge.

## Run the tests
Não foi feito um método ``main`` para o algoritmo mas foram escritos alguns testes para validar seu comportamento.

Para executar os testes:
``
python3 -m unittest path/to/tests/*
``
35 changes: 35 additions & 0 deletions checkout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from product_item import Item


class InvalidProductException(Exception):
def __init__(self):
self.message = "This product is not part of catalog"


class Checkout(object):
def __init__(self, pricing_rules):
self.pricing_rules = pricing_rules # dict
self.product_list = list()

def scan(self, product_code):
if product_code.upper() in self.pricing_rules:
self.product_list.append(product_code)
else:
raise InvalidProductException

def calculate_item_total_price(self, product_code, product_list):
item_price = Item(*self.pricing_rules[product_code.upper()])
for product in product_list:
if product == product_code:
item_price.increment_item_total()
item_price.calculate_item_price()
return item_price.calculate_item_price()

def calculate_checkout(self):
total_price = 0
product_set = set(self.product_list)
for product in product_set:
total_price += self.calculate_item_total_price(product, self.product_list)
return total_price


24 changes: 24 additions & 0 deletions product_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Item(object):
def __init__(self, unit_price, promo_size=None, promo_price=None):
self.item_total = 0
self.unit_price = unit_price
self.promo_price = promo_price
self.promo_size = promo_size

def calculate_item_price(self):
if self.has_special_price():
price = (self.item_total//self.promo_size)*self.promo_price + \
(self.item_total%self.promo_size)*self.unit_price
else:
price = self.item_total*self.unit_price
return price

def increment_item_total(self):
self.item_total += 1

def get_item_total(self):
return self.item_total

def has_special_price(self):
return bool(self.promo_price and self.promo_size)

47 changes: 47 additions & 0 deletions tests/tests_checkout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import unittest

from checkout import Checkout, InvalidProductException


class TestCheckout(unittest.TestCase):

def test_calculate_checkout(self):
rules = {
"A": (50, 3, 130),
"B": (30, 2, 45),
"C": (20, None),
"D": (15, None)
}
cashier = Checkout(rules)
try:
cashier.scan('A')
cashier.scan('D')
cashier.scan('A')
cashier.scan('a')
cashier.scan('B')
cashier.scan('b')
cashier.scan('d')
cashier.scan('A')
cashier.scan('b')
cashier.scan('C')
cashier.scan('A')
cashier.scan('C')
# expected total = 375
self.assertEqual(cashier.calculate_checkout(), 375)
except InvalidProductException as e:
print(e.message)
self.fail("No exception should have been raised here")

def test_add_invalid_product(self):
rules = {
"A": (50, 3, 130),
"D": (15, None)
}
cashier = Checkout(rules)
with self.assertRaises(InvalidProductException):
cashier.scan('A')
cashier.scan('B')


if __name__ == "__main__":
unittest.main()
31 changes: 31 additions & 0 deletions tests/tests_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest

from product_item import Item


class TestItem(unittest.TestCase):

def test_item_total(self):
item = Item(10, 2, 15)
self.assertEqual(item.item_total, 0)
for i in range(10):
item.increment_item_total()
self.assertEqual(item.item_total, 10)

def test_calculate_special_price(self):
item = Item(20, 2, 30)
self.assertEqual(item.calculate_item_price(), 0)
for i in range(5):
item.increment_item_total()
self.assertEqual(item.calculate_item_price(), 80)

def test_calculate_regular_price(self):
item = Item(20)
self.assertEqual(item.calculate_item_price(), 0)
for i in range(5):
item.increment_item_total()
self.assertEqual(item.calculate_item_price(), 100)


if __name__ == "__main__":
unittest.main()
26 changes: 26 additions & 0 deletions whatsapp.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# New conversation

As a User I would like to initiate a new conversation to communicate with my friends

## Starting a new conversation

If the conversation doesn't exists a new must be created.
There should be a button to initiate a new conversation.
User must be able to filter contacts by name (return must be a list)

* User is logged in
* Click on "New Conversation"
* Click on "Search"
* Write "No conversation contact"
* Click on "No conversation contact"
* Check that a new empty conversation screen is displayed

# From facebook

As CEO of Facebook I need the company brand to be displayed on every product we own

## Check Facebook brand presency

* User is logged in
* Go to Settings
* Assert "From Facebook" is present on page