예제 #1
0
def product_fixtures():
    timestamp = time()
    return [
        ProductFixture(_id=uuid4(),
                       name="navy polo shirt",
                       quantity=5,
                       description="great shirt, great price!",
                       price=Decimal("99.99"),
                       enabled=True,
                       publish_date=datetime.utcnow(),
                       external_id=uuid4(),
                       timestamp=timestamp),
        ProductFixture(_id=uuid4(),
                       name="cool red shorts",
                       quantity=7,
                       description="perfect to go to the beach",
                       price=Decimal("49.99"),
                       enabled=False,
                       publish_date=datetime.utcnow(),
                       external_id=uuid4(),
                       timestamp=timestamp),
        ProductFixture(_id=uuid4(),
                       name="black DC skater shoes",
                       quantity=10,
                       description="yo!",
                       price=Decimal("149.99"),
                       enabled=True,
                       publish_date=datetime.utcnow(),
                       external_id=uuid4(),
                       timestamp=timestamp)
    ]
    def test_partial_update(self, product_fixture_elasticsearch_store):
        _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_description = "red t-shirt"
        updated_quantity = 10

        product.description = updated_description
        product.quantity = updated_quantity
        product.timestamp = time()
        product_fixture_elasticsearch_store.update(product)

        read_product = product_fixture_elasticsearch_store.read(_id)
        assert read_product.name == original_name
        assert read_product.description == updated_description
        assert read_product.quantity == updated_quantity
    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_fetch_updates_with_minimum_time(self, elasticsearch_update_fetcher,
                                             product_fixture_elasticsearch_store, elasticsearch_fixture_index,
                                             product_fixture_table):

        before_minimum_timestamp = time()

        p1 = ProductFixture(_id=uuid4(), name="navy polo shirt", description="great shirt, great price!",
                            quantity=5, price=Decimal("99.99"), enabled=True, timestamp=before_minimum_timestamp)
        p2 = ProductFixture(_id=uuid4(), name="cool red shorts", description="perfect to go to the beach",
                            quantity=7, price=Decimal("49.99"), enabled=False, timestamp=before_minimum_timestamp)
        p3 = ProductFixture(_id=uuid4(), name="black DC skater shoes", description="yo!",
                            quantity=10, price=Decimal("149.99"), enabled=True, timestamp=before_minimum_timestamp)

        product_fixture_elasticsearch_store.create(p1)
        product_fixture_elasticsearch_store.create(p2)
        product_fixture_elasticsearch_store.create(p3)

        sleep(0.001)

        minimum_timestamp = time()

        p3.description = "very cool shoes"
        p3.price = Decimal("199.99")
        p3.timestamp = time()
        product_fixture_elasticsearch_store.update(p3)

        p4 = ProductFixture(_id=uuid4(), name="black gloves", description="warm, comfortable gloves",
                            quantity=7, price=Decimal("19.99"), enabled=True, timestamp=time())
        product_fixture_elasticsearch_store.create(p4)

        p4.description = "warm, comfortable, one-size fits all gloves"
        p4.quantity = 19
        product_fixture_elasticsearch_store.update(p4)

        p2.quantity = 10
        p2.timestamp = time()
        product_fixture_elasticsearch_store.update(p2)

        updates_iterator = elasticsearch_update_fetcher.fetch_updates(minimum_timestamp)
        product_updates = self.filter_documents_by_type(
            elasticsearch_fixture_index, product_fixture_table, updates_iterator)

        assert len(product_updates) == 3

        updates_by_key = self.group_updates_by_key(product_updates)

        assert p2.key in updates_by_key
        assert p3.key in updates_by_key
        assert p4.key in updates_by_key
        assert p1.key not in updates_by_key
    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_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
예제 #7
0
def product():
    return ProductFixture(_id=uuid4(),
                          timestamp=time(),
                          name="jeans",
                          description="cool jeans",
                          price=Decimal("19.99"),
                          quantity=7,
                          publish_date=datetime.utcnow(),
                          external_id=uuid4(),
                          enabled=False)
