import string, cgi, time from os import curdir, sep from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from filestore import Filestore, EncryptedFile fileStore = Filestore() aNewFile = EncryptedFile("encryptedName", "encryptedCont") fileStore.addFile(aNewFile) class FileHandler(BaseHTTPRequestHandler): def __init__(self): super(FileHandler, self).__init__(self, request, client_address, server) self.fileSt ore = filestore.Filestore() def do_GET(self): try: global fileStore print fileStore.fileMap print "entering get." fileContents1 = "hahaha" # remove leading "/" encFile = fileStore.getFile(self.path[1:]) print "AAAAAAAAAA" print encFile self.send_response(200) self.send_header('title', "yay") self.end_headers() self.wfile.write(encFile.encryptedContents) return
def test_file_store(): fs1 = Filestore(FILE) fs1.put("col", "id_1", {'a': 1, 'b': 2}) fs2 = Filestore(FILE) assert fs2.get("col", "id_1") is not None
#!/usr/bin/python3 from flask import Flask from api.component_api import component_api from api.main_api import main_api from filestore import Filestore from machine import Machine from my_machine import setup setup(Machine) Machine.initialize(Filestore("/var/blinky/blinky.json")) app = Flask(__name__) app.register_blueprint(main_api) app.register_blueprint(component_api) if __name__ == "__main__": app.run(host='0.0.0.0', port=80)
def test_retrieve_none(): fs = Filestore(FILE) fs.put("col", "id_1", {'a': 1, 'b': 2}) assert fs.get("col", "id_2") is None assert fs.get("other_col", "id_1") is None
def test_retrieve(): fs = Filestore(FILE) fs.put("col", "id_1", {'a': 1, 'b': 2}) fs.put("col", "id_2", {'a': 3, 'b': 4}) assert fs.get("col", "id_1") is not None assert fs.get("col", "id_1")['a'] == 1
def test_put_creates_collection(): fs = Filestore(FILE) fs.put("col", "id_1", {'a': 1, 'b': 2}) assert fs.collection_names()[0] == 'col'
def test_empty_filestore_contains_no_collections(): fs = Filestore(FILE) assert len(fs.collection_names()) == 0
def test_empty_filestore_creation(): fs = Filestore(FILE) assert fs is not None