Exemplo n.º 1
0
	def test_show_user_cards_by_manacost(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card_1 = Cards.query.filter_by(name = 'Black Lotus').first()
		card_2 = Cards.query.filter_by(name = 'Animate Dead').first()
		card_1.owner.append(user)
		card_2.owner.append(user)
		db.session.commit()

		response_1 = self.client.get('/manacost/eric/?manacost=0')
		response_2 = self.client.get('/manacost/eric/?manacost=B1')

		flat_response_1 = response_1.data.replace('\n', '')
		flat_response_1 = flat_response_1.replace(' ','')
		r_1 = json.dumps(dict(names=['Black Lotus'], url = ['https://magic.objects.liquidweb.services/en4vma.jpg']))
		r_1 = r_1.replace(' ', '')

		flat_response_2 = response_2.data.replace('\n', '')
		flat_response_2 = flat_response_2.replace(' ','')
		r_2 = json.dumps(dict(names=['Animate Dead'], url = ['https://magic.objects.liquidweb.services/en78ema.jpg']))
		r_2 = r_2.replace(' ', '')

		self.assertEqual(r_1, flat_response_1)
		self.assertEqual(r_2, flat_response_2)
Exemplo n.º 2
0
def add_user():

    user_input = request.get_json()
    user_username = user_input['username']
    user_email = user_input['email']
    dbcreate = Users(user_username, user_email)

    db.session.add(dbcreate)
    db.session.commit()

    return 'User %s added' % user_username
Exemplo n.º 3
0
	def test_show_user_clan(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()

		user_table = Users.query.filter_by(username = '******').first()
		clan_table = Clans.query.filter_by(clan_name = 'Golgari').first()
		clan_table.user_ref.append(user_table)

		response = self.client.get('/clan/eric')

		self.assertEqual('Your clan is Golgari', response.data)
Exemplo n.º 4
0
	def test_show_cards_users(self):
		
		user = Users('Eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card = Cards.query.filter_by(name = 'Canyon Slough').first()
		card.owner.append(user)
		response = self.client.get('/users/?name=Canyon Slough')

		flat_response = response.data.replace('\n', '')
		flat_response = flat_response.replace(' ', '')
		r = json.dumps(dict(usernames = ['Eric']))
		r = r.replace(' ', '')
		self.assertEqual(r, flat_response)
Exemplo n.º 5
0
	def test_delete_user_card(self):

		user_1 = Users('eric','*****@*****.**')
		db.session.add(user_1)
		db.session.commit()
		card = Cards.query.filter_by(name = 'Luxa River Shrine').first()
		card.owner.append(user_1)

		user_2 = Users('bela','*****@*****.**')
		db.session.add(user_2)
		db.session.commit()
		card.owner.append(user_2)

		response = self.client.delete('/delete/card/eric', data = json.dumps(dict(name = 'Luxa River Shrine')),
																			    content_type = 'application/json')
		
		user_2_t = Users.query.filter_by(username = '******').first()
		user_1_t = Users.query.filter_by(username = '******').first()
		user_2_cards = user_2_t.user_cards
		user_1_cards = user_1_t.user_cards
		self.assertEqual('Luxa River Shrine removed from user eric', response.data)
		self.assertEqual(user_2_cards[0].name, 'Luxa River Shrine')
		self.assertEqual(user_1_cards, [])
Exemplo n.º 6
0
	def test_show_user_cards_by_manacost_color(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card_1 = Cards.query.filter_by(name = 'Black Vise').first()
		card_1.owner.append(user)

		response = self.client.get('/manacost/colors/eric/?manacost=1&colors=empty')
		flat_response = response.data.replace('\n', '')
		flat_response = flat_response.replace(' ', '')

		r = json.dumps(dict(names = ['Black Vise'], url = ['https://magic.objects.liquidweb.services/en33smpskld.jpg']))
		r = r.replace(' ','')
		self.assertEqual(r, flat_response)
Exemplo n.º 7
0
	def test_show_user_cards_by_text(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card = Cards.query.filter_by(name = 'Armageddon').first()
		card.owner.append(user)

		response = self.client.get('/text/eric/?text=destroy')
		flat_response = response.data.replace('\n', '')
		flat_response = flat_response.replace(' ', '')

		r = json.dumps(dict(names = ['Armageddon'], url = ['https://magic.objects.liquidweb.services/en1v14.jpg']))
		r = r.replace(' ','')
		self.assertEqual(r, flat_response)
Exemplo n.º 8
0
	def test_show_user_cards_by_colors(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card = Cards.query.filter_by(name = 'Bad Moon').first()
		card.owner.append(user)

		response = self.client.get('/colors/eric/?colors=Black')
		flat_response = response.data.replace('\n', '')
		flat_response = flat_response.replace(' ', '')

		r = json.dumps(dict(names = ['Bad Moon'], url = ["https://magic.objects.liquidweb.services/en48ddagvl.jpg"]))
		r = r.replace(' ', '')
		self.assertEqual(r, flat_response)
Exemplo n.º 9
0
	def test_show_user_cards(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card = Cards.query.filter_by(name = 'Graceful Cat').first()
		card.owner.append(user)
		db.session.commit()

		response = self.client.get('/cards/eric')
		flat_response = response.data.replace('\n','')
		flat_response = flat_response.replace(' ','')

		r = json.dumps(dict(names = ['Graceful Cat'], url = ["https://magic.objects.liquidweb.services/pt273akh.jpg"]))
		r = r.replace(' ','')
		self.assertEqual(r, flat_response)
Exemplo n.º 10
0
	def test_show_user_cards_by_colors_text(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card_1 = Cards.query.filter_by(name = 'Luxa River Shrine').first()
		card_1.owner.append(user)


		response = self.client.get('/colors/text/eric/?colors=empty&text=life')
		flat_response = response.data.replace('\n', '')
		flat_response = flat_response.replace(' ', '')

		r = json.dumps(dict(names = ['Luxa River Shrine'], url = ['https://magic.objects.liquidweb.services/pt232akh.jpg']))
		r = r.replace(' ','')
		self.assertEqual(r, flat_response)
Exemplo n.º 11
0
	def test_show_user_cards_by_subtypes(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card_1 = Cards.query.filter_by(name = 'Badlands').first()
		card_1.owner.append(user)
		card_2 = Cards.query.filter_by(name = 'Bayou').first()
		card_2.owner.append(user)

		response = self.client.get('/subtypes/eric/?subtypes=Swamp,Mountain')
		flat_response = response.data.replace('\n', '')
		flat_response = flat_response.replace(' ', '')

		r = json.dumps(dict(names = ['Badlands'], url = ['https://magic.objects.liquidweb.services/en291vma.jpg']))
		r = r.replace(' ','')
		self.assertEqual(r, flat_response)
Exemplo n.º 12
0
	def test_add_user_to_clan(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()

		response = self.client.post('/addclan/eric', data = json.dumps(dict(clan = 'Rakdos')),
																		    content_type = 'application/json')
		
		user_clan = user.my_clan
		clan = Clans.query.filter_by(clan_name = 'Rakdos').first()
		self.assertEqual('Clan Rakdos added to User eric', response.data)
		self.assertEqual(user_clan, clan.clan_id)

		response = self.client.post('/addclan/eric', data = json.dumps(dict(clan = 'Gruul')),
																			content_type = 'application/json')

		self.assertEqual('You already have a clan (Rakdos)!', response.data)
Exemplo n.º 13
0
	def test_add_cards_to_user(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		response = self.client.post('/addcard/eric', data = json.dumps(dict(name=['Graceful Cat','Animate Artifact'])),
							 												content_type = 'application/json')
		user_table = Users.query.filter_by(username = '******').first()
		card_names = []
		for card in user_table.user_cards:
			card_names.append(card.name)

		flat_response = response.data.replace('\n', '')
		flat_response = flat_response.replace(' ','')
		r = json.dumps(dict(names=['Graceful Cat','Animate Artifact']))
		r = r.replace(' ', '')
		self.assertEqual(r, flat_response)
		self.assertEqual(['Graceful Cat', 'Animate Artifact'], card_names)
Exemplo n.º 14
0
	def test_show_clan_users(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()

		user_table = Users.query.filter_by(username = '******').first()
		clan_table = Clans.query.filter_by(clan_name = 'Selesnya').first()
		clan_table.user_ref.append(user_table)

		response = self.client.get('/clan/users/Selesnya')

		flat_response = response.data.replace('\n', '')
		flat_response = flat_response.replace(' ','')

		r = json.dumps(dict(users = ['eric']))
		r = r.replace(' ','')

		self.assertEqual(r, flat_response)
Exemplo n.º 15
0
	def test_update_user_clan(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()

		user_table = Users.query.filter_by(username = '******').first()
		clan_table = Clans.query.filter_by(clan_name = 'Golgari').first()
		clan_table.user_ref.append(user_table)
		old_clan_name = clan_table.clan_name

		response = self.client.put('/clan/update/eric', data = json.dumps(dict(clan = 'Rakdos')),
																			   content_type = 'application/json')
		new_clan_table = Clans.query.filter_by(clan_name = 'Rakdos').first()
		new_clan_name = new_clan_table.clan_name
		new_clan_id = new_clan_table.clan_id
		user_clan = user_table.my_clan

		self.assertEqual('You changed from %s to %s' % (old_clan_name, new_clan_name),response.data)
		self.assertEqual(user_clan,new_clan_id)
Exemplo n.º 16
0
	def test_show_user_card_colors(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card = Cards.query.filter_by(name = 'Armageddon').first()
		card.owner.append(user)

		response = self.client.get('/name/eric/?name=Armageddon')
		flat_response = response.data.replace('\n', '')
		flat_response = flat_response.replace(' ', '')
		r = json.dumps(dict(colors="[White]",
                            mana_cost="3W",
                            name="Armageddon",
                            subtypes="[empty]",
                            text="Destroy all lands.",
                            types= "[Sorcery]",
                            img_url = "https://magic.objects.liquidweb.services/en1v14.jpg"))
		r = r.replace(' ', '')
		self.assertEqual(r, flat_response)
Exemplo n.º 17
0
	def test_delete_user(self):

		user = Users('eric','*****@*****.**')
		db.session.add(user)
		db.session.commit()
		card_1 = Cards.query.filter_by(name = 'Luxa River Shrine').first()
		card_1.owner.append(user)

		user_id = user.user_id
		card_id = card_1.card_id

		response = self.client.delete('/delete/eric')
		deleted_user = Users.query.filter_by(user_id = user_id).first()
		remaining_card = Cards.query.filter_by(card_id = card_id).first()
		remaining_card_name = remaining_card.name
		no_user_counter = 0
		for user in remaining_card.owner:
			no_user_counter=+1

		self.assertEqual('User with id = %s deleted' % user_id,response.data)
		self.assertEqual(None, deleted_user)
		self.assertEqual(no_user_counter,0)
		self.assertEqual('Luxa River Shrine', remaining_card_name)