def test_create_ask(self): with factories.TransferTypeRepository() as transaction_type_repository: transaction_type = transaction_type_repository.create(code='create_ask', silver_points=55) user_from = factories.UserFactory(silver_points=100, username='******') card_to = factories.DeckFactory(silver_points=0) self.call_target( user_from=user_from.id, card_to=card_to.id, transaction_type=transaction_type.code ) self.assertEqual( factories.UserFactory.get(user_from.id), factories.UserFactory.build(id=user_from.id, silver_points=100 - transaction_type.silver_points, username='******') ) self.assertEqual( factories.CardFactory.get(card_to.id), factories.CardFactory.build(id=card_to.id, silver_points=0) ) tr = factories.Transfer.get()[0] self.assertEqual( tr, factories.Transfer.build( id=tr.id, user_from=user_from, card_to=card_to, silver_points=transaction_type.silver_points, transaction_type=transaction_type.code, ) )
def test_success(self): deck = factories.DeckFactory( name='test_deck', is_ask_mode_enabled=True, evaluation_period_status=card_module.EVALUATION_PERIOD_STATUS_OPEN) self.db.session.add(deck) question = factories.CardFactory(name='question') self.db.session.add(question) deck.cards.append(question) answer1 = factories.CardFactory(name='answer1') self.db.session.add(answer1) deck.cards.append(answer1) answer2 = factories.CardFactory(name='answer2') self.db.session.add(answer2) deck.cards.append(answer2) self.db.session.commit() data = {'card_id': answer1.id} response = self.client.post('/api/v1/deck/revoke_card_from_deck', data=json.dumps(data), follow_redirects=True, content_type='application/json') self.assertEqual(response.status, '200 OK') deck = Card.query.get(deck.id) self.assertEqual(len(deck.cards), 2) self.assertEqual(deck.cards[0].id, question.id) self.assertEqual(deck.cards[1].id, answer2.id)
def test_deck_deck_card_structure(self): deck = factories.DeckFactory(id="deck", is_ask_mode_enabled=True) container = factories.DeckFactory(id='container', parent=deck, is_ask_mode_enabled=False) factories.CardFactory(id='card', parent=container) self.db.session.commit() res = deck.to_dict() self.assertEqual(res['id'], 'deck') self.assertEqual(len(res['children']), 1) c = res['children'][0] self.assertEqual(c['id'], 'container') self.assertEqual(len(c['children']), 1) ca = c['children'][0] self.assertEqual(ca['id'], 'card') self.assertNotIn('children', ca)
def test_edit_deck(self): deck = factories.DeckFactory(name="test_deck", creator=self.user) self.db.session.add(deck) self.db.session.commit() data = {'deck_id': deck.id, 'card_ids': [], 'tags': ['tag1', 'tag2']} response = self.client.post('/api/v1/deck/edit_deck', data=json.dumps(data), follow_redirects=True, content_type='application/json') self.assertEqual(response.status, '200 OK') deck = Card.query.get(deck.id) self.assertEqual(deck.name, 'test_deck') self.assertEqual(len(deck.tags), 2) self.assertEqual([tag.name for tag in deck.tags], ['tag1', 'tag2'])
def test_card_should_not_published(self): deck = factories.DeckFactory(published=True, creator=self.user) card1 = factories.CardFactory(parent=deck) card2 = factories.CardFactory(parent=deck) self.db.session.commit() self.assertEqual(card1.position, 0) self.assertEqual(card2.position, 1) result = self.call_target(card_id=card1.id, position=1) self.assertEqual( result, factories.JsonResponseWithResultStatusFactory.build( data={ 'result': 'error', 'message': u'Card deck is published. you can not change order' }))
def test_succcess(self): deck = factories.DeckFactory(creator=self.user) card1 = factories.CardFactory(parent=deck) card2 = factories.CardFactory(parent=deck) card3 = factories.CardFactory(parent=deck) self.db.session.commit() self.assertEqual(card1.position, 0) self.assertEqual(card2.position, 1) self.assertEqual(card3.position, 2) result = self.call_target(card_id=card1.id, position=1) self.assertEqual(result, factories.JsonResponseWithResultStatusFactory.build()) card1 = factories.CardFactory.get(card1.id) self.assertEqual(card1.position, 1) self.assertEqual(card2.position, 0) self.assertEqual(card3.position, 2)
def test_enable_ask_mode_for_deck(self): deck = factories.DeckFactory(name="deck_name") card = factories.CardFactory(parent=deck, name="card_name") self.call_target(data=dict(deck_id=deck.id, is_ask_mode_enabled=True)) # TO DO check response card = factories.CardFactory.get(card.id) self.assertEqual(card.type, Card.TEXT) self.assertEqual(card.is_ask_mode_enabled, False) self.assertEqual(card.name, "card_name") container = card.parent self.assertEqual(container.type, Card.DECK) self.assertEqual(container.name, "deck_name") self.assertEqual(container.is_ask_mode_enabled, False) ask_mode_deck = container.parent self.assertEqual(ask_mode_deck.type, Card.DECK) self.assertEqual(ask_mode_deck.name, "deck_name") self.assertEqual(ask_mode_deck.is_ask_mode_enabled, True)