Skip to content
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
72 changes: 72 additions & 0 deletions projects/Billing_system/test_BillAppBillArea.py.invalid
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import pytest
from tkinter import *
from tkinter import messagebox
from projects.Billing_system.billing_system import Bill_App

class TestBillApp(object):

def test_bill_area_missing_customer_details(self, init_app):
# Arrange
init_app.c_name.set("")
init_app.c_phone.set("")

# Act & Assert
with pytest.raises(Exception) as e_info:
init_app.bill_area()
assert str(e_info.value) == "Customer Details Are Must"

def test_bill_area_no_products_purchased(self, init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")

# Act & Assert
with pytest.raises(Exception) as e_info:
init_app.bill_area()
assert str(e_info.value) == "No Product Purchased"

@pytest.fixture
def init_app():
root = Tk()
obj = Bill_App(root)
yield obj
root.destroy()

# Added the missing Bill_App class
class Bill_App:
def __init__(self, root):
self.root = root

def save_bill(self):
op = messagebox.askyesno("Save Bill", "Do you want to save the bill?")
if op > 0:
self.bill_data = self.txtarea.get('1.0', END)
f1 = open(f"bills/{self.bill_no.get()}.txt", "w")
f1.write(self.bill_data)
f1.close()
messagebox.showinfo("Saved", f"Bill no:{self.bill_no.get()} Saved Successfully")
else:
return

def welcome_bill(self):
self.txtarea.delete('1.0', END)
self.txtarea.insert(END, "\tWelcome Webcode Retail")
self.txtarea.insert(END, f"\n Bill Number:{self.bill_no.get()}")
self.txtarea.insert(END, f"\nCustomer Name:{self.c_name.get()}")
self.txtarea.insert(END, f"\nPhone Number{self.c_phone.get()}")
self.txtarea.insert(END, f"\n================================")
self.txtarea.insert(END, f"\nProducts\t\tQTY\t\tPrice")

# I've added the missing imports and fixed the indentation errors
@pytest.mark.usefixtures("init_app")
def test_save_bill(init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")

# Act
init_app.save_bill()

# Assert
# Add your assert statements here
184 changes: 184 additions & 0 deletions projects/Billing_system/test_BillAppBillArea220.py.invalid
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import os
import pytest
from tkinter import *
from tkinter import messagebox
from projects.Billing_system.billing_system import Bill_App

@pytest.fixture
def init_app():
root = Tk()
obj = Bill_App(root)
yield obj
root.destroy()

def test_bill_area_missing_customer_details(init_app):
# Arrange
init_app.c_name.set("")
init_app.c_phone.set("")

# Act & Assert
with pytest.raises(Exception) as e_info:
init_app.bill_area()
assert str(e_info.value) == "Customer Details Are Must"

def test_bill_area_no_products_purchased(init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")

# Act & Assert
with pytest.raises(Exception) as e_info:
init_app.bill_area()
assert str(e_info.value) == "No Product Purchased"

def test_bill_area_medical_products_purchased(init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")
init_app.sanitizer.set(2)

# Act
init_app.bill_area()

# Assert
assert init_app.txtarea.get("1.0", "end-1c") == (
"\tWelcome Webcode Retail\n"
f" Bill Number:{init_app.bill_no.get()}\n"
f"Customer Name:John Doe\n"
f"Phone Number1234567890\n"
"================================\n"
"Products\t\tQTY\t\tPrice\n"
" Sanitizer\t\t2\t\t<price>\n"
"================================\n"
" Medical Tax\t\t\t<tax>\n"
"--------------------------------\n"
" Total Bil:\t\t\t Rs.<total_bill>\n"
"--------------------------------\n"
).replace("<price>", str(init_app.m_s_p * 2)).replace("<tax>", init_app.medical_tax.get()).replace("<total_bill>", init_app.total_bill)

def test_bill_area_grocery_products_purchased(init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")
init_app.rice.set(3)

# Act
init_app.bill_area()

# Assert
assert init_app.txtarea.get("1.0", "end-1c") == (
"\tWelcome Webcode Retail\n"
f" Bill Number:{init_app.bill_no.get()}\n"
f"Customer Name:John Doe\n"
f"Phone Number1234567890\n"
"================================\n"
"Products\t\tQTY\t\tPrice\n"
" Rice\t\t3\t\t<price>\n"
"================================\n"
" Grocery Tax\t\t\t<tax>\n"
"--------------------------------\n"
" Total Bil:\t\t\t Rs.<total_bill>\n"
"--------------------------------\n"
).replace("<price>", str(init_app.g_r_p * 3)).replace("<tax>", init_app.grocery_tax.get()).replace("<total_bill>", init_app.total_bill)

def test_bill_area_cold_drinks_products_purchased(init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")
init_app.sprite.set(1)

# Act
init_app.bill_area()

# Assert
assert init_app.txtarea.get("1.0", "end-1c") == (
"\tWelcome Webcode Retail\n"
f" Bill Number:{init_app.bill_no.get()}\n"
f"Customer Name:John Doe\n"
f"Phone Number1234567890\n"
"================================\n"
"Products\t\tQTY\t\tPrice\n"
" Sprite\t\t1\t\t<price>\n"
"================================\n"
" Cold Drinks Tax\t\t\t<tax>\n"
"--------------------------------\n"
" Total Bil:\t\t\t Rs.<total_bill>\n"
"--------------------------------\n"
).replace("<price>", str(getattr(init_app, "c_d_s_p"))).replace("<tax>", init_app.cold_drinks_tax.get()).replace("<total_bill>", init_app.total_bill)

def test_bill_area_all_products_purchased(init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")
init_app.sanitizer.set(2)
init_app.rice.set(3)
init_app.sprite.set(1)

# Act
init_app.bill_area()

# Assert
assert init_app.txtarea.get("1.0", "end-1c") == (
"\tWelcome Webcode Retail\n"
f" Bill Number:{init_app.bill_no.get()}\n"
f"Customer Name:John Doe\n"
f"Phone Number1234567890\n"
"================================\n"
"Products\t\tQTY\t\tPrice\n"
" Sanitizer\t\t2\t\t<price>\n"
" Rice\t\t3\t\t<price>\n"
" Sprite\t\t1\t\t<price>\n"
"================================\n"
" Medical Tax\t\t\t<tax>\n"
" Grocery Tax\t\t\t<tax>\n"
" Cold Drinks Tax\t\t\t<tax>\n"
"--------------------------------\n"
" Total Bil:\t\t\t Rs.<total_bill>\n"
"--------------------------------\n"
).replace("<price>", str(init_app.m_s_p * 2 + init_app.g_r_p * 3 + getattr(init_app, "c_d_s_p"))).replace("<tax>", str(float(init_app.medical_tax.get()) + float(init_app.grocery_tax.get()) + float(init_app.cold_drinks_tax.get()))).replace("<total_bill>", init_app.total_bill)

def test_bill_area_taxes(init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")
init_app.sanitizer.set(2)
init_app.rice.set(3)
init_app.sprite.set(1)

# Act
init_app.bill_area()

# Assert
assert float(init_app.txtarea.get("1.0", "end-1c").split("Medical Tax\t\t\t")[1].split("\n")[0]) == pytest.approx(float(init_app.medical_tax.get()), abs=0.01)
assert float(init_app.txtarea.get("1.0", "end-1c").split("Grocery Tax\t\t\t")[1].split("\n")[0]) == pytest.approx(float(init_app.grocery_tax.get()), abs=0.01)
assert float(init_app.txtarea.get("1.0", "end-1c").split("Cold Drinks Tax\t\t\t")[1].split("\n")[0]) == pytest.approx(float(init_app.cold_drinks_tax.get()), abs=0.01)

def test_bill_area_total_bill(init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")
init_app.sanitizer.set(2)
init_app.rice.set(3)
init_app.sprite.set(1)

# Act
init_app.bill_area()

# Assert
assert float(init_app.txtarea.get("1.0", "end-1c").split(" Total Bil:\t\t\t Rs.")[1]) == pytest.approx(float(init_app.total_bill), abs=0.01)

@pytest.mark.usefixtures("init_app")
def test_save_bill(init_app):
# Arrange
init_app.c_name.set("John Doe")
init_app.c_phone.set("1234567890")
init_app.sanitizer.set(2)
init_app.rice.set(3)
init_app.sprite.set(1)

# Act
init_app.bill_area()
init_app.save_bill()

# Assert
assert os.path.exists(f"bills/{init_app.bill_no.get()}.txt")
55 changes: 55 additions & 0 deletions projects/Billing_system/test_BillAppClearData.py.invalid
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest
import random
from tkinter import *
from tkinter import messagebox
from billing_system import Bill_App

@pytest.mark.unit
@pytest.mark.clear_data
def test_clear_data_resets_quantity_variables():
obj = Bill_App(root)
initial_quantities = {
"sanitizer": obj.sanitizer.get(),
"mask": obj.mask.get(),
"hand_gloves": obj.hand_gloves.get(),
"dettol": obj.dettol.get(),
"newsprin": obj.newsprin.get(),
"thermal_gun": obj.thermal_gun.get(),
# Add other quantity variables here
}
obj.clear_data()
final_quantities = {
"sanitizer": obj.sanitizer.get(),
"mask": obj.mask.get(),
"hand_gloves": obj.hand_gloves.get(),
"dettol": obj.dettol.get(),
"newsprin": obj.newsprin.get(),
"thermal_gun": obj.thermal_gun.get(),
# Add other quantity variables here
}
assert initial_quantities == final_quantities, "Some quantity variables were not reset to zero."

# ... (other test functions)

class Bill_App:
def __init__(self, root):
self.root = root

# ... (other methods)

def clear_data(self):
op = messagebox.askyesno("Clear", "Do you really want to Clear?")
if op > 0:
self.sanitizer.set(0)
self.mask.set(0)
self.hand_gloves.set(0)
self.dettol.set(0)
self.newsprin.set(0)
self.thermal_gun.set(0)

# ... (other variables being reset)

x = random.randint(1000, 9999)
self.bill_no.set(str(x))
self.search_bill.set("")
self.welcome_bill()
56 changes: 56 additions & 0 deletions projects/Billing_system/test_BillAppClearData588.py.invalid
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest
import random
from tkinter import *
from tkinter import messagebox
from billing_system import Bill_App

@pytest.mark.unit
@pytest.mark.clear_data
def test_clear_data_resets_quantity_variables():
obj = Bill_App(root)
initial_quantities = {
"sanitizer": obj.sanitizer.get(),
"mask": obj.mask.get(),
"hand_gloves": obj.hand_gloves.get(),
"dettol": obj.dettol.get(),
"newsprin": obj.newsprin.get(),
"thermal_gun": obj.thermal_gun.get(),
# Add other quantity variables here
}
obj.clear_data()
final_quantities = {
"sanitizer": obj.sanitizer.get(),
"mask": obj.mask.get(),
"hand_gloves": obj.hand_gloves.get(),
"dettol": obj.dettol.get(),
"newsprin": obj.newsprin.get(),
"thermal_gun": obj.thermal_gun.get(),
# Add other quantity variables here
}
assert initial_quantities == final_quantities, "Some quantity variables were not reset to zero."

# ... (other test functions)

class Bill_App:
def __init__(self, root):
# ... (initialization code)

def clear_data(self):
op = messagebox.askyesno("Clear", "Do you really want to Clear?")
if op > 0:
self.sanitizer.set(0)
self.mask.set(0)
self.hand_gloves.set(0)
self.dettol.set(0)
self.newsprin.set(0)
self.thermal_gun.set(0)

# ... (other reset code)

x = random.randint(1000, 9999)
self.bill_no.set(str(x))

self.search_bill.set("")
self.welcome_bill()

# ... (other methods)
21 changes: 21 additions & 0 deletions projects/Billing_system/test_BillAppExitApp.py.invalid
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
import tkinter as tk
from tkinter import messagebox
from projects.billing_system.billing_system import Bill_App

@pytest.fixture
def setup_bill_app():
root = tk.Tk()
obj = Bill_App(root)
yield obj
root.destroy()

def test_display_correct_confirmation_dialog(setup_bill_app):
# Arrange
expected_message = "Do you really want to exit?"

# Act
result = setup_bill_app.exit_app()

# Assert
assert messagebox.showinfo.called_with("Exit", expected_message)
Loading