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_build_failure(self): with pytest.raises(expected_exception=TypeValidationError): Project( key=ProjectKey.build_by_id(project_id=1), name='project name', created_at=datetime.datetime(2019, 12, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), )
def test_build_successful(self): 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), ) assert isinstance(project, Project)
def execute(self, key: TaskKey, project_id: str) -> "Task": task = self._task_repository.fetch(key=key) if project_id != "None": project_key = ProjectKey.build_by_id(int(project_id)) else: project_key = None modified_task = task.with_project_key(project_key=project_key) self._task_repository.save(task=modified_task) return modified_task
def test_save(self): query = datastore_client.query(kind=self.KIND) query.keys_only() datastore_client.delete_multi( keys=[entity.key for entity in query.fetch()]) assert len(list(query.fetch())) == 0 project = Project( key=ProjectKey.build_by_id(project_id=123), name=ProjectName("Project Name"), created_at=datetime.datetime(2019, 12, 1, tzinfo=datetime.timezone.utc), ) self.repository.save(project=project) assert len(list(query.fetch())) == 1
def test_equal(self): key1 = ProjectKey.build_by_id(project_id=1) key2 = ProjectKey.build_by_id(project_id=1) assert key1 == key2 assert key1.project_id == 1