コード例 #1
0
class Unittest(TestCase):
    def setUp(self):
        # given
        self.atm = Atm(CashBox(cash=1000, limit=5000))
        card = MagicMock()
        card.card_holder = MagicMock()
        card.card_holder.accounts = [MagicMock()]
        card.card_holder.accounts[0].balance = 2000
        self.atm.insert_card(card)
        self.atm.enter_pin('1')

    def test_enter_valid_index(self):
        # when
        self.atm.select_account(0)

        # then
        self.assertEqual(AtmAccountSelected.get_name(),
                         self.atm.get_current_state_name())

    def test_enter_invalid_index(self):
        # when
        self.atm.select_account(2)

        # then
        self.assertEqual(AtmAuthorized.get_name(),
                         self.atm.get_current_state_name())
コード例 #2
0
class TestAtm(unittest.TestCase):
    def setUp(self):
        self.atm = Atm()
        self.atm.enter_pin(777)

    def test_atm_gives_money(self):
        money = self.atm.get_money(1000)
        self.assertEqual(1000, money)
コード例 #3
0
ファイル: cli.py プロジェクト: SPlyer/atm
 def _handle(self, args):
     atm = Atm()
     result = atm.dispense(int(args[0]))
     if result:
         print("Dispensed successfully in following notes: {}".format(
             ", ".join(["${}".format(r) for r in result])))
     else:
         print("Unable to dispense requested amount")
コード例 #4
0
 def setUp(self):
     # given
     self.atm = Atm(CashBox(cash=1000, limit=5000))
     card = MagicMock()
     card.card_holder = MagicMock()
     card.card_holder.accounts = [MagicMock()]
     card.card_holder.accounts[0].balance = 2000
     self.atm.insert_card(card)
コード例 #5
0
class TestAtmExceptions(unittest.TestCase):
    def setUp(self):
        self.atm = Atm()
        self.atm.enter_pin(777)

    def test_exception(self):
        try:
            self.atm.get_money(1000000)
        except Exception as e:
            self.assertEqual('Atm balance is no enough!!!', e.message)
コード例 #6
0
    def setUp(self):
        # given
        self.atm = Atm(CashBox(cash=1000, limit=5000))
        card = MagicMock()
        card.card_holder = MagicMock()

        account = MagicMock()
        account.balance = 100
        card.card_holder.accounts = [account]
        card.card_holder.accounts[0].balance = 2000

        self.atm.insert_card(card)
        self.atm.enter_pin('1')
        self.atm.select_account(0)
コード例 #7
0
    def __init__(self):
        self.client = zulip.Client(site="https://rhtp.zulipchat.com/api/")
        self.subscribe_all()
        self.chatbot = ChatBot(
            "Test", trainer='chatterbot.trainers.ChatterBotCorpusTrainer')
        #self.chatbot.train("chatterbot.corpus.english")
        #self.chatbot.train("chatterbot.corpus.english.greetings")
        #self.chatbot.train("chatterbot.corpus.english.conversations")
        self.currency = curr()
        #self.lat_lon = latlon()
        self.language = Lang()
        self.restaurants = Rest()
        self.bus_stations = Bus()
        self.tourist_places = Tour()
        self.jobs = Job()

        self.directions = Direct()
        self.atm = Atm()
        self.subkeys = [
            "currency", "language", "restaurant", "bus", "tourist", "job",
            "direction", "atm"
        ]
コード例 #8
0
ファイル: tests_atm.py プロジェクト: iseriki/atm
class TestAtmExceptions(unittest.TestCase):

    def setUp(self):
        self.atm = Atm()
        self.atm.enter_pin(777)
        self.atm2 = Atm()

    def test_gives_10001_money(self):
        '''Trying to give the amount more available'''
        try:
            self.atm.get_money(10001)
        except Exception as e:
            self.assertEqual('Atm balance is no enough!!!', e.message)

    def test_incorrect_pin(self):
        '''Testing an incorrect pin'''
        try:
            self.atm2.enter_pin(77)
        except Exception as e:
            self.assertEqual('Incorrect Pin!!!', e.message)
