예제 #1
0
 def setUp(self):
     '''
     Método executado antes de cada Test Case.
     O atributo phonebook ficará disponível 
     para todos os Test Cases.
     '''
     self.phonebook = Phonebook()
예제 #2
0
def main():
    main_frame = Tk()
    main_frame.title("Phonebook")
    main_frame.geometry("750x450+50+50")
    main_frame.resizable(False, False)
    app = Phonebook(main_frame)
    main_frame.mainloop()
예제 #3
0
def test_phonebook_gives_access_to_names_and_numbers():
    phonebook = Phonebook()
    phonebook.add('Alice', '12345')
    phonebook.add("Bob", "123")
    assert set(phonebook.names()) == {'Alice', 'Bob'}
    assert '12345' in phonebook.numbers()
    assert '123' in phonebook.numbers()
예제 #4
0
def phonebook(request):
	phonebook = Phonebook()
	# check documentation for newer cleanup syntax
	def cleanup_phonebook():
		phonebook.clear()
	request.addfinalizer(cleanup_phonebook)
	return phonebook
예제 #5
0
파일: callblocker.py 프로젝트: mvo5/a1fbox
 def __init__(self, fc,
              whitelist_pbids, blacklist_pbids, blocklist_pbid, blockname_prefix='',
              min_score=6, min_comments=3,
              block_abroad=False, block_illegal_prefix=True,
              logger=None):
     """ Provide a whitelist phonebook (normally first index 0) and where blocked numbers should go into. """
     self.whitelist_pbids = whitelist_pbids
     self.blacklist_pbids = blacklist_pbids
     self.blocklist_pbid = blocklist_pbid
     self.blockname_prefix = blockname_prefix
     self.min_score = int(min_score)
     self.min_comments = int(min_comments)
     # self.block_anon = block_anon  # How should that work? Impossible?
     self.block_abroad = block_abroad
     self.block_illegal_prefix = block_illegal_prefix
     self.logger = logger
     print("Retrieving data from Fritz!Box..")
     self.pb = Phonebook(fc=fc)
     fritz_model = self.pb.fc.modelname
     fritz_os = self.pb.fc.system_version
     self.cp = CallPrefix(fc=self.pb.fc)
     self.pb.ensure_pb_ids_valid(self.whitelist_pbids + self.blacklist_pbids + [self.blocklist_pbid])
     self.reload_phonebooks()
     if self.cp.country_code != '0049':
         log.warning('This script was developed for usage in Germany - please contact the author!')
     print(f'Call blocker initialized.. '
           f'model:{fritz_model} ({fritz_os}) '
           f'country:{self.cp.country_code_name} ({self.cp.country_code}) '
           f'area:{self.cp.area_code_name} ({self.cp.area_code}) '
           f'whitelisted:{len(self.whitelist)} blacklisted:{len(self.blacklist)} prefixes:{len(self.cp.prefix_dict)}')
     if TELEGRAM_BOT_URL:
         requests.get(TELEGRAM_BOT_URL + quote("CallBlocker: initialized"))
예제 #6
0
def main():
    import sys
    if len(sys.argv) == 1:
        print('Usage: app.py -list \n -find <name> \n -delete <name>')
        sys.exit(1)
    else:
        arguments = sys.argv[1:]
        print("Args: ", arguments)
        contacts = create_from_file()
        phonebook = Phonebook(contacts)
    if (arguments[0] == '-list'):
        phonebook.list()
    elif (arguments[0] == '-find'):
        phonebook.search_name(arguments[1])
    elif (arguments[0] == '-remove'):
        phonebook.remove_contact(arguments[1])
    else:
        print('Usage: app.py -list \n -find <name> \n -delete <name>')
        sys.exit(1)

    #no-args
    # contacts = create_from_file()
    # phonebook = Phonebook(contacts)
    # phonebook.list()
    # phonebook.search_name('jessica')
    # phonebook.remove_contact('jessica')
    # phonebook.search_name('Banjo')

    print('Done.')
예제 #7
0
def phonebook(request):
    phonebook = Phonebook()

    def cleanup_phonebook():
        phonebook.clear()

    request.addfinalizer(cleanup_phonebook)
    return phonebook
