コード例 #1
0
    def testWriteReadFile(self):
        test_collect = Tests.__test_collect()

        test_collect.writeJsonFile('testReadWrite.json')

        collect = CC()
        collect.readJsonFile('testReadWrite.json')

        self.assertEqual(collect, test_collect)
コード例 #2
0
    def testAdd(self):
        collect = CC()
        arrSTR = [
            'newAddress', 'newCountry', 'newCity', '+380000000000',
            '+380000000000'
        ]
        arrINT = [11111]
        collect.addNewAddress(arrSTR, arrINT)

        newOBJ = CA('newAddress', 11111, 'newCountry', 'newCity',
                    '+380000000000', '+380000000000')

        self.assertEqual(collect[0], newOBJ)
コード例 #3
0
    def testSort(self):
        collect = CC()
        collect.readJsonFile('data.json')
        test_collect = copy.deepcopy(collect)

        for i in collect[0].getAttr():
            collect.sort(str(i))
            test_collect.bubbleSort(str(i))
            self.assertEqual(collect, test_collect)

        with self.assertRaises(AttributeError):
            collect.sort('attribute')
コード例 #4
0
    def testSearch(self):
        collect = CC()
        collect.readJsonFile('data.json')

        searchResult = []

        # search 'Brodway'
        searchResult = collect.search('Brodway')
        self.assertEqual(len(searchResult), 1)  # only 1...
        self.assertEqual(searchResult[0], collect[0])

        # search uk
        searchResult = collect.search('uk')
        self.assertEqual(searchResult[0], collect[1])
        self.assertEqual(searchResult[1], collect[2])
        self.assertEqual(searchResult[2], collect[3])

        # search 'None' ...
        with self.assertRaises(AttributeError):
            collect.search('None')
コード例 #5
0
    def __test_collect():
        address1 = CA("Brodway", 45348, "opit", "uirute", "+380979085267",
                      "+380939088267")
        address2 = CA("Kedrova", 22112, "UK", "London", "+380979488267",
                      "+380973088267")
        address3 = CA("address", 12345, "Ukraine", "Lviv", "+380972088267",
                      "+380975088267")
        address4 = CA("Addr", 54321, "Ukraine", "Kiev", "+380972088267",
                      "+380979088467")
        address5 = CA("lomsd", 98766, "vcbx", "sdfs", "+380979080267",
                      "+380979008267")
        address6 = CA("newAddress", 57564, "newCountry", "newCity",
                      "+380979088967", "+380979089267")

        test_collect = CC()
        test_collect.insert(address1)
        test_collect.insert(address2)
        test_collect.insert(address3)
        test_collect.insert(address4)
        test_collect.insert(address5)
        test_collect.insert(address6)

        return test_collect
コード例 #6
0
    def testDelete(self):
        address1 = CA("Brodway", 45348, "opit", "uirute", "+380979085267",
                      "+380939088267")
        address2 = CA("Kedrova", 22112, "UK", "London", "+380979488267",
                      "+380973088267")
        address4 = CA("Addr", 54321, "Ukraine", "Kiev", "+380972088267",
                      "+380979088467")
        address5 = CA("lomsd", 98766, "vcbx", "sdfs", "+380979080267",
                      "+380979008267")
        address6 = CA("newAddress", 57564, "newCountry", "newCity",
                      "+380979088967", "+380979089267")

        test_collect = CC()
        test_collect.insert(address1)
        test_collect.insert(address2)
        test_collect.insert(address4)
        test_collect.insert(address5)
        test_collect.insert(address6)

        collect = Tests.__test_collect()
        collect.deleteElem(2)

        self.assertEqual(collect, test_collect)