コード例 #9
0
class ZulipBot(object):
    def __init__(self):
        self.client = zulip.Client(site="https://rhtp.zulipchat.com/api/")
        self.subscribe_all()
        self.chatbot = ChatBot(
            "Test", trainer='chatterbot.trainers.ChatterBotCorpusTrainer')
        #self.chatbot.train("chatterbot.corpus.english")
        #self.chatbot.train("chatterbot.corpus.english.greetings")
        #self.chatbot.train("chatterbot.corpus.english.conversations")
        self.currency = curr()
        #self.lat_lon = latlon()
        self.language = Lang()
        self.restaurants = Rest()
        self.bus_stations = Bus()
        self.tourist_places = Tour()
        self.jobs = Job()

        self.directions = Direct()
        self.atm = Atm()
        self.subkeys = [
            "currency", "language", "restaurant", "bus", "tourist", "job",
            "direction", "atm"
        ]
        #mesg = dhelp()
        #self.client.send_message({
        #	"type": "stream",
        #	"content" : self.mesg
        #	})

    def urls(self, link):
        urls = re.findall(
            'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
            link)
        return urls

    def subscribe_all(self):
        json = self.client.get_streams()["streams"]
        streams = [{"name": stream["name"]} for stream in json]
        self.client.add_subscriptions(streams)

    def help(self):
        message = "**Welcome to I-BOT**\nIBOT has various subfields\nType `ibot help <subfield>` to get help for specific subfield.\n"
        message += "\n**Subfields**\n"
        message += "`currency` - Get currency conversion rate\n"
        message += "`atm` - Get addresses of nearby ATM(s)\n"
        message += "`restaurant` - Get addresses of nearby restaurant(s)\n"
        message += "`bus` - Get addresses of nearest bus stand(s)\n"
        message += "`tourist` - Get addresses of nearby tourist place(s)\n"
        message += "`job` - Get a list of jobs available nearby\n"
        message += "`direction` - Get directions from one place to other\n"
        message += "`language` - Translate your English sentences to other languages\n"
        message += "\nIf you're bored Talk to IBOT, it will supercharge you"
        return message

    def help_sub(self, key):
        key = key.lower()
        message = "**Usage**\n"
        if key == "currency":
            message += "`ibot currency from <currency code - 1> to <currency code - 2>` - To get currency conversion rate.\n"
        elif key == "atm":
            message += "`ibot atm <nearby location>` - To get addresses of nearby ATM(s).\n"
        elif key == "restaurant":
            message += "`ibot restaurant <nearby location>` - To get addresses of nearby restaurant(s).\n"
        elif key == "bus":
            message += "`ibot bus <nearby location>` - To get addresses of nearby bus stand(s).\n"
        elif key == "tourist":
            message += "`ibot tourist <nearby location>` - To get addresses of nearby tourist place(s).\n"
        elif key == "job":
            message += "`ibot job <nearby location>` - To get a list of jobs available nearby.\n"
        elif key == "direction":
            message += "`ibot direction from <source> to <destination>` - To get directions from one place to another.\n"
        elif key == "language":
            message += "`ibot language to <language name>` - To translate your English sentences to other languages.\n"
        else:
            message = self.help()
            message += "\n{} is not a valid subfield\n".format(key)
        return message

    def process(self, msg):
        content = msg["content"].split()
        sender_email = msg["sender_email"]
        ttype = msg["type"]
        stream_name = msg['display_recipient']
        stream_topic = msg['subject']

        print(content)
        l = len(content)
        #		temstr = spell(content[1].lower())
        #		content[1] = temstr
        #		print(content[1])
        if sender_email == BOT_MAIL:
            return

        print("doing")

        if content[0].lower() == "ibot" or content[0] == "@**IBOT**":
            if content[1].lower() == "currency":
                message = self.currency.curfun(content)
                #print(message)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "latilongi":
                message = self.lat_lon.latlonfun(content)
                #print(message)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "language":
                message = self.language.langconvert(content)
                #print(message)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "restaurant":
                message = self.restaurants.restfun(content)
                #print(message)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "bus":
                message = self.bus_stations.busfun(content)
                #print(message)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "tourist":
                message = self.tourist_places.tourfun(content)
                #print(message)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "job":
                message = self.jobs.jobfun(content)
                #print(message)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "atm":
                message = self.atm.atmfun(content)
                #print(message)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "direction":
                message = self.directions.directfun(content)
                #print(message)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "help" and len(content) == 2:
                message = self.help()
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })
            if content[1].lower() == "help" and len(content) > 2:
                subkey = content[2]
                message = self.help_sub(subkey)
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })

            if content[1] not in self.subkeys:
                ip = content[1:]
                ip = " ".join(ip)
                message = self.chatbot.get_response(ip).text
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": message
                })

        if self.urls(" ".join(content)):
            summary = self.w.wiki(" ".join(content))
            if summary:
                self.client.send_message({
                    "type": "stream",
                    "subject": msg["subject"],
                    "to": msg["display_recipient"],
                    "content": summary
                })
        elif "ibot" in content and content[0] != "ibot":
            self.client.send_message({
                "type":
                "stream",
                "subject":
                msg["subject"],
                "to":
                msg["display_recipient"],
                "content":
                "Alas! Finally you called me :blush:"
            })
        else:
            return