예제 #8
0
    def test_search_all(self, product_fixture_elasticsearch_store,
                        elasticsearch_document_store,
                        elasticsearch_fixture_index, product_fixture_table):
        products = [
            ProductFixture(_id=uuid4(),
                           name="Apple iPhone 6s",
                           description="the new iPhone",
                           price="1999.99",
                           timestamp=time()),
            ProductFixture(_id=uuid4(),
                           name="Samsung Galaxy A+",
                           description="beats iPhone",
                           price="999.99",
                           timestamp=time()),
            ProductFixture(_id=uuid4(),
                           name="Nokia Ultimate 89",
                           description="windows phone 10",
                           price="899.99",
                           timestamp=time())
        ]

        for product in products:
            product_fixture_elasticsearch_store.create(product)

        search_result = elasticsearch_document_store.search_all()

        filtered_documents = self.filter_documents_by_type(
            elasticsearch_fixture_index, product_fixture_table, search_result)
        assert len(filtered_documents) >= len(products)

        documents_by_key = self.group_documents_by_key(filtered_documents)

        for product in products:
            document = documents_by_key[str(product.id)]
            assert document
            assert abs(document.timestamp - product.timestamp) < 0.001
            assert product.name == document.get_field_value("name")
            assert product.description == document.get_field_value(
                "description")
            assert product.price == document.get_field_value("price")
    def test_fetch_multiple_save_updates_for_the_same_entity(self, cassandra_update_fetcher,
                                                             product_fixture_cassandra_store):
        _id = uuid.uuid4()
        timestamp = time()

        product_fixture = ProductFixture(_id=_id, timestamp=timestamp, name="The new MacBook Pro by Apple", quantity=10,
                                         description="it's amazing", price=Decimal("1999.99"), enabled=True)
        product_fixture_cassandra_store.create(product_fixture)

        product_fixture.price = Decimal("1499.99")
        product_fixture.timestamp = time()
        product_fixture_cassandra_store.update(product_fixture)

        product_fixture.description = "it' beyond amazing"
        product_fixture.enabled = False
        product_fixture.timestamp = time()
        product_fixture_cassandra_store.update(product_fixture)

        updates_iterator = cassandra_update_fetcher.fetch_updates(minimum_timestamp=timestamp)

        updates = []
        for update in updates_iterator:
            updates.append(update)

        assert len(updates) == 3

        fields = {}
        for update in updates:
            for field in update.fields:
                fields[field.name] = field.value

        assert fields["price"] == Decimal("1499.99")
        assert fields["description"] == "it' beyond amazing"
        assert fields["enabled"] is False
    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
    def test_delete_all(self, product_fixture_elasticsearch_store):
        product = ProductFixture(_id=uuid4(),
                                 timestamp=time(),
                                 name="jeans",
                                 description="cool jeans",
                                 quantity=5)
        product_fixture_elasticsearch_store.create(product)

        assert product_fixture_elasticsearch_store.read(product.id)

        product_fixture_elasticsearch_store.delete_all()

        assert not product_fixture_elasticsearch_store.read(product.id)
예제 #12
0
def product_fixtures(product_fixture_cassandra_store,
                     product_fixtures_creation_timestamp):
    product_fixture_cassandra_store.delete_all()

    products = [
        ProductFixture(_id=uuid.uuid4(),
                       timestamp=product_fixtures_creation_timestamp,
                       name="navy polo shirt",
                       quantity=5,
                       description="great shirt, great price!",
                       price=Decimal("99.99"),
                       enabled=True),
        ProductFixture(_id=uuid.uuid4(),
                       timestamp=product_fixtures_creation_timestamp,
                       name="cool red shorts",
                       quantity=7,
                       description="perfect to go to the beach",
                       price=Decimal("49.99"),
                       enabled=False),
        ProductFixture(_id=uuid.uuid4(),
                       timestamp=product_fixtures_creation_timestamp,
                       name="black DC skater shoes",
                       quantity=10,
                       description="yo!",
                       price=Decimal("149.99"),
                       enabled=True),
        ProductFixture(_id=uuid.uuid4(),
                       timestamp=product_fixtures_creation_timestamp,
                       name="warm gloves",
                       quantity=15,
                       description="elegant, warm, one-size-fits-all gloves",
                       price=Decimal("19.99"),
                       enabled=True)
    ]

    for product in products:
        product_fixture_cassandra_store.create(product)
    return products
