def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) with SessionContext(self.graph), transaction(): self.new_order = Order().create() self.new_pizza = Pizza( id=new_object_id(), order_id=self.new_order.id, pizza_size=PizzaSize.SMALL.name, pizza_type=PizzaType.HANDTOSSED.name, ).create() self.first_topping = Topping( id=new_object_id(), pizza_id=self.new_pizza.id, topping_type=ToppingType.ONIONS, ) self.second_topping = Topping( id=new_object_id(), pizza_id=self.new_pizza.id, topping_type=ToppingType.CHICKEN, )
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.username1 = "glen.runciter" self.user1 = User( username=self.username1, email="*****@*****.**", first_name="Glen", last_name="Runciter", title="Big Boss", bio="Ubik-- get it today!", ) self.username2 = "joe.chip" self.user2 = User( username=self.username2, email="*****@*****.**", first_name="Joe", last_name="Chip", title="Technician", bio="Ubik-- get it today!", ) with SessionContext(self.graph), transaction(): self.user1.create() self.user2.create() self.user1_follow_user2 = FollowerRelationship( id=new_object_id(), user_id=self.user2.id, follower_id=self.user1.id, ) self.user2_tweet_content1 = """ Friends, this is clean-up time and we’re discounting all our silent, electric Ubiks by this much money. Yes, we’re throwing away the blue-book. And remember: every Ubik on our lot has been used only as directed. """ self.user2_tweet_content2 = """ The best way to ask for beer is to sing out Ubik. Made from select hops, choice water, slow-aged for perfect flavor, Ubik is the nation’s number-one choice in beer. Made only in Cleveland. """ with SessionContext(self.graph), transaction(): self.user1_follow_user2.create() self.user2_tweet1 = Tweet( id=new_object_id(), user_id=self.user2.id, tweet_content=self.user2_tweet_content1, ).create() self.user2_tweet2 = Tweet( id=new_object_id(), user_id=self.user2.id, tweet_content=self.user2_tweet_content2, ).create()
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.order_id = new_object_id() self.order1 = Order(id=self.order_id, customer_id=new_object_id()) self.detail_uri = f"/api/v1/order/{self.order1.id}"
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.order_event_id = new_object_id() self.order = Order(id=new_object_id()) self.order_event = OrderEvent( id=self.order_event_id, order_id=self.order.id, event_type="OrderInitialized", ) self.detail_uri = f"{self.list_uri}/{self.order_event_id}"
def setup(self): self.graph = create_app(testing=True) recreate_all(self.graph) self.client = TestClient(self.graph.app) self.pizza_id = new_object_id()
def test_create(self): uri = "/api/v1/pizza" with SessionContext(self.graph), transaction(): self.order.create() customer_id = str(new_object_id()) with patch.object(self.graph.pizza_store, "new_object_id") as mocked: mocked.return_value = self.pizza1.id response = self.client.post( uri, json=dict(customerId=customer_id, crustType="thin", size=12, orderId=self.order_id), ) assert_that(response.status_code, is_(equal_to(201))) assert_that( response.json, has_entries( id=str(self.pizza1.id), customerId=customer_id, crustType="thin", size=12, ), )
def test_created_event(self): created_event_id = new_object_id() with patch.object(self.graph.task_event_store, "new_object_id") as mocked: mocked.return_value = created_event_id response = self.client.post( "/api/v1/task_event", data=dumps( dict( taskId=str(self.task.id), eventType=TaskEventType.CREATED.name, parentId=str(self.task.id), )), ) assert_that(response.status_code, is_(equal_to(201))) data = loads(response.data.decode("utf-8")) assert_that(data, has_entry("id", str(created_event_id))) assert_that(data, has_entry("taskId", str(self.task.id))) assert_that(data, has_entry("clock", 1)) assert_that(data, has_entry("parentId", none())) self.graph.sns_producer.produce.assert_called_with( media_type= "application/vnd.globality.pubsub._.created.task_event.created", uri="http://localhost/api/v1/task_event/{}".format(data["id"]), ) with SessionContext(self.graph), transaction(): task_event = self.graph.task_event_store.retrieve(data["id"]) assert_that(task_event.state, is_(contains(TaskEventType.CREATED)))
def test_configure_pubsub_event(self): created_event_id = new_object_id() with patch.object(self.graph.task_event_controller, "get_event_factory_kwargs") as mocked_factory_kwargs: mocked_factory_kwargs.return_value = dict( publish_event_pubsub=False, publish_model_pubsub=True, ) with patch.object(self.graph.task_event_store, "new_object_id") as mocked: mocked.return_value = created_event_id response = self.client.post( "/api/v1/task_event", data=dumps( dict( taskId=str(self.task.id), eventType=TaskEventType.CREATED.name, parentId=str(self.task.id), )), ) assert_that(response.status_code, is_(equal_to(201))) self.graph.sns_producer.produce.assert_called_with( media_type="application/vnd.globality.pubsub._.created.task_event", uri="http://localhost/api/v1/task_event/{}".format( created_event_id), )
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.name1 = "name1" self.order_id = new_object_id() self.customer_id = new_object_id() self.order = Order(id=self.order_id, customer_id=self.customer_id) self.pizza1 = Pizza( id=new_object_id(), customer_id=self.customer_id, crust_type="thin", size=12, order_id=self.order_id, )
def setup(self): self.graph = create_app(testing=True) self.order_event_store = self.graph.order_event_store self.order_id = new_object_id() self.context = SessionContext(self.graph) self.context.recreate_all() self.context.open()
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) with SessionContext(self.graph), transaction(): self.new_order = Order().create() self.customer_event = CustomerStartedOrder(id=new_object_id(), order_id=self.new_order.id)
def test_create(self): customer_id = str(new_object_id()) with patch.object(self.graph.order_store, "new_object_id") as mocked: mocked.return_value = self.order1.id response = self.client.post(self.list_create_uri, json=dict(customerId=customer_id)) assert_that(response.status_code, is_(equal_to(201))) assert_that( response.json, has_entries(id=str(self.order1.id), customerId=str(customer_id)))
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.name = "name" self.account = Account( id=new_object_id(), name=self.name, )
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.name1 = "name1" self.example1 = Example( id=new_object_id(), name=self.name1, )
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.name1 = "name1" self.example1 = Example( id=new_object_id(), name=self.name1, )
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.factory = self.graph.order_event_factory self.pizza_id = new_object_id() self.order_id = new_object_id() self.customer_id = new_object_id() self.topping_id = new_object_id() self.pizza = Pizza(id=self.pizza_id, customer_id=self.customer_id) self.order = Order(id=self.order_id, customer_id=self.customer_id) self.topping1 = Topping( id=self.topping_id, pizza_id=self.pizza_id, topping_type="ONION", order_id=self.order_id, ) self.detail_uri = f"/api/v1/topping/{self.topping1.id}"
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.username1 = "glen.runciter" self.user1 = User( username=self.username1, email="*****@*****.**", first_name="Glen", last_name="Runciter", title="Big Boss", bio="Ubik-- get it today!", ) self.username2 = "joe.chip" self.user2 = User( username=self.username2, email="*****@*****.**", first_name="Joe", last_name="Chip", title="Technician", bio="Ubik-- get it today!", ) with SessionContext(self.graph), transaction(): self.user1.create() self.user2.create() self.user1_follow_user2 = FollowerRelationship( id=new_object_id(), user_id=self.user1.id, follower_id=self.user2.id, ) self.user2_follow_user1 = FollowerRelationship( id=new_object_id(), user_id=self.user2.id, follower_id=self.user1.id, )
def test_create(self): """ Pizza can be persisted. """ new_pizza = Pizza(customer_id=new_object_id(), crust_type="thin", size=10) with transaction(): self.pizza_store.create(new_pizza) retrieved_pizza = self.pizza_store.retrieve(new_pizza.id) assert_that(retrieved_pizza, is_(equal_to(new_pizza)))
def setup(self): self.graph = RobOnboardingOrdersDaemon.create_for_testing().graph self.handler = self.graph.order_fulfilled_handler self.customer_id = new_object_id() self.delivery_event_id = new_object_id() self.order_id = new_object_id() self.delivery_event_type = "DeliveryCompleted" self.message = dict( uri= f"https://deliveries.dev.globaltiy.io/api/v1/delivery_event/{self.delivery_event_id}" ) self.delivery_event = dict( id=self.delivery_event_id, orderId=self.order_id, eventType=self.delivery_event_type, ) self.order = MagicMock( json=MagicMock(return_value=dict(customerId=self.customer_id)), raise_for_status=MagicMock(), ) self.order_event = MagicMock(json=MagicMock(return_value=dict( items=[dict(eventType=str(OrderEventType.OrderSubmitted))])))
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.username1 = "glen.runciter" self.email1 = "*****@*****.**" self.first_name1 = "Glen" self.last_name1 = "Runciter" self.title1 = "Big Boss" self.bio1 = "Ubik-- get it today!" self.user1 = User( id=new_object_id(), username=self.username1, email=self.email1, first_name=self.first_name1, last_name=self.last_name1, title=self.title1, bio=self.bio1, )
def clone(instance, substitutions, ignore=()): """ Clone an instance of `Model` that uses `IdentityMixin`. :param instance: the instance to clonse :param substitutions: a dictionary of substitutions :param ignore: a tuple of column names to ignore """ substitutions[instance.id] = new_object_id() def substitute(value): try: hash(value) except Exception: return value else: return substitutions.get(value, value) return instance.__class__(**{ key: substitute(value) for key, value in iter_items(instance, ignore) }).create()
def test_search(self): self.username2 = "joe.chip" self.email2 = "*****@*****.**" self.first_name2 = "Joe" self.last_name2 = "Chip" self.title2 = "Technician" self.bio2 = "Ubik-- get it today!" self.user2 = User( id=new_object_id(), username=self.username2, email=self.email2, first_name=self.first_name2, last_name=self.last_name2, title=self.title2, bio=self.bio2, ) with SessionContext(self.graph), transaction(): self.user1.create() self.user2.create() uri = "/api/v1/user" response = self.client.get(uri) assert_that(response.status_code, is_(equal_to(200))) data = loads(response.data) assert_that(len(data["items"]), is_(equal_to(2))) assert_that(data, has_entries( items=contains( has_entries( id=str(self.user1.id), username=self.user1.username, email=self.user1.email, firstName=self.user1.first_name, lastName=self.user1.last_name, title=self.user1.title, bio=self.user1.bio, ), has_entries( id=str(self.user2.id), username=self.user2.username, email=self.user2.email, firstName=self.user2.first_name, lastName=self.user2.last_name, title=self.user2.title, bio=self.user2.bio, ), ), )) response = self.client.get( uri, query_string=dict( username=self.user1.username, ), ) assert_that(response.status_code, is_(equal_to(200))) data = loads(response.data) assert_that(len(data["items"]), is_(equal_to(1))) assert_that(data, has_entries( items=contains( has_entries( id=str(self.user1.id), username=self.user1.username, email=self.user1.email, firstName=self.user1.first_name, lastName=self.user1.last_name, title=self.user1.title, bio=self.user1.bio, ), ), ))
def test_proc_events_create_end_event(self): """ Insert a canceled event at the end of the event stream. """ cancelled_event_id = new_object_id() events_to_create_string = ( f"CREATE TEMP TABLE events_to_create AS (\n" f" SELECT\n" f" '{cancelled_event_id}'::uuid as id,\n" f" extract(epoch from now()) as created_at,\n" f" extract(epoch from now()) as updated_at,\n" f" assignee,\n" f" NULL::timestamp without time zone as deadline,\n" f" task_id,\n" f" 'CANCELED' as event_type,\n" f" id as parent_id,\n" f" '{{\"CANCELED\"}}'::character varying[] as state,\n" f" 1 as version\n" f" FROM task_event WHERE event_type='STARTED'\n" f" );" ) self.activity_store.session.execute(events_to_create_string) self.activity_store.session.execute(""" SELECT proc_events_create( 'task_event', 'events_to_create', '( id, created_at, updated_at, assignee, deadline, task_id, event_type, parent_id, state, version )' ); """) results = self.store.search() assert_that(results, has_length(5)) # NB: The events appear out of order because they are sorted by clock, # but the parent id chain is correct. In particular the parent of the # STARTED event has been changed by the migration assert_that(results, contains( has_properties( event_type=TaskEventType.CANCELED, state=[TaskEventType.CANCELED], parent_id=self.started_event.id, id=cancelled_event_id, ), has_properties( event_type=TaskEventType.STARTED, state=[TaskEventType.STARTED], id=self.started_event.id, parent_id=self.assigned_event.id, ), has_properties( event_type=TaskEventType.ASSIGNED, state=[TaskEventType.ASSIGNED, TaskEventType.CREATED, TaskEventType.SCHEDULED], id=self.assigned_event.id, parent_id=self.scheduled_event.id, ), has_properties( event_type=TaskEventType.SCHEDULED, state=[TaskEventType.CREATED, TaskEventType.SCHEDULED], id=self.scheduled_event.id, parent_id=self.created_event.id, ), has_properties( event_type=TaskEventType.CREATED, state=[TaskEventType.CREATED], id=self.created_event.id, parent_id=None, ), ))
def new_object_id(self): """ Injectable id generation to facilitate mocking. """ return new_object_id()
def setup(self): self.graph = create_app(testing=True) self.client = self.graph.flask.test_client() recreate_all(self.graph) self.new_order = Order(id=new_object_id(), )
def test_retrieve_not_found(self): assert_that( calling(self.store.retrieve).with_args(new_object_id()), raises(ModelNotFoundError), )
def new_object_id(self): """ Injectable id generation to facilitate mocking. """ return new_object_id()