コード例 #10
0
 def setUpClass(cls) -> None:
     cls.a = Atm(100, 'pz', 16123412341234123412341234, 1234)
コード例 #11
0
class TestAtmPinBlock(unittest.TestCase):
    """
    Testing block with a pin input
    """
    def setUp(self):
        self.term = Atm()

    def test_input_correct_pin_and_get_balance(self):

        self.term.enter_pin(777)
        bal = self.term.check_balance()
        self.assertEqual(bal, 10000)

    def test_input_wrong_pin_three_times_and_get_error_message(self):

        try:
            self.term.enter_pin(111)
            self.term.enter_pin(111)
            self.term.enter_pin(111)
        except IncorrectPin as e:
            pass
        except AttemptsOver as e:
            self.assertEqual('Attempts are over!!!', e.message)

    def test_input_wrong_pin_two_times_then_correct_and_get_balance(self):

        try:
            self.term.enter_pin(111)
            self.term.enter_pin(111)
            self.term.enter_pin(777)
            bal = self.term.check_balance()
            self.assertEqual(bal, 10000)
        except IncorrectPin as e:
            pass

    def test_input_pin_value_more_than_three_characters(self):

        try:
            self.term.enter_pin(8888)
        except Exception as e:
            self.assertEqual("Incorrect Pin!!!", e.message)

    def test_input_pin_value_less_than_three_characters(self):

        try:
            self.term.enter_pin(88)
        except Exception as e:
            self.assertEqual("Incorrect Pin!!!", e.message)

    def test_input_pin_value_string(self):

        try:
            self.term.enter_pin("something")
        except Exception as e:
            self.assertEqual("Incorrect Pin!!!", e.message)

    def test_input_pin_value_char(self):

        try:
            self.term.enter_pin('A')
        except Exception as e:
            self.assertEqual("Incorrect Pin!!!", e.message)

    def test_input_pin_value_empty(self):

        try:
            self.term.enter_pin("")
        except Exception as e:
            self.assertEqual("Incorrect Pin!!!", e.message)

    def test_input_pin_value_space(self):

        try:
            self.term.enter_pin(" ")
        except Exception as e:
            self.assertEqual("Incorrect Pin!!!", e.message)

    def test_without_input_pin_check_balance(self):

        try:
            self.term.check_balance()
        except Exception as e:
            self.assertEqual("Enter pin first!!!", e.message)

    def test_without_input_pin_get_money(self):

        try:
            self.term.get_money(1000)
        except Exception as e:
            self.assertEqual("Enter pin first!!!", e.message)

    def test_without_input_pin_rise_money(self):

        try:
            self.term._rise_money(1000)
        except Exception as e:
            self.assertEqual("Enter pin first!!!", e.message)
