def test_index_contents(): "Test the index page contents" expected_message = "This is the endpoint for the home page. /message \ and /reminder are more useful starting points." message = main.index() assert message.get('msg', '') == expected_message
def convert(directory=PATH): for logLevel in LOGLEVELS: indexes = main.listLogIndexes(logLevel, directory) if len(indexes) > 0: lowestIndex, highestIndex = indexes[0], indexes[-1] for fileName, filePath in main.listLogArchives(logLevel, directory): if ".gz" not in fileName: # open the original file with open(filePath, "rb+") as unzippedFile: newIndex = highestIndex + lowestIndex - main.index( filePath) zippedFileName = "{0}.log.{1}.gz".format( logLevel, newIndex) zippedFilePath = os.path.join(directory, zippedFileName) with gzip.open(zippedFilePath, "wb") as zippedFile: unzippedRaw = unzippedFile.read() zippedFile.write(unzippedRaw) # delete the original file os.remove(filePath)
def index(): # all the available services data = main.index() if request.method == "GET": return jsonify(data) else: return data
def addZippedFile(self, filePath): self.zippedFiles.append({ "path": filePath, "size": main.size(filePath), "index": main.index(filePath) }) self.totalZippedSize += main.size( filePath) # add the size to the total size of zipped logs self.zippedFiles.sort(key=lambda x: x["index"]) # sort list by index
def start(): main.index() return redirect('http://localhost:5000/')
def test_index(): from main import index assert index()
def index(): db_conn = get_db() data = main.index(db_conn) return flask.render_template('table.html', data=data)
def unzip(source_filename, dest_dir): print('unzip ban file %s' % source_filename) if not os.path.exists(dest_dir): os.mkdir(dest_dir) with zipfile.ZipFile(source_filename) as zf: for member in zf.infolist(): # Path traversal defense copied from # http://hg.python.org/cpython/file/tip/Lib/http/server.py#l789 words = member.filename.split('/') path = dest_dir for word in words[:-1]: while True: drive, word = os.path.splitdrive(word) head, word = os.path.split(word) if not drive: break if word in (os.curdir, os.pardir, ''): continue path = os.path.join(path, word) zf.extract(member, path) if __name__ == '__main__': if len(sys.argv) > 1: url = sys.argv[1] get_ban_file(url) unzip(BAN_FILE_PATH, 'data/ban/') main.index() print("DONE")
def test_index(self): self.assertEqual(index(), 'it\'s alive')
def test_index(self): """Index returns greetind as data dict""" self.assertEqual({"greeting": "Hello, World!"}, index())
def test_main(): result = main.index() assert result['version'] is not None
def test_return_content_successfull(self): self.assertTrue( index('', '')['statusCode'] is 200 and "Hello World 1!" in index('', '')['body'])
def index_temp(): tech_data = main.index() #print(tech_data) return render_template("index.html", data=tech_data)
def test_1(): array = [1, 2, 3, 4] N = 2 assert index(array, N) == 9
def test_2(): array = [1, 2, 3] N = 3 assert index(array, N) == -1
def test_no_http_request(capsys): main.index() out, _ = capsys.readouterr() print(out) assert "trace" not in out
os.path.join(OUTPUT_DIRECTORY, "content", dir, name)) ]) == 0: os.rmdir(os.path.join(OUTPUT_DIRECTORY, "content", dir)) # Copy resources shutil.copytree("resources", os.path.join(OUTPUT_DIRECTORY, "resources")) shutil.copy("resources/favicon.ico", os.path.join(OUTPUT_DIRECTORY, "favicon.ico")) os.unlink(os.path.join(OUTPUT_DIRECTORY, "resources", "favicon.ico")) # Copy index page with open(os.path.join(OUTPUT_DIRECTORY, "index.html"), "w") as f: f.write(main.index()) # Iter CTFs writeups = main.load_writeups() for ctf in writeups: os.makedirs(os.path.join(OUTPUT_DIRECTORY, ctf)) # Copy CTF pages with open(os.path.join(OUTPUT_DIRECTORY, ctf, "index.html"), "w") as f: f.write(main.ctf(ctf)) # Iter writeups
def main(path="/"): return index(request)