예제 #1
0
class ServerTest(AsyncHTTPTestCase):
    def setUp(self):
        self.db = RiakDb()
        self.db.create_user(TEST_EMAIL, "test name", "testpass", "New York")
        super().setUp()

    def tearDown(self):
        self.db.delete_user(TEST_EMAIL)
        super().tearDown()

    def get_app(self):
        return serve2.Application(self.db)
예제 #2
0
class TestDbPolygonTypes(unittest.TestCase):
    def setUp(self):
        self.db = RiakDb()
        self.db.create_poly_type("Test", False, None, ["child1", "child2"])

    def tearDown(self):
        self.db.delete_polygon("Test")
        self.db.delete_user(U_EMAIL)

    def test_get_poly_type(self):
        self.assertEqual(
            self.db.get_poly_type("Test")['children'][0], "child1")

    # TODO: test_get_deleted_poly_type

    def test_delete_poly_type(self):
        self.db.delete_poly_type("Test")
        self.assertIsNone(self.db.get_poly_type("Test"))
예제 #3
0
class TestDbUsers(unittest.TestCase):
    def setUp(self):
        self.db = RiakDb()
        self.db.create_user(U_EMAIL, U_NAME, U_PASS, U_ADDR)

    def tearDown(self):
        self.db.delete_user(U_EMAIL)

    def test_get_user(self):
        self.assertEqual(self.db.get_user(U_EMAIL)['name'], U_NAME)

    def test_check_correct_password(self):
        self.assertTrue(self.db.login(U_EMAIL, U_PASS))

    def test_check_incorrect_password(self):
        self.assertFalse(self.db.login(U_EMAIL, "bad"))

    def test_delete_user(self):
        self.db.delete_user(U_EMAIL)
        self.assertIsNone(self.db.get_user(U_EMAIL))
예제 #4
0
class TestDbPolygonHarvest(unittest.TestCase):
    def setUp(self):
        self.db = RiakDb()
        harvest = self.db.create_harvest(1, str(date.today()), 5, "bushels")
        self.harvest_id = harvest['id']

    def tearDown(self):
        self.db.delete_harvest(self.harvest_id)
        self.db.delete_user(U_EMAIL)

    def test_get_own_harvest(self):
        units = self.db.get_harvest(self.harvest_id)['units']
        self.assertEqual(units, "bushels")

    def test_delete_task(self):
        self.db.delete_harvest(self.harvest_id)
        self.assertIsNone(self.db.get_harvest(self.harvest_id))
예제 #5
0
class TestDbPolygonNotes(unittest.TestCase):
    def setUp(self):
        self.db = RiakDb()
        note = self.db.create_note(1, str(date.today()), "NoteTitle",
                                   "NoteContent")
        self.note_id = note['id']

    def tearDown(self):
        self.db.delete_note(self.note_id)
        self.db.delete_user(U_EMAIL)

    def test_get_note(self):
        title = self.db.get_note(self.note_id)['title']
        self.assertEqual(title, "NoteTitle")

    def test_delete_note(self):
        self.db.delete_note(self.note_id)
        self.assertIsNone(self.db.get_note(self.note_id))
예제 #6
0
class TestDbPolygonTasks(unittest.TestCase):
    def setUp(self):
        self.db = RiakDb()
        task = self.db.create_task(1, "water tomatoes", str(date.today()), 1,
                                   False, "water the tomatoes")
        self.task_id = task['id']

    def tearDown(self):
        self.db.delete_user(U_EMAIL)
        self.db.delete_task(self.task_id)

    def test_get_own_task(self):
        name = self.db.get_task(self.task_id)['name']
        self.assertEqual(name, "water tomatoes")

    def test_delete_task(self):
        self.db.delete_task(self.task_id)
        self.assertIsNone(self.db.get_task(self.task_id))
예제 #7
0
 def setUp(self):
     self.db = RiakDb()
     self.db.create_poly_type("Test", False, None, ["child1", "child2"])
예제 #8
0
 def setUp(self):
     self.db = RiakDb()
     self.db.create_user(U_EMAIL, U_NAME, U_PASS, U_ADDR)
     p = self.db.create_polygon("Nevada", "Area 51", U_EMAIL, date.today(),
                                None, ['type1', 'typeB'])
     self.poly_id = p['id']