コード例 #12
0
ファイル: tests_atm.py プロジェクト: iseriki/atm
class TestAtm(unittest.TestCase):

    def setUp(self):
        self.atm = Atm()
        self.atm.enter_pin(777)



    def test_enter_true_pin_and_check_balance(self):
        '''Enter the correct pin and check the balance'''
        balance = self.atm.check_balance()
        self.assertEqual(10000, balance)

    def test_gives_4000_money(self):
        '''Give money in the amount of 4000'''
        money = self.atm.get_money(4000)
        self.assertEqual(4000, money)

    def test_gives_10000_money(self):
        '''Give money in the amount of 10000'''
        money = self.atm.get_money(10000)
        self.assertEqual(10000, money)

    def test_gives_9999_money(self):
        '''Give money in the amount of 9999'''
        money = self.atm.get_money(9999)
        self.assertEqual(9999, money)

    def test_gives_0_money(self):
        '''Give money in the amount of 0'''
        money = self.atm.get_money(0)
        self.assertEqual(0, money)

    @unittest.skip("Bug #0001")
    def test_gives_min_1_money(self):
        '''A negative amount is given'''
        money = self.atm.get_money(-1)
        self.assertEqual(0, money)

    def test_rise_1000000_money(self):
        '''Add the amount of 1000000'''
        rise_money = self.atm._rise_money(1000000)
        self.assertEqual(1010000, rise_money)

    def test_rise_0_money(self):
        '''Add the amount of 0'''
        rise_money = self.atm._rise_money(0)
        self.assertEqual(10000, rise_money)

    @unittest.skip("Bug #0002")
    def test_rise_min_1_money(self):
        '''A negative amount is added'''
        rise_money = self.atm._rise_money(-1)
        self.assertEqual(10000, rise_money)
コード例 #13
0
ファイル: 系统主程序.py プロジェクト: w45957968/learn
def main():
    view = View()
    atm = Atm()
    view.admin_view()
    if view.adminlogin() == -1:
        return -1
    print("登陆成功.........")
    time.sleep(2)
    while 1:
        view.guest_view()
        option = input("请选择您的操作:")
        if option == "1":
            atm.creatUser()
        elif option == "2":
            atm.searchInfo()
        elif option == "3":
            atm.withdrawal()
        elif option == "4":
            atm.deposit()
        elif option == "5":
            atm.transferAccounts()
        elif option == "6":
            atm.changePassword()
        elif option == "7":
            atm.lockUser()
        elif option == "8":
            atm.unlockUser()
        elif option == "9":
            atm.makeANewCard()
        elif option == "0":
            atm.closeUser()
        elif option == "q" or option == "Q":
            if view.adminlogin() == "a":
                print("系统正在退出中....")
                time.sleep(2)
                break

        elif option == "a" or option == "A":
            if view.adminlogin() == -1:
                pass
コード例 #14
0
ファイル: lab25V2.py プロジェクト: drewherron/class_sheep
from atm import Atm

#=================================Version 2====================================
# Have the ATM maintain a list of transactions. Every time the user makes a deposit or withdrawal, add a string to a list saying 'user deposited $15' or 'user withdrew $15'.

balance = Atm()

user_deposit = int(input('how much do you want to deposit?'))

balance.deposit(user_deposit)

user_withdrawal = int(input('how much do you want to withdraw?'))

balance.withdraw(user_withdrawal)

balance.print_transactions()
コード例 #15
0
class Unittest(TestCase):
    def setUp(self):
        # given
        self.atm = Atm(CashBox(cash=1000, limit=5000))
        card = MagicMock()
        card.card_holder = MagicMock()

        account = MagicMock()
        account.balance = 100
        card.card_holder.accounts = [account]
        card.card_holder.accounts[0].balance = 2000

        self.atm.insert_card(card)
        self.atm.enter_pin('1')
        self.atm.select_account(0)

    def test_select_menu(self):
        # when
        self.atm.select_deposit()

        # then
        self.assertEqual(
            AtmProcessingDeposit.get_name(),
            self.atm.get_current_state_name()
        )

    def test_put_valid_amount(self):
        # when
        self.atm.select_deposit()
        self.atm.put_in_cash(100)

        # then
        self.assertEqual(
            AtmDisplayingBalance.get_name(),
            self.atm.get_current_state_name()
        )

    def test_put_invalid_amount(self):
        # when
        self.atm.select_deposit()
        self.atm.put_in_cash(-100)

        # then
        self.assertEqual(
            AtmExit.get_name(),
            self.atm.get_current_state_name()
        )
コード例 #16
0
ファイル: tests.py プロジェクト: giovaneliberato/codekatas
 def test_withdraw_two_bills_same_value(self):
     atm = Atm({50: 2})
     result = atm.withdraw(100)
     self.assertEquals(result, '50 | 50')
     self.assertEquals(atm.bills, {50: 0})