예제 #13
0
    def test_search_by_minimum_timestamp(self,
                                         product_fixture_elasticsearch_store,
                                         elasticsearch_document_store):

        base_timestamp = time()

        p1 = ProductFixture(_id=uuid4(), name="1", timestamp=base_timestamp)
        p2 = ProductFixture(_id=uuid4(),
                            name="2",
                            timestamp=base_timestamp + 1)
        p3 = ProductFixture(_id=uuid4(),
                            name="3",
                            timestamp=base_timestamp + 2)
        p4 = ProductFixture(_id=uuid4(),
                            name="4",
                            timestamp=base_timestamp + 3)

        minimum_timestamp = (base_timestamp + 3) + 0.001

        p5 = ProductFixture(_id=uuid4(), name="5", timestamp=minimum_timestamp)
        p6 = ProductFixture(_id=uuid4(),
                            name="6",
                            timestamp=minimum_timestamp + 1)
        p7 = ProductFixture(_id=uuid4(),
                            name="7",
                            timestamp=minimum_timestamp + 2)
        p8 = ProductFixture(_id=uuid4(),
                            name="8",
                            timestamp=minimum_timestamp + 3)

        products = [p1, p2, p3, p4, p5, p6, p7, p8]

        for p in products:
            product_fixture_elasticsearch_store.create(p)

        found_documents = elasticsearch_document_store.search_by_minimum_timestamp(
            minimum_timestamp).to_list()

        assert len(found_documents) == 4

        found_ids = []
        for document in found_documents:
            found_ids.append(UUID(document.identifier.key))

        assert p5.id in found_ids
        assert p6.id in found_ids
        assert p7.id in found_ids
        assert p8.id in found_ids
def product_fixtures():
    timestamp = time()
    return [
        ProductFixture(_id=uuid4(),
                       name="navy polo shirt",
                       quantity=5,
                       description="great shirt, great price!",
                       price=Decimal("99.99"),
                       enabled=True,
                       publish_date=datetime.utcnow(),
                       external_id=uuid4(),
                       timestamp=timestamp),
        ProductFixture(_id=uuid4(),
                       name="cool red shorts",
                       quantity=7,
                       description="perfect to go to the beach",
                       price=Decimal("49.99"),
                       enabled=False,
                       publish_date=datetime.utcnow(),
                       external_id=uuid4(),
                       timestamp=timestamp),
        ProductFixture(_id=uuid4(),
                       name="black DC skater shoes",
                       quantity=10,
                       description="yo!",
                       price=Decimal("149.99"),
                       enabled=True,
                       publish_date=datetime.utcnow(),
                       external_id=uuid4(),
                       timestamp=timestamp),
        ProductFixture(_id=uuid4(),
                       name="black shirt",
                       quantity=20,
                       description="black is the new black",
                       price=Decimal("39.99"),
                       enabled=True,
                       publish_date=datetime.utcnow(),
                       external_id=uuid4(),
                       timestamp=timestamp),
        ProductFixture(_id=uuid4(),
                       name="white boxers",
                       quantity=10,
                       description="5 units in a package",
                       price=Decimal("10.99"),
                       enabled=False,
                       publish_date=datetime.utcnow(),
                       external_id=uuid4(),
                       timestamp=timestamp),
        ProductFixture(_id=uuid4(),
                       name="armani business shirt",
                       quantity=2,
                       description="dress like a boss",
                       price=Decimal("299.99"),
                       enabled=True,
                       publish_date=datetime.utcnow(),
                       external_id=uuid4(),
                       timestamp=timestamp)
    ]