예제 #9
0
class TestDbPolygons(unittest.TestCase):
    def setUp(self):
        self.db = RiakDb()
        self.db.create_user(U_EMAIL, U_NAME, U_PASS, U_ADDR)
        p = self.db.create_polygon("Nevada", "Area 51", U_EMAIL, date.today(),
                                   None, ['type1', 'typeB'])
        self.poly_id = p['id']

    def tearDown(self):
        self.db.delete_polygon(self.poly_id)
        self.db.delete_user(U_EMAIL)

    def test_get_own_polygon(self):
        poly = self.db.get_polygon(self.poly_id, U_EMAIL)
        self.assertEqual(poly['name'], "Area 51")
        self.assertEqual(poly['type'], ['type1', 'typeB'])

    def test_polygon_start_date_as_datetime(self):
        dt = self.db.get_polygon(self.poly_id, U_EMAIL)['start_date']
        self.assertEqual(dt, date.today())

    def test_get_other_polygon(self):
        self.assertIsNone(self.db.get_polygon(self.poly_id, "wrong_user"))

    def test_delete_polygon(self):
        self.db.delete_polygon(self.poly_id)
        self.assertIsNone(self.db.get_polygon(self.poly_id, U_EMAIL))
예제 #10
0
 def setUp(self):
     self.db = RiakDb()
     harvest = self.db.create_harvest(1, str(date.today()), 5, "bushels")
     self.harvest_id = harvest['id']
예제 #11
0
from storage.riak import RiakDb


def clear_bucket(bucket):
    keys = bucket.get_keys()
    for k in keys:
        obj = bucket.get(k)
        obj.delete()


db = RiakDb()
clear_bucket(db.user_bucket)
clear_bucket(db.poly_bucket)
clear_bucket(db.task_bucket)
clear_bucket(db.harvest_bucket)
clear_bucket(db.note_bucket)
clear_bucket(db.poly_type_bucket)

ptypes = {
    "root": {
        "name": "root",
        "is_container": False,
        "harvest": None,
        "children": []
    }
}
with open("poly_types.csv") as types_db:
    for line in types_db:
        data = [f.strip() for f in line.split(",")]
        parent = data[0]
        if not parent or parent == "parent":
예제 #12
0
 def setUp(self):
     self.db = RiakDb()
     note = self.db.create_note(1, str(date.today()), "NoteTitle",
                                "NoteContent")
     self.note_id = note['id']
예제 #13
0
파일: serve2.py 프로젝트: 3mi1y/RLand
            (r"/api/polygon_type_tree", PolyTypeTreeHandler),
            (r"/api/polygon_types", PolyTypeCollectionHandler),
            (r"/api/polygon_types/(.*)", PolyTypeHandler),
            (r"/(favicon.ico)", tornado.web.StaticFileHandler, {
                "path": os.path.join(os.path.dirname(__file__), "static")
            }),
            (r"/(assets/.*|ember-welcome-page/.*|fonts/.*|tests/.*|index.html|robots.txt|testem.js)",
             tornado.web.StaticFileHandler,
             dict(path=os.path.join(os.path.dirname(__file__),
                                    "../ember-proj/dist/"))),
            (r"/.*", MainHandler),
        ]
        settings = dict(
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            login_url="/login",
            # TODO: change the cookie secret for production
            cookie_secret=
            b'\xaf\x07\xee0]DN\xe1R\xac\xd3\xe6\xcbO\xa5\xd7oo\xf9)\xef\xad\xc4L\xbf\xe9\x1c\x93\xfa\xd5\x90\xb9',
            db=database,
        )
        super(Application, self).__init__(handlers, **settings)


if __name__ == "__main__":
    tornado.options.parse_command_line()
    db = RiakDb()
    http_server = tornado.httpserver.HTTPServer(Application(db))
    http_server.listen(options.port)
    print("IM RUNNING ON PORT: " + str(options.port))
    tornado.ioloop.IOLoop.current().start()
예제 #14
0
 def setUp(self):
     self.db = RiakDb()
     self.db.create_user(TEST_EMAIL, "test name", "testpass", "New York")
     super().setUp()
예제 #15
0
 def setUp(self):
     self.db = RiakDb()
     self.db.create_user(U_EMAIL, U_NAME, U_PASS, U_ADDR)
예제 #16
0
 def setUp(self):
     self.db = RiakDb()
     task = self.db.create_task(1, "water tomatoes", str(date.today()), 1,
                                False, "water the tomatoes")
     self.task_id = task['id']
예제 #17
0
파일: reset_db.py 프로젝트: 3mi1y/RLand
from storage.riak import RiakDb


def clear_bucket(bucket):
    keys = bucket.get_keys()
    for k in keys:
        obj = bucket.get(k)
        obj.delete()


db = RiakDb()
clear_bucket(db.user_bucket)
clear_bucket(db.poly_bucket)
clear_bucket(db.task_bucket)
clear_bucket(db.harvest_bucket)
clear_bucket(db.note_bucket)
clear_bucket(db.poly_type_bucket)

ptypes = {"root": {"name": "root", "is_container": False, "harvest": None, "children": []}}
with open("poly_types.csv") as types_db:
    for line in types_db:
        data = [f.strip() for f in line.split(",")]
        parent = data[0]
        if not parent or parent == "parent":
            continue

        name = data[1]
        is_container = data[2] == "1"
        harvest = data[3] or None

        ptype = {"name": name, "is_container": is_container, "harvest": harvest, "children": []}