def test_full_update(self, product_fixture_elasticsearch_store): _id = uuid4() product = ProductFixture(_id=_id, timestamp=time(), name="jeans", description="cool jeans", quantity=5, price=Decimal("49.99"), enabled=False) product_fixture_elasticsearch_store.create(product) updated_name = "shirt" updated_description = "red t-shirt" updated_quantity = 10 updated_price = Decimal("99.99") updated_enabled = True product.name = updated_name product.description = updated_description product.quantity = updated_quantity product.price = updated_price product.enabled = updated_enabled product.timestamp = time() product_fixture_elasticsearch_store.update(product) read_product = product_fixture_elasticsearch_store.read(_id) assert read_product.name == updated_name assert read_product.description == updated_description assert read_product.quantity == updated_quantity assert read_product.price == updated_price assert read_product.enabled == updated_enabled
def test_full_update(self, product_fixture_elasticsearch_store): _id = uuid4() product = ProductFixture(_id=_id, timestamp=time(), name="jeans", description="cool jeans", quantity=5, price=Decimal("49.99"), enabled=False) product_fixture_elasticsearch_store.create(product) updated_name = "shirt" updated_description = "red t-shirt" updated_quantity = 10 updated_price = Decimal("99.99") updated_enabled = True product.name = updated_name product.description = updated_description product.quantity = updated_quantity product.price = updated_price product.enabled = updated_enabled product.timestamp = time() product_fixture_elasticsearch_store.update(product) read_product = product_fixture_elasticsearch_store.read(_id) assert read_product.name == updated_name assert read_product.description == updated_description assert read_product.quantity == updated_quantity assert read_product.price == updated_price assert read_product.enabled == updated_enabled
def test_do_not_apply_update_to_existing_document_if_it_was_already_updated( self, update_applier, cassandra_fixture_keyspace, product_fixture_table, product_fixture_cassandra_store): keyspace = cassandra_fixture_keyspace table = product_fixture_table _id = uuid4() original_name = "jeans" original_description = "cool jeans" original_quantity = 5 product = ProductFixture(_id=_id, timestamp=time(), name=original_name, description=original_description, quantity=original_quantity) product_fixture_cassandra_store.create(product) updated_name = "t-shirt" updated_description = "cool red t-shirt" updated_quantity = 10 obsolete_update = build_update(namespace=keyspace, table=table, key=str(_id), timestamp=time(), fields=build_fields( name=updated_name, description=updated_description, quantity=updated_quantity)) sleep(0.001) more_recently_updated_name = "shoes" more_recently_updated_description = "skater shoes" product.name = more_recently_updated_name product.description = more_recently_updated_description product.timestamp = time() product_fixture_cassandra_store.update(product) update_applier.apply_update(obsolete_update) product = product_fixture_cassandra_store.read(_id) assert product.name == more_recently_updated_name assert product.description == more_recently_updated_description assert product.quantity == original_quantity
def test_do_not_apply_update_to_existing_document_if_it_was_already_updated(self, update_applier, elasticsearch_fixture_index, product_fixture_table, product_fixture_elasticsearch_store): _index = elasticsearch_fixture_index _type = product_fixture_table _id = uuid4() original_name = "jeans" original_description = "cool jeans" original_quantity = 5 product = ProductFixture(_id=_id, timestamp=time(), name=original_name, description=original_description, quantity=original_quantity) product_fixture_elasticsearch_store.create(product) updated_name = "t-shirt" updated_description = "cool red t-shirt" updated_quantity = 10 obsolete_update = build_update(namespace=_index, table=_type, key=str(_id), timestamp=time(), fields=build_fields(name=updated_name, description=updated_description, quantity=updated_quantity)) sleep(0.001) more_recently_updated_name = "shoes" more_recently_updated_description = "skater shoes" product.name = more_recently_updated_name product.description = more_recently_updated_description product.timestamp = time() product_fixture_elasticsearch_store.update(product) update_applier.apply_update(obsolete_update) product = product_fixture_elasticsearch_store.read(_id) assert product.name == more_recently_updated_name assert product.description == more_recently_updated_description assert product.quantity == original_quantity