def test_project_key_property(self): task = Task( key=TaskKey.build_by_id(task_id=1), name=TaskName("Task Name"), project_key=None, finished_at=None, created_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), ) assert not task.project_key project = Project( key=ProjectKey.build_by_id(project_id=1), name=ProjectName("Project Name"), created_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), ) finished_task = Task( key=TaskKey.build_by_id(task_id=1), name=TaskName("Task Name"), project_key=project.key, finished_at=None, created_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), ) assert finished_task.key
def test_finished_property(self): task = Task( key=TaskKey.build_by_id(task_id=1), name=TaskName("Task Name"), project_key=None, finished_at=None, created_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), ) assert not task.is_finished finished_task = Task( key=TaskKey.build_by_id(task_id=1), name=TaskName("Task Name"), project_key=None, finished_at=datetime.datetime(2019, 12, 2, 0, 0, 0, tzinfo=datetime.timezone.utc), created_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), ) assert finished_task.is_finished
def post(self, task_id): task_key = TaskKey.build_by_id(task_id=task_id) task_name: str = flask.request.form.get("new_task_name", "") service: TaskNameUpdateService = injector.get(TaskNameUpdateService) service.execute(key=task_key, task_name=task_name) return flask.redirect("/tasks")
def post(self, task_id): task_key = TaskKey.build_by_id(task_id=task_id) project_id: str = flask.request.form.get("project_id", "") service: TaskProjectUpdateService = injector.get(TaskProjectUpdateService) service.execute(key=task_key, project_id=project_id) return flask.redirect("/tasks")
def test_build_from_key(self): entity_key = EntityKeyFactory().build( kind="Task", name=1, ) task_key = TaskKey.build_from_key(key=entity_key) assert entity_key != task_key assert entity_key.key_literal() == task_key.key_literal()
def post(self, task_id): task_key = TaskKey.build_by_id(task_id=task_id) finished = flask.request.form.get("finished", "false") == "true" service: TaskStatusUpdateService = injector.get( TaskStatusUpdateService) service.execute(key=task_key, finished=finished) print(flask.request.path) return flask.redirect("/")
def _to_domain_entity(self, doc: datastore.Entity) -> Task: return Task( key=TaskKey.build_from_key(key=doc.key), name=TaskName(doc["name"]), project_key=ProjectKey.build_from_key(key=doc["project_key"]) if doc["project_key"] is not None else doc["project_key"], finished_at=doc["finished_at"], created_at=doc["created_at"], updated_at=doc["update_at"], )
def _to_domain_entity(self, doc: DatastoreEntity) -> Task: model = TaskDataModel.from_datastore_entity(doc=doc) return Task( key=TaskKey.build_from_key(key=self.to_entity_key(datastore_key=model.key)), name=TaskName(model.name), project_key=ProjectKey.build_from_key(key=self.to_entity_key(datastore_key=model.project_key)) if model.project_key is not None else model.project_key, finished_at=model.finished_at, created_at=model.created_at, updated_at=model.update_at, )
def post(self, task_id): task_key = TaskKey.build_by_id(task_id=task_id) finished = flask.request.form.get("finished", "false") == "true" redirect_to = flask.request.form.get("redirectTo", "/tasks") if not redirect_to.startswith("/"): redirect_to = "/tasks" service: TaskStatusUpdateService = injector.get(TaskStatusUpdateService) service.execute(key=task_key, finished=finished) return flask.redirect(redirect_to)
def test_save(self): self.cleanup_entities() assert self.count_entities() == 0 task = Task( key=TaskKey.build_by_id(task_id=123), name=TaskName("Task Name"), finished_at=None, project_key=None, created_at=datetime.datetime(2019, 12, 1, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(2019, 12, 1, tzinfo=datetime.timezone.utc), ) self.repository.save(task=task) assert self.count_entities() == 1
def execute(self, task_name: str) -> Task: now = datetime.datetime.utcnow().astimezone(tz=datetime.timezone.utc) task = Task( key=TaskKey.build_for_new(), name=TaskName(task_name), project_key=None, finished_at=None, created_at=now, updated_at=now, ) self._task_repository.save(task=task) return task
def test_build_failure(self): with pytest.raises(expected_exception=TypeValidationError): Task( key=TaskKey.build_by_id(task_id=1), name='task name', project_key=None, finished_at=None, created_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), )
def test_build_successful(self): task = Task( key=TaskKey.build_by_id(task_id=1), name=TaskName("Task Name"), project_key=None, finished_at=None, created_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), updated_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), ) assert isinstance(task, Task)
def test_equal(self): key1 = TaskKey.build_by_id(task_id=1) key2 = TaskKey.build_by_id(task_id=1) assert key1 == key2 assert key1.task_id == 1
def post(self, task_id): task_key = TaskKey.build_by_id(task_id=task_id) repository: TaskRepository = injector.get(TaskRepository) repository.delete(key=task_key) return flask.redirect("/tasks")