def test_rename_tag_name_taken(self): tag = Tag(owner=self.test_user_id, name=self.tag_name) self.session.add(tag) tag2 = Tag(owner=self.test_user_id, name=self.tag_name_new) self.session.add(tag2) self.session.commit() with self.assertRaises(IntegrityError): TagWrapper.rename_tag(self.session, self.test_user_id, self.tag_name, self.tag_name_new)
def setUp(self): self.tag_name_alt = TAGS[1] self.all_tags = TAGS self.test_user_id = TEST_USER_ID engine, Session = startup() self.session = Session() self.test_game_id = TEST_GAME_ID self.test_game_ids = self.create_replay_names() test_user = self.session.query(Player).filter(Player.platformid == self.test_user_id).first() if test_user is None: test_user = Player(platformid=self.test_user_id) self.session.add(test_user) for i in range(len(self.test_game_ids)): tag_name = self.all_tags[i] tag = self.session.query(Tag).filter(Tag.owner == self.test_user_id, Tag.name == tag_name).first() if tag is None: tag = Tag(owner=self.test_user_id, name=tag_name) self.session.add(tag) for game_id in self.test_game_ids: game = self.session.query(Game).filter(Game.hash == game_id).first() if game is None: game = Game(hash=game_id) self.session.add(game) self.session.commit() # add some spice to the games :> for i in range(len(self.test_game_ids)): game_id = self.test_game_ids[i] for j in range(len(self.test_game_ids) - i): TagWrapper.add_tag_to_game(self.session, game_id, self.test_user_id, self.all_tags[j])
def create_tag(session, user_id: str, name: str, private_key: str = None) -> Tag: tag = Tag(name=name, owner=user_id, private_id=private_key) session.add(tag) session.commit() return tag
def test_get_tag_success(self): tag = Tag(owner=self.test_user_id, name=self.tag_name) self.session.add(tag) self.session.commit() tag = TagWrapper.get_tag(self.session, self.test_user_id, self.tag_name) self.assertIsNotNone(tag)
def test_remove_tag_success(self): tag = Tag(owner=self.test_user_id, name=self.tag_name) self.session.add(tag) self.session.commit() TagWrapper.delete_tag(self.session, self.test_user_id, self.tag_name) tag = self.session.query(Tag).filter(Tag.owner == self.test_user_id, Tag.name == self.tag_name).first() self.assertIsNone(tag)
def setUp(self): self.tag_name = TAGS[0] self.tag_name_alt = TAGS[1] self.test_user_id = TEST_USER_ID engine, Session = startup() self.session = Session() self.test_game_id = TEST_GAME_ID test_user = self.session.query(Player).filter(Player.platformid == self.test_user_id).first() if test_user is None: test_user = Player(platformid=self.test_user_id) self.session.add(test_user) tag = self.session.query(Tag).filter(Tag.owner == self.test_user_id, Tag.name == self.tag_name).first() if tag is None: tag = Tag(owner=self.test_user_id, name=self.tag_name) self.session.add(tag) game = self.session.query(Game).filter(Game.hash == self.test_game_id).first() if game is None: game = Game(hash=self.test_game_id) self.session.add(game) self.session.commit()
def create_tag(session, user_id: str, name: str) -> Tag: tag = Tag(name=name, owner=user_id) session.add(tag) session.commit() return tag