Exemple #1
0
def main():
    #when there is a system argument, and the argument is -f go to Filter Menu,
    #if the arugment is -a then go to Analyzer menu
    if len(sys.argv) >= 2:
        if sys.argv[1] == '-f':
            Filter(sys.argv[2], sys.argv[3])
        elif sys.argv[1] == '-a':
            Analyzer()
        else:
            print "Invalid arguments, SYSTEM TERMINATED!"
            sys.exit()
    #if no default argument, then show the menu
    #the menu is conducted in infinite loop,
    #user can either close it or input valid data to proceed
    while True:
        #show the label of the menu, in this case Main Menu
        print "##########################################"
        print "##\t\tMain Menu\t\t##"
        print "##########################################"
        #show the option of the menu
        print "1. Filter Menu"
        print "2. Analyzer Menu"
        print "0. Exit"
        #require input from user to select option
        option = raw_input("Option: ")
        if option == '1':
            fil()  #go to Filter menu if selected 1
        elif option == '2':
            alert()  #go to Analyzer menu if selected 2
        elif option == '0':
            sys.exit()  #terminated the program when user input 0
        else:
            #any other input consider as wrong input, ask user to re-input
            print "Wrong input, please try again."
 def test_filter_not_equal(self):
     from core.Filter import Filter
     from core.Status import Status
     my_filter = Filter.from_dict({'operator': 'NOT EQUAL', 'field': 'Status._status', 'value': 'SUCCESS'})
     assert my_filter != False
     s1 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'FAILURE', details={})
     s2 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'SUCCESS', details={})
     assert my_filter.check_status(s1) == True
     assert my_filter.check_status(s2) == False
     status_filter = my_filter.check_statuses([s1, s2])
     assert len(status_filter) == 1
     assert status_filter[0]._test_id == s1._test_id
 def test_filter_details(self):
     from core.Filter import Filter
     from core.Status import Status
     my_filter = Filter.from_dict({'operator': 'EQUAL', 'field': 'Status._details[\'BROWSER\']', 'value': 'Firefox'})
     assert my_filter != False
     s1 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'FAILURE', details={'BROWSER': 'Firefox'})
     s1._on = datetime.datetime.now() - datetime.timedelta(seconds=5)
     s2 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'SUCCESS', details={'BROWSER': 'Chrome'})
     s2._on = datetime.datetime.now() + datetime.timedelta(seconds=5)
     assert my_filter.check_status(s1) == True
     assert my_filter.check_status(s2) == False
     status_filter = my_filter.check_statuses([s1, s2])
     assert len(status_filter) == 1
     assert status_filter[0]._test_id == s1._test_id
 def test_filter_greater_than(self):
     from core.Filter import Filter
     from core.Status import Status
     my_filter = Filter.from_dict({'operator': 'GREATER THAN', 'field': 'Status._on', 'value': 'datetime.datetime.now() + datetime.timedelta(days=1)'})
     assert my_filter != False
     s1 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'FAILURE', details={})
     s1._on = datetime.datetime.now() - datetime.timedelta(seconds=5)
     s2 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'SUCCESS', details={})
     s2._on = datetime.datetime.now() + datetime.timedelta(days=1, seconds=5)
     assert my_filter.check_status(s1) == False
     assert my_filter.check_status(s2) == True
     status_filter = my_filter.check_statuses([s1, s2])
     assert len(status_filter) == 1
     assert status_filter[0]._test_id == s2._test_id
 def test_filter_or(self):
     from core.Filter import Filter
     from core.Status import Status
     my_filter = Filter.from_dict({'operator': 'OR',
                                   'part1': {'operator': 'EQUAL', 'field': 'Status._status', 'value': 'SUCCESS'},
                                   'part2': {'operator': 'EQUAL', 'field': 'Status._last', 'value': 'True'}})
     assert my_filter != False
     s1 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'FAILURE', details={})
     s2 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'SUCCESS', details={}, last=True)
     s3 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'SUCCESS', details={})
     s4 = Status(str(uuid.uuid4()), str(uuid.uuid4()), 'FAILURE', details={}, last=True)
     assert my_filter.check_status(s1) == False
     assert my_filter.check_status(s2) == True
     assert my_filter.check_status(s3) == True
     assert my_filter.check_status(s4) == True
     status_filter = my_filter.check_statuses([s1, s2, s3, s4])
     assert len(status_filter) == 3
     assert sorted([sf._test_id for sf in status_filter]) == sorted([s2._test_id, s3._test_id, s4._test_id])
Exemple #6
0
def fil():
    menu = True  #temporary turn on the menu
    while menu:
        #for formating purpose only
        print "##################################"
        print "##\t\tFilter\t\t##"
        print "##################################"
        #show menu option
        print "1. Show Filter Policy"
        print "2. Add Filter Policy"
        print "3. Edit Filter Policy"
        print "4. Delete Filter Policy"
        print "5. Run Filter"
        print "9. Back to Main Menu"
        print "0. Exit"

        option = raw_input("Option: ")  #get input to choose option
        if option == '1':
            show()  #display all Filter policy information
        elif option == '2':
            add()  #add new Filter policy
        elif option == '3':
            edit()  #edit current Filter policy
        elif option == '4':
            delete()  #delete Filter policy
        elif option == '5':
            fr = raw_input("From port: ")
            to = raw_input("To port: ")
            Filter(fr, to)  #call Filter to filter the normal data of port file
            menu = False
        elif option == '9':
            menu = False  #set Menu to False, so it will back to Main()
        elif option == '0':
            sys.exit()  #terminated program
        else:
            print "Wrong input, please try again."
 def test_from_dict_errors(self):
     from core.Filter import Filter
     assert Filter.from_dict(str(uuid.uuid4())) == False
     assert Filter.from_dict({str(uuid.uuid4()): str(uuid.uuid4())}) == False
     assert Filter.from_dict({'operator': str(uuid.uuid4()), 'part1': 1, 'part2': 2}) == False