コード例 #17
0
def main():
    allUserInfo = {}

    try:
        f = open("peoplelist.txt", "rb")
        if len(f.read()) > 0:
            f.seek(0, 0)
            allUserInfo = pickle.load(f)
    except Exception as msg:
        print(msg)
        f = open("peoplelist.txt", "wb")
        print(msg)
    finally:
        f.close()

    adminview = View()
    adminview.printSysUI()

    atm = Atm(allUserInfo)

    #选择角色
    print("请选择角色:")
    print("1:管理员")
    print("2:普通用户")
    roleNum = input()  #角色序号
    if roleNum == '1':
        if not adminview.adminlogin():
            print("管理员登录失败")
            return
        time.sleep(1)
        print("管理员登录成功!请稍候...")

    elif roleNum == '2':
        #验证卡号是否存在
        while True:
            inputCard = input("请输入您的卡号:")
            isExist = atm.isExistCard(inputCard)
            if isExist:
                break

        #验证密码是否正确
        if not atm.isExistPwd(inputCard):
            #文件中写入所有用户信息
            f = open("peoplelist.txt", "wb")
            pickle.dump(atm.allUserInfo, f)
            f.close()
            return

    while True:
        adminview.printUI(roleNum)
        inputNum = input("请输入操作选项(数字):")

        if inputNum == '1' and roleNum == '1':
            print(atm.allUserInfo)
            atm.createUser()
            print(atm.allUserInfo)

        elif inputNum == '2' and roleNum == '2':
            #取款操作
            atm.nomony(inputCard)
        elif inputNum == '3' and roleNum == '2':
            atm.cunqian(inputCard)
        elif inputNum == '4' and roleNum == '2':
            atm.transMoney(inputCard)
        elif inputNum == '5' and roleNum == '2':
            atm.allpeople(inputCard)
        elif inputNum == '6' and roleNum == '2':
            atm.newpassword(inputCard)
        elif inputNum == '7' and roleNum == '1':
            if atm.jiechusuooding():
                print("解卡成功")
        elif inputNum == '0':
            exit()
        else:
            print("您操作有误,请重新操作!")

        #文件中写入所有用户信息
        f = open("peoplelist.txt", "wb")
        pickle.dump(atm.allUserInfo, f)
        f.close()
コード例 #18
0
card
class Card
attribute: cardId, cardPassword, money


atm
class atm
attribute: users
behavior: open account, search info, deposit, withdraw, transfer, change password, lock account, unlock account,
cancel account, re-make a card, exit

