Ejemplo n.º 1
0
        def setUp(self):

            self.gateway = None
            self.db = None

            self.mapper = ClassMapper([Cat, Dog])

            self.start_gateway()
Ejemplo n.º 2
0
 def __init__(self):
     mapper = ClassMapper([User, Call, Event])
     self.db = CouchDBWrapper(
       mapper,
       'https://*****:*****@couchbk.stag.sensitve.app/',
       'sensitive'
     )
Ejemplo n.º 3
0
 def setUp(self):
     self.mapper = ClassMapper([Dog, Cat, Person])
     self.db = CouchDBWrapper(self.mapper,
                              COUCHDB_URL,
                              COUCHDB_NAME,
                              reset=True)
     self.db.update_designs()
Ejemplo n.º 4
0
 def setUp(self):
     mapper = ClassMapper([Dog, Cat, Person, JackRussell])
     self.db = CouchbaseWrapper(mapper,
                                COUCHBASE_HOST,
                                COUCHBASE_BUCKET,
                                read_only=False)
     self.db.update_designs()
Ejemplo n.º 5
0
    def test_make_a_validator_from_modules(self):

        mapper = ClassMapper([], modules=[test01])
        validator = ModelValidator(mapper)
        self.db = CouchDBWrapper(mapper,
                                 COUCHDB_URL,
                                 COUCHDB_NAME,
                                 reset=True,
                                 validator=validator)
        self.db.update_designs()

        paul = Person(name="paul")
        paul.save(self.db)
        cat = Cat(name="whiskers", owner_id=paul.key, legs=4)
        cat.save(self.db)
        self.assertEqual(cat.owner, paul)
        self.assertEqual(cat.owner.name, "paul")

        #missing legs
        cat = Cat(name="puss", owner_id=paul.key)

        self.assertRaises(FamValidationError, cat.save, self.db)

        #additional properties
        def failing_cat():
            cat = Cat(name="puss", owner_id=paul.key, legs=2, collar="green")

        self.assertRaises(FamValidationError, failing_cat)
        dog = Dog(name="fly")
        self.db.put(dog)
        dog.tail = "long"
        self.db.put(dog)

        self.db.session.close()
Ejemplo n.º 6
0
    def test_make_a_validator(self):

        mapper = ClassMapper([Dog, Cat, Person, JackRussell])
        validator = ModelValidator(None,
                                   classes=[Dog, Cat, Person, JackRussell])
        self.db = CouchDBWrapper(mapper,
                                 COUCHDB_URL,
                                 COUCHDB_NAME,
                                 reset=True,
                                 validator=validator)
        self.db.update_designs()

        paul = Person(name="paul")
        paul.save(self.db)
        cat = Cat(name="whiskers", owner_id=paul.key, legs=4)
        cat.save(self.db)

        self.assertEqual(cat.owner, paul)
        self.assertEqual(cat.owner.name, "paul")

        cat = Cat(name="puss", owner_id=paul.key)

        self.assertRaises(FamValidationError, cat.save, self.db)

        self.db.session.close()
Ejemplo n.º 7
0
    def test_string_format(self):

        mapper = ClassMapper([], modules=[test01])
        validator = ModelValidator(mapper)
        self.db = CouchDBWrapper(mapper,
                                 COUCHDB_URL,
                                 COUCHDB_NAME,
                                 reset=True,
                                 validator=validator)
        self.db.update_designs()

        paul = Person(name="paul")
        paul.save(self.db)
        cat = Cat(name="whiskers", owner_id=paul.key, legs=4)
        cat.save(self.db)
        self.assertEqual(cat.owner, paul)
        self.assertEqual(cat.owner.name, "paul")

        cat = Cat(name="puss",
                  owner_id=paul.key,
                  legs=3,
                  email="*****@*****.**")
        cat.save(self.db)
        cat.email = "paulglowinthedark.co.uk"
        self.assertRaises(FamValidationError, self.db.put, cat)

        self.db.session.close()
Ejemplo n.º 8
0
    def _add_changes(self):

        from fam.tests.test_mutation.models.test02 import Dog, Cat, JackRussell, Person, Monkey
        self.mapper = ClassMapper([Dog, Cat, JackRussell, Person, Monkey])
        self.db.mapper = self.mapper
        self.mutator = FamMutator(self.mapper, DATA_PATH)
        self.mutator.db = self.db