예제 #8
0
def phonebook(tmpdir):
    "Provide an empty phone book"
    phonebook = Phonebook()

    def cleanup_phonebook():
        phonebook.clear()

    request.addfinalizer(cleanup_phonebook)
    return phonebook
예제 #9
0
 def __init__(self, port = 8080):
 
     self.testargs = " ".join(sys.argv[1:])
     self.publickey, self.privatekey = rsa.newkeys(512)
     self.host = ''   # <-- works on all available network interfaces
     self.port = port
     self.chain = blockchain.Blockchain()
     self.phonebook = Phonebook()
     self.uid = uuid.uuid1()
예제 #10
0
    def test_mock_up_thing(self):
        thing = Phonebook()

        #<MagicMock id='140115817358032'>
        thing.method = MagicMock(return_value=3)

        # It is going to return 3
        thing.method(3, 4, 5, key='value')
        thing.method.assert_called_with(3, 4, 5, key='value')
예제 #11
0
def main():
    phonebook = Phonebook()

    person1 = Contact("Maija", "Mehiläinen", "29392949", 1994)
    person2 = Contact("Matti", "Meikäläinen", "03846737", 1995)

    phonebook.AddContact(person1)
    phonebook.AddContact(person2)

    phonebook.PrintContacts()
    def run(self):

        # This block was moved from server file to try and make it handled here instead
        phonebook = Phonebook()  # called from the phonebook.py
        filename = "AddressBook.txt"
        while True:
            try:
                file = open(filename, "r")  # opens in read only
                contents = file.readlines()
                for line in contents:
                    information = line.split(
                        " "
                    )  # This splits each line of the text file by spaces
                    phonebook.add(information[0], information[1])
                break
            except ReferenceError:
                print("File not found.")
                filename = input(
                    "Please enter the name of the phonebook to be loaded: ")
        # End of test block

        # create string of phonebook to send to client on connection
        start_book = phonebook.__str__()
        encrypt(start_book)
        self.client.send(bytes(encrypt(start_book.encode()))
                         )  # encrypts start_book for delivery to client

        self.client.send(bytes("Welcome to the phone book application!", ))
        while True:
            message = decode(self.client.recv(BUFSIZE), )
            decrypt(message)  # decrypts incoming message
            if not message:
                print("Client disconnected")
                self.client.close()
                break
            else:
                request = message.split()
                command = request[0]
                if command == "FIND":
                    number = self.phonebook.get(request[1])
                    if not number:
                        reply = "Number not found."
                    else:
                        reply = "The number is " + number
                else:
                    self.phonebook.add(request[1], request[2])

                    # write it to the file:
                    filename = "AddressBook.txt"
                    phonebook_file = open(filename, "a")  # opens in read only
                    phonebook_file.write(request[1] + " " + request[2] + "\n")
                    phonebook_file.close()

                    reply = "Name and number added to phone book and file.\nPress Update to update the table."
                self.client.send(bytes(reply, ))
예제 #13
0
 def test_list_records(self):
     """Check for right output when record created and listed"""
     capturedOutput = io.StringIO()
     sys.stdout = capturedOutput
     phonebook = Phonebook()
     phonebook.add_record("John Mayer", 12345)
     phonebook.list_records()
     sys.stdout = sys.__stdout__
     self.assertEqual(
         capturedOutput.getvalue(),
         "\nPhonebook has following entries:\n'John Mayer' => 12345\n")
예제 #14
0
    def test_less_than_2_pounds_stop_publishing(self):
        mock_phys = Mock(PhysicalDimensions())
        """
		`mock_phys.weight = 1` if commented out
		yields this error from unittest: TypeError: '<' not supported between instances of 'Mock' and 'int'
		if real Phys defaults to weight=0, why not the mock?
		why can we set the field only after instantiation?
		"""
        mock_phys.weight = 1
        pb = Phonebook(dimensions=mock_phys)
        self.assertEqual('stop publishing', pb.keep_publishing())
