Beispiel #1
0
  async def testNotSaved(self):
    data = {"name": "Test delete not saved"}
    model = models.MinimalMongo(self.table)
    model.load(data)

    with self.assertRaises(AttributeError):
      await model.delete()
Beispiel #2
0
  async def testNoTable(self):
    data = {"_id": bson.ObjectId(), "name": "Test delete no table"}
    model = models.MinimalMongo()
    model.load(data)

    with self.assertRaises(InvalidOperation):
      await model.delete()
Beispiel #3
0
 def test(self):
   model = models.MinimalMongo()
   data = {"_id": Decimal(10), "name": "This should produce a deserialization error"}
   model.load(data)
   errors = model.get_errors()
   self.assertNotIn("_id", model.get_data())
   self.assertIn("_id", errors)
   self.assertEqual('invalid ObjectId `10`', errors["_id"][0])
Beispiel #4
0
  async def test(self):
    data = {"name": "Test get"}
    result = await self.table.insert_one(data)
    data["_id"] = result.inserted_id

    model = models.MinimalMongo(self.table)
    await model.get(name = data["name"])

    modeldata = model.get_data()
    self.assertEqual(sorted(data.items()), sorted(modeldata.items()))

    self.table.delete_one({"_id": modeldata["_id"]})
Beispiel #5
0
  async def test(self):
    model = models.MinimalMongo(self.table)
    data = {"name": "Test create"}
    model.load(data)
    await model.create()
    saved = await self.table.find_one(data)
    model_data = model.get_data()

    self.assertDictEqual(model_data, saved)
    self.assertIn("_id", model_data.keys())

    self.table.delete_one({"_id": model_data["_id"]})
Beispiel #6
0
  async def test(self):
    data = {"name": "Test delete"}
    result = await self.table.insert_one(data)
    data["_id"] = result.inserted_id

    model = models.MinimalMongo(self.table)
    await model.get(_id = data["_id"])
    await model.delete()

    check_if_exists = await self.table.find_one({"_id": data["_id"]})

    self.assertIsNone(check_if_exists)
Beispiel #7
0
  async def testValidationError(self):
    data = {"name": "Test update validation error"}
    result = await self.table.insert_one(data)
    data["_id"] = result.inserted_id

    model = models.MinimalMongo(self.table)
    await model.get(name = data["name"])

    with self.assertRaises(ValidationError):
      await model.update({"name": 25})

    await self.table.delete_one({"_id": data["_id"]})
Beispiel #8
0
  async def testActualData(self):
    data = {"name": "Test update actual data"}
    result = await self.table.insert_one(data)
    data["_id"] = result.inserted_id

    model = models.MinimalMongo(self.table)
    await model.get(name = data["name"])
    new_name = "Test update actual data edited"
    model.__data__["name"] = new_name
    await model.update()

    new_data = await self.table.find_one({"_id": model.get_data()["_id"]})

    self.assertEqual(new_data["name"], new_name)

    await self.table.delete_one({"_id": data["_id"]})
Beispiel #9
0
 async def testNoData(self):
   model = models.MinimalMongo(self.table)
   with self.assertRaises(NotFound):
     await model.get(name = "A name that doesn't exists")
Beispiel #10
0
 async def testNoTable(self):
   model = models.MinimalMongo()
   data = {"name": "Test get no table"}
   model.load(data)
   with self.assertRaises(InvalidOperation):
     await model.get(name = data["name"])
Beispiel #11
0
 async def testNoData(self):
   model = models.MinimalMongo(self.table)
   with self.assertRaises(InvalidOperation):
     await model.create()
Beispiel #12
0
  async def testNotSaved(self):
    model = models.MinimalMongo(self.table)
    model.load({"name": "Test update not saved"})

    with self.assertRaises(InvalidOperation):
      await model.update({"name": "Test update not saved updated"})
Beispiel #13
0
  async def testNoTable(self):
    model = models.MinimalMongo()
    model.load({"_id": bson.ObjectId(), "name": "Test update no table"})

    with self.assertRaises(InvalidOperation):
      await model.update({"name": "Test update no table updated"})