Ejemplo n.º 9
0
    def setUp(self):

        mapper = ClassMapper([Dog, Cat, Person, JackRussell, Monkey])
        self.firestore = FirestoreWrapper(mapper, CREDS, namespace=NAMESPACE)
        self.couchdb = CouchDBWrapper(mapper,
                                      "http://localhost:5984",
                                      db_name="test",
                                      reset=True)
        self.couchdb.update_designs()
        self.clear_db()
Ejemplo n.º 10
0
    def setUp(self):

        if os.path.exists(SCHEMATA_DIR):
            shutil.rmtree(SCHEMATA_DIR)

        mapper = ClassMapper([Dog, Cat, JackRussell, Person, Monkey])
        self.mutator = FamMutator(mapper, DATA_PATH)
        self.db = FirestoreWrapper(mapper,
                                   CREDS,
                                   validator=self.mutator,
                                   namespace="http://glowinthedark.co.uk/test")

        if self.db.db.project != "orcast-test":
            raise Exception("wrong db: " % self.db.db.project)
Ejemplo n.º 11
0
    def setUp(self):
        cmd = "{} -log=* -url walrus: ".format(SYNC_GATEWAY_PATH)
        # print cmd

        time.sleep(0.25)
        self.gateway = subprocess.Popen(cmd, shell=True)
        time.sleep(0.25)
        filepath = os.path.join(DATA_PATH, "animal_views.js")
        mapper = ClassMapper(
            [Dog, Cat, Person, JackRussell, Monkey, Monarch, Monster],
            designs=[filepath])

        url = "http://%s:%s" % (SYNC_GATEWAY_ADMIN_HOST,
                                SYNC_GATEWAY_ADMIN_PORT)
        self.db = SyncGatewayWrapper(mapper, url, SYNC_GATEWAY_NAME)
        self.db.update_designs()
        super(self.__class__, self).setUp()
Ejemplo n.º 12
0
    def test_included_refs_from_in_validator(self):
        mapper = ClassMapper([], modules=[test01])
        validator = ModelValidator(mapper)
        self.db = CouchDBWrapper(mapper,
                                 COUCHDB_URL,
                                 COUCHDB_NAME,
                                 reset=True,
                                 validator=validator)
        self.db.update_designs()

        paul = Person(name="paul")
        paul.save(self.db)

        paul_id = paul.key
        cat = Cat(name="whiskers", owner_id=paul.key, legs=4)
        cat.save(self.db)
        self.assertEqual(cat.owner, paul)
        self.assertEqual(cat.owner.name, "paul")

        paul = Person.get(self.db, paul_id)

        paul.save(self.db)

        self.db.session.close()
Ejemplo n.º 13
0
    def setUpClass(cls):

        mapper = ClassMapper([House, Fence])
        cls.db = FirestoreWrapper(mapper, None, namespace=NAMESPACE)
        if cls.db.db.project != "localtest":
            raise Exception("wrong db: %s" % cls.db.db.project)
Ejemplo n.º 14
0
 def setUpClass(cls):
     mapper = ClassMapper([Fish])
     cls.db = FirestoreWrapper(mapper, None, namespace=fish_namespace)
     if cls.db.db.project != "localtest":
         raise Exception("wrong db: %s" % cls.db.db.project)
Ejemplo n.º 15
0
 def setUpClass(cls):
     mapper = ClassMapper([Dog, Cat, Person, JackRussell, Monkey, Monarch])
     cls.db = FirestoreWrapper(mapper, None, namespace=NAMESPACE)
     if cls.db.db.project != "localtest":
         raise Exception("wrong db: %s" % cls.db.db.project)
Ejemplo n.º 16
0
 def setUp(self):
     mapper = ClassMapper([Dog, Cat, Person, JackRussell, Monkey, Monarch])
     self.db = MockDatabase(mapper)
