def test_tag_delete_id(self): tag = self.create_test_tag() request = TagDataRequest(request_id=random.randrange(1000000), id=tag.unique_id, name=None, color=None, request_type=RequestType.DELETE) result, error = self.storage_provider.execute(request) self.assertIsNone(error)
def tag_write(self, tag_id: int = None, tag_name: str = None, color: int = None) -> Tag: request = TagDataRequest(request_id=random.randrange(1000000), id=tag_id, name=tag_name, color=color, request_type=RequestType.WRITE) response, error = self.storage_provider.execute(request) if error is not None: raise Error("""Undefined DB exception! Code: {} Description: {}""".format(error.code, error.description)) return response.tags[0]
def tag_delete(self, tag_id: int = None, tag_name: str = None) -> None: request = TagDataRequest(request_id=random.randrange(1000000), id=tag_id, name=tag_name, color=None, request_type=RequestType.DELETE) response, error = self.storage_provider.execute(request) if error is not None: if error.code == StorageProviderErrors.TAG_DOES_NOT_EXIST: raise TagDoesNotExistError(error.description) else: raise Error("""Undefined DB exception! Code: {} Description: {}""".format(error.code, error.description))
def test_tag_read_many(self): tags = [ self.create_test_tag(), self.create_test_tag(), self.create_test_tag() ] request = TagDataRequest(request_id=random.randrange(1000000), id=None, name=None, color=None, request_type=RequestType.READ) result, error = self.storage_provider.execute(request) self.assertIsNone(error) self.assertIsNotNone(result) self.assertIsNotNone(result.tags) self.assertEqual(len(result.tags), len(tags))
def test_tag_read_name(self): tag = self.create_test_tag() request = TagDataRequest(request_id=random.randrange(1000000), id=None, name=tag.name, color=None, request_type=RequestType.READ) result, error = self.storage_provider.execute(request) self.assertIsNone(error) self.assertIsNotNone(result) self.assertIsNotNone(result.tags) self.assertNotEqual(len(result.tags), 0) read_tag = result.tags[0] self.assertEqual(tag.unique_id, read_tag.unique_id) self.assertEqual(tag.name, read_tag.name) self.assertEqual(tag.color, read_tag.color)
def test_tag_rewrite(self): tag = self.create_test_tag() request = TagDataRequest(request_id=random.randrange(1000000), id=tag.unique_id, name="New name", color=0xFFFFFF, request_type=RequestType.WRITE) result, error = self.storage_provider.execute(request) self.assertIsNone(error) self.assertIsNotNone(result) self.assertIsNotNone(result.tags) self.assertNotEqual(len(result.tags), 0) tag = result.tags[0] self.assertIsNotNone(tag.unique_id) self.assertEqual(tag.name, request.name) self.assertEqual(tag.color, request.color)
def create_test_tag(self) -> Tag: request = TagDataRequest(request_id=random.randrange(1000000), id=None, name=''.join( random.choices(string.ascii_letters + string.digits, k=6)), color=random.randrange(0xFFFFFF + 1), request_type=RequestType.WRITE) result, error = self.storage_provider.execute(request) self.assertIsNone(error) self.assertIsNotNone(result) self.assertIsNotNone(result.tags) self.assertNotEqual(len(result.tags), 0) tag = result.tags[0] self.assertIsNotNone(tag.unique_id) self.assertEqual(tag.name, request.name) self.assertEqual(tag.color, request.color) return tag