예제 #15
0
def main():
    phone_book = Phonebook()
    phone_book.add_contact(
        Contact('Дмитрий',
                'Дюков',
                '+70000000000',
                email='*****@*****.**',
                telegram='@dukov',
                email2='*****@*****.**',
                facebook='DyukovDmitry'))
    phone_book.add_contact(
        Contact('Эмануил',
                'Виторган',
                '+70000000001',
                email='*****@*****.**',
                telegram='@emsvit'))
    phone_book.add_contact(
        Contact('Тюльпек',
                'Ганджубасов',
                '+70000000002',
                favorite=True,
                email='*****@*****.**',
                telegram='@gandzhubasov'))
    phone_book.add_contact(
        Contact('Курмультук',
                'Ильясов',
                '+70000000003',
                favorite=True,
                email='*****@*****.**',
                telegram='@mudeni'))
    phone_book.add_contact(
        Contact('Зугинтульба',
                'Иванова',
                '+70000000004',
                favorite=True,
                email='*****@*****.**',
                telegram='@eultubey'))

    print(
        '=====================================Печать всех ====================================================='
    )
    phone_book.print_contacts()
    print(
        '=====================================Удаление по номеру =============================================='
    )
    phone_book.delete_contact('+70000000000')
    print(
        '=====================================Показать избраных ==============================================='
    )
    phone_book.print_favorite()
    print(
        '=====================================Поиск по Имени и Фамилии ========================================'
    )
    phone_book.search_contact('Тюльпек', 'Ганджубасов')
예제 #16
0
def phonebook(tmpdir) -> Phonebook:
    """
    Provides an empty Phonebook object
    """
    # return Phonebook()

    # Use 'yield' and not 'return' so that we can run clear at the end of every test case
    # phonebook = Phonebook()
    # yield phonebook
    # phonebook.clear()

    # With the tmpdir built-in pytest fixture, you can revert to the return
    # You can run 'pytest --fixtures' to get a list of the pytest fixtures
    # and their docstrings
    return Phonebook(tmpdir)
예제 #17
0
 def setUp(self):
     self.contacts = dict()
     self.info0 = dict(name='ZuZu',
                       number='123',
                       address='1 Main',
                       note='hi')
     self.info1 = dict(name='Daisy',
                       number='456',
                       address='1 Dog',
                       note='bye')
     self.test_contact0 = Contact(**self.info0)
     self.test_contact1 = Contact(**self.info1)
     self.contacts[self.test_contact0.get_variable(
         'name')] = self.test_contact0
     self.contacts[self.test_contact1.get_variable(
         'name')] = self.test_contact1
     self.test_phonebook = Phonebook(self.contacts)
예제 #18
0
 def setUp(self):
     self.phonebook = Phonebook()
     self.contact = self.phonebook.add_contact("Redlion", "0715846586")
예제 #19
0
def phonebook(tmpdir):
    "Provides an empty Phonebook"
    phonebook = Phonebook(tmpdir)
    return phonebook
예제 #20
0
def phonebook(tmpdir):
    "Provised an empty Phonebook"
    return Phonebook(tmpdir)
def phonebook(tmpdir):
    phonebook=Phonebook(tmpdir)
    return phonebook
예제 #22
0
 def test_lookup_entry_by_name(self):
     phonebook = Phonebook()
     phonebook.add('Bob', '12345')
     self.assertEqual("12345", phonebook.lookup("Bob"))
예제 #23
0
 def test_missing_entry_raises_KeyError(self):
     self.phonebook = Phonebook()
     with self.assertRaises(KeyError):
         self.phonebook.lookup("missing")
예제 #24
0
 def test_raise_value_error(self):
     phonebook = Phonebook()
     self.assertRaises(TypeError, phonebook.add_record(123, 123))
예제 #25
0
 def test_delete_record(self):
     """Check record deleted from phonebook"""
     phonebook = Phonebook()
     phonebook.add_record("John Mayer", 12345)
     phonebook.delete_record("John Mayer")
     self.assertNotIn("John Mayer", Phonebook.phonebook.keys())
예제 #26
0
 def setUp(self):
     phonebook = Phonebook()
     self.contact1 = phonebook.add_contact
예제 #27
0
 def test_create_phonebook(self):
    phonebook = Phonebook()
예제 #28
0
def phonebook():
    return Phonebook()
예제 #29
0
 def setUp(self):
     self.phonebook = Phonebook()
예제 #30
0
def phonebook(tmpdir):
    """
    Provides an empty Phonebook within a temp directory
    """
    return Phonebook(tmpdir)