Ejemplo n.º 17
0
class testPermissions(unittest.TestCase):

        def setUp(self):

            self.gateway = None
            self.db = None

            self.mapper = ClassMapper([Cat, Dog])

            self.start_gateway()



        def start_gateway(self):

            cmd = "{} -log=* -url walrus: ".format(SYNC_GATEWAY_PATH)
            # print cmd

            time.sleep(0.25)
            self.gateway = subprocess.Popen(cmd, shell=True)
            time.sleep(0.25)

            admin_url = "http://%s:%s" % (SYNC_GATEWAY_ADMIN_HOST, SYNC_GATEWAY_ADMIN_PORT)
            self.admin_db = SyncGatewayWrapper(self.mapper, admin_url, SYNC_GATEWAY_NAME)
            self.admin_db.update_designs()
            self.add_users()


        def add_users(self):

            admin_url = "http://%s:%s" % (SYNC_GATEWAY_ADMIN_HOST, SYNC_GATEWAY_ADMIN_PORT)

            couchbase_utils.add_person_to_gateway(admin_url,
                                                  SYNC_GATEWAY_NAME,
                                                  "paul_id",
                                                  "paul",
                                                  "password1",
                                                  admin_channels=["cars", "paul"])

            couchbase_utils.add_person_to_gateway(admin_url,
                                                  SYNC_GATEWAY_NAME,
                                                  "sol_id",
                                                  "sol",
                                                  "password2",
                                                  admin_channels=["sol"])

            paul_url = "http://*****:*****@%s:%s" % (SYNC_GATEWAY_HOST, SYNC_GATEWAY_PORT)
            self.paul_db = SyncGatewayWrapper(self.mapper, paul_url, SYNC_GATEWAY_NAME)

            sol_url = "http://*****:*****@%s:%s" % (SYNC_GATEWAY_HOST, SYNC_GATEWAY_PORT)
            self.sol_db = SyncGatewayWrapper(self.mapper, sol_url, SYNC_GATEWAY_NAME)


        def tearDown(self):
            # stop the gateway
            if self.gateway is not None:
                self.gateway.kill()


        def test_ensure_designs(self):

            for namespace_name, namespace in self.admin_db.mapper.namespaces.items():
                view_namespace = namespace_name.replace("/", "_")
                key = "_design/%s" % view_namespace
                doc = self.mapper.get_design(namespace, namespace_name, self.admin_db.FOREIGN_KEY_MAP_STRING)
                doc["_id"] = key
                existing = self.admin_db.get_design(key)
                matches = self.admin_db._new_matches_existing(doc, existing)
                self.assertTrue(matches)

            # Add another class
            self.admin_db.mapper._add_classes([Person])

            for namespace_name, namespace in self.admin_db.mapper.namespaces.items():
                view_namespace = namespace_name.replace("/", "_")
                key = "_design/%s" % view_namespace
                doc = self.mapper.get_design(namespace, namespace_name, self.admin_db.FOREIGN_KEY_MAP_STRING)
                doc["_id"] = key
                existing = self.admin_db.get_design(key)
                matches = self.admin_db._new_matches_existing(doc, existing)

                self.assertFalse(matches)
Ejemplo n.º 18
0
 def setUp(self):
     filepath = os.path.join(THIS_DIR, "animal_views.js")
     mapper = ClassMapper([Dog, Cat, Person, JackRussell], designs=[filepath])
     self.db = CouchDBWrapper(mapper, COUCHDB_URL, COUCHDB_NAME, reset=True)
     self.db.update_designs()
Ejemplo n.º 19
0
 def setUp(self):
     self.mapper = ClassMapper([Dog, Cat, Person, JackRussell, Monarch])
Ejemplo n.º 20
0
 def setUp(self):
     mapper = ClassMapper([Dog, Cat])
     self.db = CouchbaseWrapper(mapper,
                                COUCHBASE_HOST,
                                COUCHBASE_BUCKET,
                                read_only=False)
Ejemplo n.º 21
0
 def setUp(self):
     mapper = ClassMapper([Fish])
     self.db = CouchDBWrapper(mapper, COUCHDB_URL, COUCHDB_NAME, reset=True)
     self.db.update_designs()
Ejemplo n.º 22
0
from fam.mapper import ClassMapper
from fam.database import CouchDBWrapper

from class_app import Call
from class_app import User

mapper = ClassMapper([User, Call])
db = CouchDBWrapper(mapper, 'http://127.0.0.1:5984/', 'sensitive')


def get_code(code):
    return db.get(code)


def create_user(user):
    return db.get(code)
Ejemplo n.º 23
0
    def setUp(self):

        self.gateway = None
        self.db = None

        self.mapper = ClassMapper([Car, Boat])