'''
import random
from atm import Atm
from card import Card
ATM = Atm()
# CARD = Card()
# print(CARD.card_id)
while True:
    ATM.atm_interface()
    print("Please Enter a number to do the operation:  ")
    operation = str(input())
    if operation == "1":
        ATM.open_account()

    elif operation == "2":
        ATM.balance_info()

    elif operation == "3":
        ATM.deposit()
コード例 #19
0
 def setUpClass(cls):
     cls.atm = Atm(CashBox(cash=1000, limit=5000))
コード例 #20
0
ファイル: lab25.py プロジェクト: drewherron/class_sheep
from atm import Atm
#=================================Version 1====================================

#my initial balance.  setting the balance variable to the aAtm type
var = Atm()

#calling the check balance method
print(var.check_balance())

#calling the deposit method
user_deposit = round(int(input("How much money do you want to depost.\n: $")),
                     2)
var.deposit(user_deposit)

#calling the check balance method
print(var.check_balance())

#inputting how much money to withdraw, calls the check_withdrawal method, calls the withdraw funtio in the print statement
user_withdrawal = round(
    int(input("How much money do you want to withdraw? \n: $")), 2)
var.check_withdrawal(user_withdrawal)
print(f"you have ${var.withdraw(user_withdrawal)} remaining in your account")

#to determine the interest, i input how many months the account has been open and then call the calc_interest method.
time = float(input("How many months has your account been open"))
print(
    f" your total balance including interst earned is {var.calc_interest(time)}"
)
コード例 #21
0
def main():

    # 界面对象
    view = Admin()

    # 管理员开机
    view.printAdminView()
    if not view.admin_option():
        return -1

    print("登录成功!请稍后")

    # 存储所有用户的信息
    abs_path = os.getcwd()
    file_path = os.path.join(abs_path, "allusers.txt")

    with open(file_path, "rb") as f:
        all_user = pickle.load(f)

    ATM = Atm(all_user)

    view.printsysView()

    while True:
        # 等待用户操作
        view.printsysView()
        option = input("请输入您的操作:")
        if option == "1":
            # 目标向用户字典中增加(卡号———用户)
            ATM.create_user()

        elif option == "2":
            ATM.search_user()

        elif option == "3":
            ATM.withdraws()

        elif option == "4":
            ATM.save_money()

        elif option == "5":
            ATM.transfer_money()

        elif option == "6":
            ATM.change_password()
        elif option == "7":
            ATM.lock_user()

        elif option == "8":
            ATM.unlock_user()

        elif option == "9":
            ATM.new_card()

        elif option == "0":
            print("销户")

        elif option == "q":
            if view.admin_option():
                print("退出,成功")
                # 将当前系统中的文件保存进入文件中
                with open(file_path, "wb") as f:
                    pickle.dump(ATM.all_user, f)
                return True

            else:
                print("退出失败,请重新退出")
                time.sleep(1)
        elif option == "c":
            ATM.user_check()
        time.sleep(2)
コード例 #22
0
ファイル: lab25v3.py プロジェクト: drewherron/class_sheep
from atm import Atm

#===============================Version 3====================================

balance = Atm()

while True:

    user_input = input("deposit, withdraw, check balance, history\n :")

    if user_input == 'cancel':
        break

    if user_input == 'deposit':
        user_deposit = round(
            int(input("How much money do you want to deposit.\n: $")), 2)
        balance.deposit(user_deposit)
        print(balance.check_balance())

    elif user_input == 'withdraw':
        user_withdrawal = round(
            int(input("How much money do you want to withdraw? \n: $")), 2)
        balance.check_withdrawal(user_withdrawal)
        print(
            f"you have ${balance.withdraw(user_withdrawal)} remaining in your account"
        )

    elif user_input == 'check_balance':  #time is months
        time = float(input("How many months has your account been open"))
        print(
            f" your total balance including interst earned is {balance.calc_interest(time)}"
コード例 #23
0
def main():
    #infoList = []
    atm = Atm()
    view = View("1", "123", "userlist.txt")
    signal = view.printLoginView()

    atm.loadData(view.dataPath)
    while signal == True:
        signal1 = view.printUserView()
        if str(signal1) == "1":
            atm.kaiHu()
        elif str(signal1) == "2":
            atm.chaXun()
        elif str(signal1) == "3":
            atm.quKan()
        elif str(signal1) == "4":
            atm.cunKuan()
        elif str(signal1) == "5":
            atm.zhuanZhang()
        elif str(signal1) == "6":
            atm.gaiMiMa()
        elif str(signal1) == "7":
            atm.suoDing()
        elif str(signal1) == "8":
            atm.jieSuo()
        elif str(signal1) == "9":
            atm.buKa()
        elif str(signal1) == "10":
            atm.xiaoHu()
        elif str(signal1) == "t":
            if view.printLogOutView() == True:
                atm.chiJiuHua(view.dataPath)
                break
        else:
            print("输入有误")
        time.sleep(3)
    else:
        print("The error code is %s ." % signal)
コード例 #24
0
def main():
    # 存取所以用户的信息

    # 界面对象
    admin = Admin()
    admin.print_admin_view()
    # 用户管理员开机
    # 如果view.admin_login()返回值是-1,程序结束。如果是0就不会执行下去
    if admin.admin_option() == -1:
        return -1

    # 提款机对象
    '''
    
    f = open(file_path, "rb")
    all_users = pickle.load(f)
    atm = Atm(all_users)
    '''
    file_path = os.path.join(os.getcwd(), "a.txt")
    all_users = {}
    atm = Atm(all_users)

    # admin.print_sys_function_view()
    while True:
        admin.print_sys_function_view()
        # 等待用户操作
        option = input("请输入你的操作:")
        if option == "1":
            atm.create_user()
        elif option == "2":
            atm.search_user_info()
        elif option == "3":
            atm.get_money()
        elif option == "4":
            print("存款")
        elif option == "5":
            print("转账")
        elif option == "6":
            print("改密")
        elif option == "7":
            atm.lock_user()
        elif option == "8":
            atm.unlock_user()
        elif option == "9":
            print("补卡")
        elif option == "0":
            print("销户")
        elif option == "q":
            if not admin.admin_option():
                # 讲当前系统中用户信息保存到文件中
                # abs_path = os.getcwdb()        # 获取当前目录觉得路径
                # file_path = os.path.join(os.getcwdb(), "allusers.txt")
                f = open(file_path, "wb")
                pickle.dump(atm.all_user, f)
                f.closed
                print(file_path)
                return -1

        time.sleep(0.5)
コード例 #25
0
ファイル: tests.py プロジェクト: giovaneliberato/codekatas
 def test_withdraw_two_bills_different_values(self):
     atm = Atm({50: 1, 20: 1})
     result = atm.withdraw(70)
     self.assertEquals(result, '50 | 20')
     self.assertEquals(atm.bills, {50: 0, 20: 0})
コード例 #26
0
from atm import Atm

card_number = input("Enter your card number: ")
pin_number = input("Enter your pin number: ")
atm = Atm(card_number, pin_number)
コード例 #27
0
ファイル: tests.py プロジェクト: giovaneliberato/codekatas
 def test_withdraw_not_using_all_the_values(self):
     atm = Atm({50: 1, 10: 1, 20: 2})
     result = atm.withdraw(40)
     self.assertEquals(result, '20 | 20')
     self.assertEquals(atm.bills, {50: 1, 10: 1, 20: 0})
コード例 #28
0
ファイル: tests.py プロジェクト: giovaneliberato/codekatas
 def test_always_gives_the_minimun_amount_of_bills(self):
     atm = Atm({50: 1, 10: 4, 20: 2})
     result = atm.withdraw(40)
     self.assertEquals(result, '20 | 20')
     self.assertEquals(atm.bills, {50: 1, 10: 4, 20: 0})
コード例 #29
0
ファイル: main.py プロジェクト: ebsiqueira/SAAS
# Versão 1.0                                    #
# Modelo de subsistema para caixas eletrônicos  #
#################################################

#################################################
# Sistema hipotético para controle de notas em  #
# caixas eletrônicos. Caso fosse ser utilizado, #
# os prints e inputs seriam substituidos pelas  #
# devidas entradas e saídas de dados indicadas. #
#################################################

# Import da classe Atm, localizada em atm.py
from atm import Atm

# Criação de um "Caixa Eletrônico"
atm = Atm()

# Controle do Menu
controleMenu = True

# Saldo de Conta fictício para testes de execução
saldoConta = 9999

while (controleMenu):
    menu = int(input('\n1. Abastecer\n2. Sacar\n3. Consultar\n4. Sair\n> '))

    # Abastecimento do caixa
    if (menu == 1):
        nota = int(input("\nCédula que será inserida: "))
        quantidade = int(input('Quantidade de cédulas: '))
        atm.abastece(nota, quantidade)
コード例 #30
0
 def setUp(self):
     self.atm = Atm()
     self.atm.enter_pin(777)
コード例 #31
0
def main():
    filepath = os.path.join(os.getcwd(), "allusers.txt")

    f = open(filepath, "rb")

    allUsers = pickle.load(f)

    admin1 = int(input("请输入你的卡号:"))
    admin = Admin(allUsers,admin1)               #将登陆账户传入到用户类中储存

    atm = Atm(allUsers,admin1)                    #将登陆账户传入到atm类中储存
    if admin.login():

        admin.welcomeView()

        print("*********************************************************")
        # print(allUsers)
        print("请选择一下功能选项:")
        time.sleep(2)

        while True:
            admin.startView()
            option = input("请输入你要办理的业务号:")
            if option == '1':
                atm.createUser()
            elif option == '2':
                atm.selectInfor()
            elif option == '3':
                atm.get_Money()
            elif option == '4':
                atm.save_Money()
            elif option == '5':
                atm.transfer_Accounts()
            elif option == '6':
                atm.change_Password()
            elif option == '7':
                atm.card_Lock()
            elif option == '8':
                atm.card_ReLock()
            elif option == '9':
                atm.fill_Card()
            elif option == '0':
                atm.del_User()
            elif option == 't':
                f = open(filepath,"wb")
                pickle.dump(allUsers,f)
                f.close()
                break
            # time.sleep(2)
    else:
        atm.createUser()
        while True:
            admin.startView()
            option = input("请输入你要办理的业务号:")
            if option == '1':
                atm.createUser()
            elif option == '2':
                atm.selectInfor()
            elif option == '3':
                atm.get_Money()
            elif option == '4':
                atm.save_Money()
            elif option == '5':
                atm.transfer_Accounts()
            elif option == '6':
                atm.change_Password()
            elif option == '7':
                atm.card_Lock()
            elif option == '8':
                atm.card_ReLock()
            elif option == '9':
                atm.fill_Card()
            elif option == '0':
                atm.del_User()
            elif option == 't':
                f = open(filepath, "wb")
                pickle.dump(allUsers, f)
                # f.write(allUsers.encode("utf-8"))
                f.close()
                # return -1
                break
コード例 #32
0
class TestAtmMoneyBlock(unittest.TestCase):
    """
    Testing block with a cash transactions
    """
    def setUp(self):
        self.term = Atm()
        self.term.enter_pin(777)

    def test_rise_money(self):

        rise = self.term._rise_money(1000)
        self.assertEqual(rise, 11000)

    def test_get_money(self):
        get = self.term.get_money(1000)
        balance = self.term.check_balance()
        self.assertEqual(balance, 10000 - get)

    def test_rise_money_with_negative_value(self):

        try:
            self.term._rise_money(-1000)
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)

    def test_rise_money_with_zero_value(self):

        try:
            self.term._rise_money(0)
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)

    def test_rise_money_with_very_big_value(self):

        try:
            self.term._rise_money(999999999)
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)

    def test_rise_money_with_string_value(self):

        try:
            self.term._rise_money("Something")
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)

    def test_rise_money_with_character_value(self):

        try:
            self.term._rise_money('A')
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)

    def test_get_money_with_negative_value(self):

        try:
            self.term.get_money(-1000)
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)

    def test_get_money_with_zero_value(self):

        try:
            self.term.get_money(0)
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)

    def test_get_money_with_very_big_value(self):

        try:
            self.term.get_money(999999999)
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)

    def test_get_money_with_string_value(self):

        try:
            self.term.get_money("Something")
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)

    def test_get_money_with_character_value(self):

        try:
            self.term.get_money('A')
        except Exception as e:
            self.assertEqual("Atm balance is no enough!!!", e.message)
コード例 #33
0
ファイル: tests.py プロジェクト: giovaneliberato/codekatas
 def test_withdraw_single_bill(self):
     atm = Atm({50: 1})
     result = atm.withdraw(50)
     self.assertEquals(result, '50')
     self.assertEquals(atm.bills, {50: 0})
コード例 #34
0
 def setUp(self):
     self.term = Atm()
     self.term.enter_pin(777)
コード例 #35
0
def main():
    # 1.创建管理员对象
    ad = Admin("admin", "123")
    # 2. 管理员登录
    ad.landUI()
    # 3.创建atm对象
    atm = Atm()
    # 4.显示操作界面
    while True:
        atm.printOptionUI()  # 5.用户输入对应的编号,调用对应的函数
        bh = input("请输入编号")
        if bh == "1":
            atm.creatUser()
        elif bh == "2":
            atm.serach()
        elif bh == "3":
            atm.save()
        elif bh == "4":
            atm.take()
        elif bh == "5":
            atm.transfer()
        elif bh == "6":
            atm.change()
        elif bh == "7":
            atm.lock()
        elif bh == "8":
            atm.unlock()
        elif bh == "9":
            atm.clear()
        elif bh == "T":
            atm.exit()
コード例 #36
0
class Unittest(TestCase):
    def setUp(self):
        # given
        self.atm = Atm(CashBox(cash=1000, limit=2000))
        card = MagicMock()
        card.card_holder = MagicMock()

        account = MagicMock()
        account.balance = 100
        card.card_holder.accounts = [account]
        card.card_holder.accounts[0].balance = 3000

        self.atm.insert_card(card)
        self.atm.enter_pin('1')
        self.atm.select_account(0)

    def test_cash_box_overflow(self):
        # when
        self.atm.select_deposit()
        self.atm.put_in_cash(1500)

        # then
        self.assertEqual(
            AtmExit.get_name(),
            self.atm.get_current_state_name()
        )

    def test_enter_overflow2(self):
        # when
        self.atm.select_withdraw()
        self.atm.enter_withdrawal_amount(1500)
        self.atm.take_out_cash(1500)

        # then
        self.assertEqual(
            AtmExit.get_name(),
            self.atm.get_current_state_name()
        )