예제 #15
0
    def test_initial_sync_then_incremental_saves(
            self, product_fixtures, product_fixture_cassandra_store,
            product_fixture_elasticsearch_store, sync_interval_time):

        for product in product_fixtures:
            product_fixture_elasticsearch_store.create(product)

        sleep(sync_interval_time)

        for product in product_fixtures:
            product.name = "new name"
            product.description = "new description"
            product.quantity = 100
            product.price = Decimal("299.99")
            product.publish_date = datetime.utcnow()
            product.external_id = uuid4()
            product.timestamp = time()
            product_fixture_elasticsearch_store.update(product)

        sleep(sync_interval_time)

        product_fixtures[0].description = "another description"
        product_fixtures[0].timestamp = time()
        product_fixture_elasticsearch_store.update(product_fixtures[0])

        product_fixtures[1].price = Decimal("1.99")
        product_fixtures[1].timestamp = time()
        product_fixture_elasticsearch_store.update(product_fixtures[1])

        sleep(sync_interval_time)

        new_product = ProductFixture(_id=uuid4(),
                                     name="black gloves",
                                     quantity=10,
                                     description="comfortable, warm",
                                     price=Decimal("29.99"),
                                     enabled=False,
                                     publish_date=datetime.utcnow(),
                                     external_id=uuid4(),
                                     timestamp=time())
        product_fixture_elasticsearch_store.create(new_product)
        product_fixtures.append(new_product)

        sleep(sync_interval_time)

        for product in product_fixtures:
            product_read_from_elasticsearch = product_fixture_cassandra_store.read(
                product.id)
            assert product_read_from_elasticsearch
            assert product == product_read_from_elasticsearch
    def test_partial_update(self, product_fixture_elasticsearch_store):
        _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_description = "red t-shirt"
        updated_quantity = 10

        product.description = updated_description
        product.quantity = updated_quantity
        product.timestamp = time()
        product_fixture_elasticsearch_store.update(product)

        read_product = product_fixture_elasticsearch_store.read(_id)
        assert read_product.name == original_name
        assert read_product.description == updated_description
        assert read_product.quantity == updated_quantity
    def only_update_if_fields_are_different(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
        original_price = Decimal("149.99")
        original_enabled = True

        original_timestamp = time()

        product = ProductFixture(_id=_id,
                                 timestamp=original_timestamp,
                                 name=original_name,
                                 description=original_description,
                                 quantity=original_quantity,
                                 price=original_price,
                                 enabled=original_enabled)
        product_fixture_cassandra_store.create(product)

        sleep(0.001)

        update_timestamp = time()
        useless_update = build_update(namespace=keyspace,
                                      table=table,
                                      key=str(_id),
                                      timestamp=update_timestamp,
                                      fields=build_fields(
                                          name=original_name,
                                          description=original_description,
                                          quantity=original_quantity,
                                          enabled=original_enabled,
                                          price=original_price))

        update_applier.apply_update(useless_update)

        read_product = product_fixture_cassandra_store.read(product)
        assert read_product.name == original_name
        assert read_product.description == original_description
        assert read_product.quantity == original_quantity
        assert read_product.timestamp == original_timestamp
    def test_create_and_read(self, product_fixture_elasticsearch_store):
        _id = uuid4()
        created_product = ProductFixture(_id=_id,
                                         name="jeans",
                                         description="cool jeans",
                                         quantity=5,
                                         price=Decimal("99.99"),
                                         enabled=True,
                                         timestamp=time())
        product_fixture_elasticsearch_store.create(created_product)

        read_product = product_fixture_elasticsearch_store.read(_id)
        assert created_product.name == read_product.name
        assert created_product.description == read_product.description
        assert created_product.quantity == read_product.quantity
        assert created_product.id == read_product.id
        assert created_product.price == read_product.price
        assert abs(created_product.timestamp - read_product.timestamp) < 0.001
    def test_apply_partial_save_update_to_existing_document(
            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
        original_price = Decimal("149.99")
        original_enabled = True

        product = ProductFixture(_id=_id,
                                 timestamp=time(),
                                 name=original_name,
                                 description=original_description,
                                 quantity=original_quantity,
                                 price=original_price,
                                 enabled=original_enabled)
        product_fixture_cassandra_store.create(product)

        updated_description = "cool red t-shirt"
        updated_quantity = 10

        update = build_update(namespace=keyspace,
                              table=table,
                              key=str(_id),
                              timestamp=time(),
                              fields=build_fields(
                                  description=updated_description,
                                  quantity=updated_quantity))
        update_applier.apply_update(update)

        product = product_fixture_cassandra_store.read(_id)
        assert product.name == original_name
        assert product.price == original_price
        assert product.enabled == original_enabled
        assert product.description == updated_description
        assert product.quantity == updated_quantity
    def test_apply_delete_update_to_existing_document(
            self, update_applier, elasticsearch_fixture_index,
            product_fixture_table, product_fixture_elasticsearch_store):
        _index = elasticsearch_fixture_index
        _type = product_fixture_table
        _id = uuid4()

        product = ProductFixture(_id=_id,
                                 name="jeans",
                                 timestamp=time(),
                                 description="cool jeans",
                                 quantity=5)
        product_fixture_elasticsearch_store.create(product)

        delete_update = build_update(namespace=_index,
                                     table=_type,
                                     key=str(_id),
                                     timestamp=time(),
                                     is_delete=True)
        update_applier.apply_update(delete_update)

        assert not product_fixture_elasticsearch_store.read(_id)
    def test_apply_full_save_update_to_existing_document(
            self, update_applier, cassandra_fixture_keyspace,
            product_fixture_table, product_fixture_cassandra_store):

        keyspace = cassandra_fixture_keyspace
        table = product_fixture_table
        _id = uuid4()

        product = ProductFixture(_id=_id,
                                 name="jeans",
                                 description="cool jeans",
                                 quantity=10,
                                 price=Decimal("49.99"),
                                 enabled=True,
                                 timestamp=time())
        product_fixture_cassandra_store.create(product)

        updated_name = "t-shirt"
        updated_description = "cool red t-shirt"
        updated_quantity = 5
        updated_price = Decimal("69.99")
        updated_enabled = False

        update = build_update(namespace=keyspace,
                              table=table,
                              key=str(_id),
                              timestamp=time(),
                              fields=build_fields(
                                  name=updated_name,
                                  description=updated_description,
                                  quantity=updated_quantity,
                                  price=updated_price,
                                  enabled=updated_enabled))
        update_applier.apply_update(update)

        product = product_fixture_cassandra_store.read(_id)
        assert product.name == updated_name
        assert product.description == updated_description
        assert product.quantity == updated_quantity
    def test_apply_delete_update_to_existing_document(
            self, update_applier, cassandra_fixture_keyspace,
            product_fixture_table, product_fixture_cassandra_store):
        keyspace = cassandra_fixture_keyspace
        table = product_fixture_table
        _id = uuid4()

        product = ProductFixture(_id=_id,
                                 name="jeans",
                                 timestamp=time(),
                                 description="cool jeans",
                                 quantity=5)
        product_fixture_cassandra_store.create(product)

        delete_update = build_update(namespace=keyspace,
                                     table=table,
                                     key=str(_id),
                                     timestamp=time(),
                                     is_delete=True)
        update_applier.apply_update(delete_update)

        assert not product_fixture_cassandra_store.read(_id)
예제 #23
0
    def test_fetch_multiple_save_updates_for_the_same_entity(
            self, cassandra_update_fetcher, product_fixture_cassandra_store):
        _id = uuid.uuid4()
        timestamp = time()

        product_fixture = ProductFixture(_id=_id,
                                         timestamp=timestamp,
                                         name="The new MacBook Pro by Apple",
                                         quantity=10,
                                         description="it's amazing",
                                         price=Decimal("1999.99"),
                                         enabled=True)
        product_fixture_cassandra_store.create(product_fixture)

        product_fixture.price = Decimal("1499.99")
        product_fixture.timestamp = time()
        product_fixture_cassandra_store.update(product_fixture)

        product_fixture.description = "it' beyond amazing"
        product_fixture.enabled = False
        product_fixture.timestamp = time()
        product_fixture_cassandra_store.update(product_fixture)

        updates_iterator = cassandra_update_fetcher.fetch_updates(
            minimum_timestamp=timestamp)

        updates = []
        for update in updates_iterator:
            updates.append(update)

        assert len(updates) == 3

        fields = {}
        for update in updates:
            for field in update.fields:
                fields[field.name] = field.value

        assert fields["price"] == Decimal("1499.99")
        assert fields["description"] == "it' beyond amazing"
        assert fields["enabled"] is False
예제 #24
0
    def test_fetch_updates_from_the_beginning_of_time(
            self, elasticsearch_update_fetcher,
            product_fixture_elasticsearch_store, elasticsearch_fixture_index,
            product_fixture_table):

        p1 = ProductFixture(_id=uuid4(),
                            name="navy polo shirt",
                            description="great shirt, great price!",
                            quantity=5,
                            price=Decimal("99.99"),
                            enabled=True,
                            timestamp=time())
        p2 = ProductFixture(_id=uuid4(),
                            name="cool red shorts",
                            description="perfect to go to the beach",
                            quantity=7,
                            price=Decimal("49.99"),
                            enabled=False,
                            timestamp=time())
        p3 = ProductFixture(_id=uuid4(),
                            name="black DC skater shoes",
                            description="yo!",
                            quantity=10,
                            price=Decimal("149.99"),
                            enabled=True,
                            timestamp=time())

        product_fixture_elasticsearch_store.create(p1)
        product_fixture_elasticsearch_store.create(p2)
        product_fixture_elasticsearch_store.create(p3)

        sleep(0.001)

        p3.description = "very cool shoes"
        p3.price = Decimal("199.99")
        p3.timestamp = time()
        product_fixture_elasticsearch_store.update(p3)

        p4 = ProductFixture(_id=uuid4(),
                            name="black gloves",
                            description="warm, comfortable gloves",
                            quantity=7,
                            price=Decimal("19.99"),
                            enabled=True,
                            timestamp=time())
        product_fixture_elasticsearch_store.create(p4)

        p4.description = "warm, comfortable, one-size fits all gloves"
        p4.quantity = 19
        p4.timestamp = time()
        product_fixture_elasticsearch_store.update(p4)

        p1.quantity = 10
        p1.timestamp = time()
        product_fixture_elasticsearch_store.update(p1)

        products = (p1, p2, p3, p4)

        updates_iterator = elasticsearch_update_fetcher.fetch_updates()
        product_updates = self.filter_documents_by_type(
            elasticsearch_fixture_index, product_fixture_table,
            updates_iterator)

        assert len(product_updates) == len(products)

        updates_by_key = self.group_updates_by_key(product_updates)

        for product in products:
            update = updates_by_key[product.key]
            assert abs(product.timestamp - update.timestamp) < 0.001
            assert product.name == update.get_field_value("name")
            assert product.description == update.get_field_value("description")
            assert product.price == Decimal(update.get_field_value("price"))
            assert product.enabled == update.get_field_value("enabled")
            assert product.quantity == update.get_field_value("quantity")
예제 #25
0
    def test_fetch_updates_with_minimum_time(
            self, elasticsearch_update_fetcher,
            product_fixture_elasticsearch_store, elasticsearch_fixture_index,
            product_fixture_table):

        before_minimum_timestamp = time()

        p1 = ProductFixture(_id=uuid4(),
                            name="navy polo shirt",
                            description="great shirt, great price!",
                            quantity=5,
                            price=Decimal("99.99"),
                            enabled=True,
                            timestamp=before_minimum_timestamp)
        p2 = ProductFixture(_id=uuid4(),
                            name="cool red shorts",
                            description="perfect to go to the beach",
                            quantity=7,
                            price=Decimal("49.99"),
                            enabled=False,
                            timestamp=before_minimum_timestamp)
        p3 = ProductFixture(_id=uuid4(),
                            name="black DC skater shoes",
                            description="yo!",
                            quantity=10,
                            price=Decimal("149.99"),
                            enabled=True,
                            timestamp=before_minimum_timestamp)

        product_fixture_elasticsearch_store.create(p1)
        product_fixture_elasticsearch_store.create(p2)
        product_fixture_elasticsearch_store.create(p3)

        sleep(0.001)

        minimum_timestamp = time()

        p3.description = "very cool shoes"
        p3.price = Decimal("199.99")
        p3.timestamp = time()
        product_fixture_elasticsearch_store.update(p3)

        p4 = ProductFixture(_id=uuid4(),
                            name="black gloves",
                            description="warm, comfortable gloves",
                            quantity=7,
                            price=Decimal("19.99"),
                            enabled=True,
                            timestamp=time())
        product_fixture_elasticsearch_store.create(p4)

        p4.description = "warm, comfortable, one-size fits all gloves"
        p4.quantity = 19
        product_fixture_elasticsearch_store.update(p4)

        p2.quantity = 10
        p2.timestamp = time()
        product_fixture_elasticsearch_store.update(p2)

        updates_iterator = elasticsearch_update_fetcher.fetch_updates(
            minimum_timestamp)
        product_updates = self.filter_documents_by_type(
            elasticsearch_fixture_index, product_fixture_table,
            updates_iterator)

        assert len(product_updates) == 3

        updates_by_key = self.group_updates_by_key(product_updates)

        assert p2.key in updates_by_key
        assert p3.key in updates_by_key
        assert p4.key in updates_by_key
        assert p1.key not in updates_by_key
    def test_fetch_updates_from_the_beginning_of_time(self, elasticsearch_update_fetcher,
                                                      product_fixture_elasticsearch_store, elasticsearch_fixture_index,
                                                      product_fixture_table):

        p1 = ProductFixture(_id=uuid4(), name="navy polo shirt", description="great shirt, great price!",
                            quantity=5, price=Decimal("99.99"), enabled=True, timestamp=time())
        p2 = ProductFixture(_id=uuid4(), name="cool red shorts", description="perfect to go to the beach",
                            quantity=7, price=Decimal("49.99"), enabled=False, timestamp=time())
        p3 = ProductFixture(_id=uuid4(), name="black DC skater shoes", description="yo!",
                            quantity=10, price=Decimal("149.99"), enabled=True, timestamp=time())

        product_fixture_elasticsearch_store.create(p1)
        product_fixture_elasticsearch_store.create(p2)
        product_fixture_elasticsearch_store.create(p3)

        sleep(0.001)

        p3.description = "very cool shoes"
        p3.price = Decimal("199.99")
        p3.timestamp = time()
        product_fixture_elasticsearch_store.update(p3)

        p4 = ProductFixture(_id=uuid4(), name="black gloves", description="warm, comfortable gloves",
                            quantity=7, price=Decimal("19.99"), enabled=True, timestamp=time())
        product_fixture_elasticsearch_store.create(p4)

        p4.description = "warm, comfortable, one-size fits all gloves"
        p4.quantity = 19
        p4.timestamp = time()
        product_fixture_elasticsearch_store.update(p4)

        p1.quantity = 10
        p1.timestamp = time()
        product_fixture_elasticsearch_store.update(p1)

        products = (p1, p2, p3, p4)

        updates_iterator = elasticsearch_update_fetcher.fetch_updates()
        product_updates = self.filter_documents_by_type(
            elasticsearch_fixture_index, product_fixture_table, updates_iterator)

        assert len(product_updates) == len(products)

        updates_by_key = self.group_updates_by_key(product_updates)

        for product in products:
            update = updates_by_key[product.key]
            assert abs(product.timestamp - update.timestamp) < 0.001
            assert product.name == update.get_field_value("name")
            assert product.description == update.get_field_value("description")
            assert product.price == Decimal(update.get_field_value("price"))
            assert product.enabled == update.get_field_value("enabled")
            assert product.quantity == update.get_field_value("quantity")
    def test_only_propagate_updates_that_are_created_after_minimum_timestamp(
            self, river, product_fixture_cassandra_store,
            product_fixture_elasticsearch_store):

        before_timestamp = time()
        product_created_before = ProductFixture(
            _id=uuid4(),
            name="gloves",
            description="warm pair of gloves",
            quantity=50,
            timestamp=before_timestamp)
        product_fixture_cassandra_store.create(product_created_before)

        sleep(0.001)

        minimum_timestamp = time()
        products_created_after = [
            ProductFixture(uuid4(),
                           "navy polo shirt",
                           5,
                           "great shirt, great price!",
                           timestamp=minimum_timestamp),
            ProductFixture(uuid4(),
                           "cool red shorts",
                           7,
                           "perfect to go to the beach",
                           timestamp=minimum_timestamp),
            ProductFixture(uuid4(),
                           "black DC skater shoes",
                           10,
                           "yo!",
                           timestamp=minimum_timestamp),
            ProductFixture(uuid4(),
                           "regular jeans",
                           12,
                           "blue, nice jeans",
                           timestamp=minimum_timestamp)
        ]

        for product in products_created_after:
            product_fixture_cassandra_store.create(product)

        sleep(0.001)

        for product in products_created_after:
            product.name = "new_name"
            product.description = "new_description"
            product.timestamp = time()
            product_fixture_cassandra_store.update(product)

        river.propagate_updates(minimum_timestamp=minimum_timestamp)

        for product in products_created_after:
            read_from_cassandra = product_fixture_cassandra_store.read(
                product.id)
            read_from_elasticsearch = product_fixture_elasticsearch_store.read(
                product.id)
            assert product == read_from_cassandra == read_from_elasticsearch

        assert product_fixture_cassandra_store.read(product_created_before.id)
        assert not product_fixture_elasticsearch_store.read(
            product_created_before.id)