class UpdatedClientTest(BaseTest):
    def setUp(self):
        super(UpdatedClientTest, self).setUp()
        self.emanager = EntityManager(SimpleClient)

        self.client1 = BaseTestFactory.create_client_with_3_address()
        self.client2 = BaseTestFactory.create_client_with_3_address()
        self.client3 = BaseTestFactory.create_client_with_3_address()

    @gen_test
    def test_client2_was_successful_updated(self):
        yield self.emanager.remove_all()
        self.objectid_1 = yield self.emanager.save(self.client1)
        self.objectid_2 = yield self.emanager.save(self.client2)
        self.objectid_3 = yield self.emanager.save(self.client3)

        self.client_to_update = yield self.emanager.find_one(_id=self.objectid_2)
        self.client_to_update.name = "updated_name"
        self.client_to_update.last_name = "updated_last_name"

        yield self.emanager.update(self.client_to_update)

        self.updated_client = yield self.emanager.find_one(_id=self.objectid_2)

        self.return_client1 = yield self.emanager.find_one(_id=self.objectid_1)
        self.return_client3 = yield self.emanager.find_one(_id=self.objectid_3)

        # check if client2 was updated
        self.assertEqual(self.client_to_update.name, self.updated_client.name)
        self.assertEqual(self.client_to_update.last_name, self.updated_client.last_name)

        # check if nothing changed in client1 and client3
        self.assertTrue(compare_objs(self.client1, self.return_client1))
        self.assertTrue(compare_objs(self.client3, self.return_client3))
class StoreWithThreeClientsOnlyTest(BaseTest):
    def setUp(self):
        super(StoreWithThreeClientsOnlyTest, self).setUp()
        self.emanager = EntityManager(StoreWithThreeClientsOnly)
        self.client = BaseTestFactory.create_store_with_some_clients()

    @gen_test
    def test_saved_client_with_address(self):
        self.object_id = yield self.emanager.save(self.client)
        self.client_result = yield self.emanager.find_one(_id=self.object_id)
        yield self.emanager.remove(_id=self.object_id)
        self.assertTrue(compare_objs(self.client, self.client_result), "client with 3 addresses was not properly saved")
class ClientWithManyProductsTest(BaseTest):
    def setUp(self):
        super(ClientWithManyProductsTest, self).setUp()
        self.emanager = EntityManager(ClientWithManyProducts)
        self.client = BaseTestFactory.create_clients_with_many_products()

    @gen_test
    def test_saved_client_with_many_products(self):
        self.object_id = yield self.emanager.save(self.client)
        self.client_result = yield self.emanager.find_one(_id=self.object_id)
        yield self.emanager.remove(_id=self.object_id)
        self.assertTrue(compare_objs(self.client, self.client_result), "client was not properly saved")
class ProductWithShippingOptionsTest(AsyncTestCase):
    def setUp(self):
        super(ProductWithShippingOptionsTest, self).setUp()
        EntityConnection.open('localhost', 27017, db="product_with_shipping", io_loop=self.io_loop)
        self.emanager = EntityManager(ProductWithShippingOptions)
        self.product = BaseTestFactory.create_product_with_3_shipping_options()

    @gen_test
    def test_product_with_3_shipping_options(self):
        object_id = yield self.emanager.save(self.product)
        saved_product = yield self.emanager.find_one(_id=object_id)
        self.assertTrue(compare_objs(self.product, saved_product), "product was not properly saved")
class ConnectionUsingHostPortTest(AsyncTestCase):
    def setUp(self):
        super(ConnectionUsingHostPortTest, self).setUp()
        EntityConnection.open('localhost', 27017, db="ym_db_test_16", io_loop=self.io_loop)
        self.emanager = EntityManager(SimpleClient)
        self.simple_client = SimpleClient('_name', '__last_name')

    @gen_test
    def test_saved_simple_client(self):
        object_id = yield self.emanager.save(self.simple_client)
        saved_client = yield self.emanager.find_one(_id=object_id)
        self.assertTrue(compare_objs(self.simple_client, saved_client), "client was not mapped")
Beispiel #6
0
class StoreWithThreeClientsOnlyTest(BaseTest):
    def setUp(self):
        super(StoreWithThreeClientsOnlyTest, self).setUp()
        self.emanager = EntityManager(StoreWithThreeClientsOnly)
        self.client = BaseTestFactory.create_store_with_some_clients()

    @gen_test
    def test_saved_client_with_address(self):
        self.object_id = yield self.emanager.save(self.client)
        self.client_result = yield self.emanager.find_one(_id=self.object_id)
        yield self.emanager.remove(_id=self.object_id)
        self.assertTrue(compare_objs(self.client, self.client_result),
                        "client with 3 addresses was not properly saved")