コード例 #7
0
def main2():
    optionChArr = [
        '1 - insert collection from file', '2 - print collection', '3 - sort',
        '4 - search', '5 - delete obj', '6 - add new obj', '7 - edit obj',
        '8 - exit'
    ]
    collect = CC()
    while True:
        try:
            choice = options(optionChArr)

            if choice == 1:
                arr = CC.readFile()
                collect.fromStrAddress(arr)

            elif choice == 2:
                print(collect)

            elif choice == 3:
                attr = v.enterStr('Enter attribute: ')
                collect.sort(attr)
                print(collect)
                collect.writeFile("output.txt", "r+")

            elif choice == 4:
                value = v.enterStr("Enter search elem - ")
                collect.search(value)

            elif choice == 5:
                index = v.intValidateInRange('enter index - ', 0, len(collect))
                collect.deleteElem(index)
                #CC.writeFile("output.txt", "r+")

            elif choice == 6:
                collect.addNewAddress()
                #CC.writeFile("output.txt", "r+")

            elif choice == 7:
                collect.editAddress()
                #CC.writeFile("output.txt", "r+")

            elif choice == 8:
                break

        except Exception as e:
            print('Error ', '--' * 20, '  ', e)
コード例 #8
0
    def testEdite(self):
        newOBJ = CA('newAddress', 11111, 'newCountry', 'newCity',
                    '+380000000000', '+380000000000')
        collect = CC()
        collect.insert(newOBJ)

        # address_line
        testOBJ = CA('editeAddress', 11111, 'newCountry', 'newCity',
                     '+380000000000', '+380000000000')
        collect.editAddress(0, 'address_line', 'editeAddress')
        self.assertEqual(collect[0], testOBJ)

        # postal_code
        testOBJ = CA('editeAddress', 22222, 'newCountry', 'newCity',
                     '+380000000000', '+380000000000')
        collect.editAddress(0, 'postal_code', 22222)
        self.assertEqual(collect[0], testOBJ)

        # country
        testOBJ = CA('editeAddress', 22222, 'editeCountry', 'newCity',
                     '+380000000000', '+380000000000')
        collect.editAddress(0, 'country', 'editeCountry')
        self.assertEqual(collect[0], testOBJ)

        # city
        testOBJ = CA('editeAddress', 22222, 'editeCountry', 'editeCity',
                     '+380000000000', '+380000000000')
        collect.editAddress(0, 'city', 'editeCity')
        self.assertEqual(collect[0], testOBJ)

        # fax_number
        testOBJ = CA('editeAddress', 22222, 'editeCountry', 'editeCity',
                     '+380111111111', '+380000000000')
        collect.editAddress(0, 'fax_number', '+380111111111')
        self.assertEqual(collect[0], testOBJ)

        # phone_number
        testOBJ = CA('editeAddress', 22222, 'editeCountry', 'editeCity',
                     '+380111111111', '+380111111111')
        collect.editAddress(0, 'phone_number', '+380111111111')
        self.assertEqual(collect[0], testOBJ)
コード例 #9
0
def main2():
    options = '1 - insert collection from file\n2 - print collection\n3 - sort\n4 - search\n5 - delete obj\n6 - add new obj\n7 - edit obj\n8 - exit\n'
    collect = CC()
    while True:
        try:
            print(options)
            choice = enterIntInRange(0, 'Enter choice : ', 0, 9)

            if choice == 1:
                arr = CC.readFile()
                collect.fromStrAddress(arr)

            elif choice == 2:
                print(collect)

            elif choice == 3:
                attr = enterStr('0', 'Enter attribute: ')
                collect.sort(attr)
                collect.writeFile("output.txt", "r+")

            elif choice == 4:
                value = enterStr('0', "Enter search elem - ")
                collect.search(value)

            elif choice == 5:
                index = enterIntInRange(0, 'Enter index : ', 0, len(collect))
                collect.deleteElem(index)
                collect.writeFile("output.txt", "r+")

            elif choice == 6:
                collect.addNewAddress()
                collect.writeFile("output.txt", "r+")

            elif choice == 7:
                collect.editAddress()
                collect.writeFile("output.txt", "r+")

            elif choice == 8:
                break

        except Exception as e:
            print('Error ', '--' * 20, '  ', e)