Ejemplo n.º 1
0
    def test_active_urls(self):
        # Setup
        records = [
            FileRecord('', 'GET /test/top4'),
            FileRecord('', 'GET /test/top5'),
            FileRecord('', 'GET /test/top1'),
            FileRecord('', 'GET /test/top1'),
            FileRecord('', 'GET /test/top1'),
            FileRecord('', 'GET /test/top1'),
            FileRecord('', 'GET /test/top2'),
            FileRecord('', 'GET /test/top2'),
            FileRecord('', 'GET /test/top2'),
            FileRecord('', 'GET /test/top3'),
            FileRecord('', 'GET /test/top3'),
            FileRecord('', 'GET /test/top3')
        ]

        file = File(records)

        # Call
        top = file.active_urls(3)

        # Assert
        self.assertEqual(top[0][0], 'GET /test/top1')
        self.assertEqual(top[1][0], 'GET /test/top2')
        self.assertEqual(top[2][0], 'GET /test/top3')
Ejemplo n.º 2
0
    def test_active_ips(self):
        # Setup
        records = [
            FileRecord('4.4.4.4', ''),
            FileRecord('5.5.5.5', ''),
            FileRecord('1.1.1.1', ''),
            FileRecord('1.1.1.1', ''),
            FileRecord('1.1.1.1', ''),
            FileRecord('1.1.1.1', ''),
            FileRecord('2.2.2.2', ''),
            FileRecord('2.2.2.2', ''),
            FileRecord('2.2.2.2', ''),
            FileRecord('3.3.3.3', ''),
            FileRecord('3.3.3.3', ''),
            FileRecord('3.3.3.3', ''),
        ]

        file = File(records)

        # Call
        top = file.active_ips(3)

        # Assert
        self.assertEqual(top[0][0], '1.1.1.1')
        self.assertEqual(top[1][0], '2.2.2.2')
        self.assertEqual(top[2][0], '3.3.3.3')
Ejemplo n.º 3
0
    def test_reader(self):
        f = File(self.valid_filename)

        with open(f.file_path, 'r') as file_handler:
            line_count = 0
            for line in File.reader(file_handler):
                self.assertIsInstance(line, File.Line)

                line_count += 1

            self.assertEqual(line_count, 3)
Ejemplo n.º 4
0
    def test_distinct_ips(self):
        # Setup
        records = [
            FileRecord('4.4.4.4', ''),
            FileRecord('5.5.5.5', ''),
            FileRecord('1.1.1.1', ''),
            FileRecord('1.1.1.1', ''),
            FileRecord('1.1.1.1', ''),
            FileRecord('1.1.1.1', ''),
            FileRecord('2.2.2.2', ''),
            FileRecord('2.2.2.2', ''),
            FileRecord('2.2.2.2', ''),
            FileRecord('3.3.3.3', ''),
            FileRecord('3.3.3.3', ''),
            FileRecord('3.3.3.3', ''),
        ]

        file = File(records)

        # Call
        distinct = file.distinct_ips()

        # Assert
        self.assertEqual(distinct, 5)
Ejemplo n.º 5
0
    def test_Bug(self):
        self.assertEqual(Bug(self.valid_filename).filename, self.valid_filename)

        for filename in self.invalid_filenames:
            self.assertRaises(TypeError, lambda: File(filename))
Ejemplo n.º 6
0
 def test_pattern(self):
     line = File.Line(self.valid_line_prop['id'], self.valid_line_prop['pattern'])
     self.assertEqual(line.pattern, self.valid_line_prop['pattern'])
Ejemplo n.º 7
0
 def test_Line(self):
     for line_prop in self.invalid_line_props:
         self.assertRaises(TypeError, lambda: File.Line(line_prop['id'], line_prop['pattern']))
Ejemplo n.º 8
0
    def test_file_path(self):
        f = File(self.non_existing_valid_filename)
        self.assertRaises(ValueError, lambda: f.file_path)

        f = File(self.valid_filename)
        self.assertEqual(f.file_path, '{folder}/{file}'.format(folder=DATA_FOLDER_PATH, file=self.valid_filename))
Ejemplo n.º 9
0
from main import encrypt, Lexer, Parser, File

answer = input("""
        Hey Pr0, What you wanna do(?)
        Press 1 for Encrypting text
        Press 2 for Decrypting text
        \n
        """)
if answer == "1":
    text = input("Tell me what you wanna encrypt: ")
    new_l = Lexer(encrypt(text))
    new_l.create_encrypted()
    new_l.create_schema()
    print(new_l.generate_files())
elif answer == "2":
    enc = input("Enter the exact path of the encrypted file: ")
    sch = input("Enter the exact path of the schema file: ")
    dec = Parser(File(enc).read(), File(sch).read())
    print("Here goes the decrypted string" + "\n" +
          "==========================HALO10=============================" +
          "\n" + dec.decrypt())
else:
    print("Simp.. that's an incorrect try")
Ejemplo n.º 10
0
def test_file_encode():
    text = Path("fixtures/get_file.json").read_text()
    data = json.loads(text)
    ev: File = File.fromJSON(data)
    ev.text = "my new file contents"
    assert ev.content == b"bXkgbmV3IGZpbGUgY29udGVudHM="
Ejemplo n.º 11
0
def test_file_decode():
    text = Path("fixtures/get_file.json").read_text()
    data = json.loads(text)
    ev: File = File.fromJSON(data)
    assert ev.text == "my updated file contents"