Beispiel #7
0
class ClientWithManyProductsTest(BaseTest):
    def setUp(self):
        super(ClientWithManyProductsTest, self).setUp()
        self.emanager = EntityManager(ClientWithManyProducts)
        self.client = BaseTestFactory.create_clients_with_many_products()

    @gen_test
    def test_saved_client_with_many_products(self):
        self.object_id = yield self.emanager.save(self.client)
        self.client_result = yield self.emanager.find_one(_id=self.object_id)
        yield self.emanager.remove(_id=self.object_id)
        self.assertTrue(compare_objs(self.client, self.client_result),
                        "client was not properly saved")
class ClientWithOneAddressTest(BaseTest):
        def setUp(self):
            super(ClientWithOneAddressTest, self).setUp()
            self.emanager = EntityManager(ClientWithOneAddress)
            self.client_with_address = ClientWithOneAddress('leo', 'sza')
            self.address = Address(city='MANILA', street='test', number=10)
            self.client_with_address.set_address(self.address)

        @gen_test
        def test_saved_client_with_one_address(self):
            object_id = yield self.emanager.save(self.client_with_address)
            saved_client = yield self.emanager.find_one(_id=object_id)
            yield self.emanager.remove(_id=object_id)
            self.assertTrue(compare_objs(saved_client.address, self.address), "Address was not mapped")
Beispiel #9
0
class ClientWithOneAddressTest(BaseTest):
    def setUp(self):
        super(ClientWithOneAddressTest, self).setUp()
        self.emanager = EntityManager(ClientWithOneAddress)
        self.client_with_address = ClientWithOneAddress('leo', 'sza')
        self.address = Address(city='MANILA', street='test', number=10)
        self.client_with_address.set_address(self.address)

    @gen_test
    def test_saved_client_with_one_address(self):
        object_id = yield self.emanager.save(self.client_with_address)
        saved_client = yield self.emanager.find_one(_id=object_id)
        yield self.emanager.remove(_id=object_id)
        self.assertTrue(compare_objs(saved_client.address, self.address),
                        "Address was not mapped")
Beispiel #10
0
class UpdatedClientTest(BaseTest):
    def setUp(self):
        super(UpdatedClientTest, self).setUp()
        self.emanager = EntityManager(SimpleClient)

        self.client1 = BaseTestFactory.create_client_with_3_address()
        self.client2 = BaseTestFactory.create_client_with_3_address()
        self.client3 = BaseTestFactory.create_client_with_3_address()

    @gen_test
    def test_client2_was_successful_updated(self):
        yield self.emanager.remove_all()
        self.objectid_1 = yield self.emanager.save(self.client1)
        self.objectid_2 = yield self.emanager.save(self.client2)
        self.objectid_3 = yield self.emanager.save(self.client3)

        self.client_to_update = yield self.emanager.find_one(
            _id=self.objectid_2)
        self.client_to_update.name = "updated_name"
        self.client_to_update.last_name = "updated_last_name"

        yield self.emanager.update(self.client_to_update)

        self.updated_client = yield self.emanager.find_one(_id=self.objectid_2)

        self.return_client1 = yield self.emanager.find_one(_id=self.objectid_1)
        self.return_client3 = yield self.emanager.find_one(_id=self.objectid_3)

        # check if client2 was updated
        self.assertEqual(self.client_to_update.name, self.updated_client.name)
        self.assertEqual(self.client_to_update.last_name,
                         self.updated_client.last_name)

        # check if nothing changed in client1 and client3
        self.assertTrue(compare_objs(self.client1, self.return_client1))
        self.assertTrue(compare_objs(self.client3, self.return_client3))
Beispiel #11
0
class ProductWithShippingOptionsTest(AsyncTestCase):
    def setUp(self):
        super(ProductWithShippingOptionsTest, self).setUp()
        EntityConnection.open('localhost',
                              27017,
                              db="product_with_shipping",
                              io_loop=self.io_loop)
        self.emanager = EntityManager(ProductWithShippingOptions)
        self.product = BaseTestFactory.create_product_with_3_shipping_options()

    @gen_test
    def test_product_with_3_shipping_options(self):
        object_id = yield self.emanager.save(self.product)
        saved_product = yield self.emanager.find_one(_id=object_id)
        self.assertTrue(compare_objs(self.product, saved_product),
                        "product was not properly saved")
Beispiel #12
0
class ConnectionUsingHostPortTest(AsyncTestCase):
    def setUp(self):
        super(ConnectionUsingHostPortTest, self).setUp()
        EntityConnection.open('localhost',
                              27017,
                              db="ym_db_test_16",
                              io_loop=self.io_loop)
        self.emanager = EntityManager(SimpleClient)
        self.simple_client = SimpleClient('_name', '__last_name')

    @gen_test
    def test_saved_simple_client(self):
        object_id = yield self.emanager.save(self.simple_client)
        saved_client = yield self.emanager.find_one(_id=object_id)
        self.assertTrue(compare_objs(self.simple_client, saved_client),
                        "client was not mapped")