def setUp(self): self.nemo = Fish("Nemo") self.dory = Fish("Dory") self.marlin = Fish("Marlin") self.nile = River("Nile") self.baloo = Bear("Baloo") self.nile.add_fish(self.nemo) self.nile.add_fish(self.dory)
class TestBear(TestCase): def setUp(self): self.nemo = Fish("Nemo") self.dory = Fish("Dory") self.marlin = Fish("Marlin") self.nile = River("Nile") self.baloo = Bear("Baloo") self.nile.add_fish(self.nemo) self.nile.add_fish(self.dory) def test_can_get_name(self): self.assertEqual(self.baloo.get_name(), "Baloo") def test_can_count_stomach_contents(self): self.assertEqual(self.baloo.count_stomach_contents(), 0) def test_can_add_fish_to_stomach(self): self.baloo.eat_fish(self.marlin) self.assertEqual(self.baloo.count_stomach_contents(), 1) def test_can_see_stomach_contents(self): self.baloo.eat_fish(self.marlin) self.assertEqual(self.baloo.get_stomach_contents(), [self.marlin]) def test_can_be_sick(self): self.baloo.eat_fish(self.marlin) self.baloo.be_sick() self.assertEqual(self.baloo.count_stomach_contents(), 0) def test_bear_can_eat_fish_from_river(self): self.baloo.eat_fish(self.marlin) self.baloo.eat_fish_from_river(self.nemo, self.nile) self.assertEqual(self.baloo.get_stomach_contents(), [self.marlin, self.nemo]) self.assertEqual(self.nile.count_fish(), 1)
from ex1 import mlab_connect from models.river import River mlab_connect() rivers = River.objects(continent = 'Africa') if len(rivers) == 0: print("Not found") else: for river in rivers: print(river)
def s_america(): all_rivers = River.objects(continent="S. America", lenght__lt=1000) return render_template('rivers.html', all_rivers=all_rivers)
from pymongo import * import mlab from models.river import River mlab.connect() all_rivers_in_africa = River.objects() for river in all_rivers_in_africa: if river['continent'] == 'S. America' and river['length'] < 1000: print(river['name'])
def river_america(): name_list = River.objects(continent="S. America", length__lt=1000) return render_template("ex23.html", name_list=name_list)
def africa(): all_rivers = River.objects(continent="Africa") return render_template('rivers.html', all_rivers=all_rivers)
def rivers1(): africa_river_list = River.objects(continent__icontains="S. America", length__lt=1000) return render_template("rivers1.html", africa_river_list=africa_river_list)
def river_africa(): river_list = River.objects(continent='Africa') return render_template("river.html",river_list=river_list)
from models.river import River import mlab7 mlab7.connect() SA_river = River.objects(continent = "S. America") for river in SA_river: if river["length"] <= 1000: print(river["name"]) print("- "*10)
from models.river import River import mlab7 mlab7.connect() Africa_river = River.objects(continent="Africa") for river in Africa_river: print(river["name"]) print(river["length"]) print("- " * 10)
def setUp(self): self.nile = River("Nile") self.nemo = Fish("Nemo") self.dory = Fish("Dory")
from models.river import River import river.mlab river.mlab.connect() river_SA_1000 = River.objects(continent = "S. America", length__lt=1000) for river in river_SA_1000: print(river.name) print(river.length) print("*" * 10)
class TestRiver(TestCase): def setUp(self): self.nile = River("Nile") self.nemo = Fish("Nemo") self.dory = Fish("Dory") def test_can_get_name(self): self.assertEqual(self.nile.get_name(), "Nile") def test_can_add_fish(self): self.nile.add_fish(self.nemo) self.assertEqual(self.nile.count_fish(), 1) def test_can_remove_fish(self): self.nile.add_fish(self.nemo) self.nile.remove_fish(self.nemo) self.assertEqual(self.nile.count_fish(), 0) def test_can_remove_all_fish(self): self.nile.add_fish(self.nemo) self.nile.add_fish(self.dory) self.nile.remove_all_fish() self.assertEqual(self.nile.count_fish(), 0)
from models.river import River import mlab7 mlab7.connect() river_in_SAmerica_lt1000km = River.objects(continent="S. America", length__lt=1000) for river in river_in_SAmerica_lt1000km: print(river.name) print(river.length) print("* " * 20)
from mlab import mlab_connect from models.river import River mlab_connect() african_rivers = River.objects(continent="Africa") for river in african_rivers: print(river) samerican_rivers_1000 = River.objects(continent='S. America', length__lt=1000) for river in samerican_rivers_1000: print(river)
import mlab from models.river import River mlab.connect() print("ex2") river_list = River.objects(continent__iexact="Africa") for river in river_list: print(river.name) print("ex3") river_list = River.objects(continent__iexact="S. America", length__lt=1000) for river in river_list: print(river.name, river.length)
import mlab from models.river import River mlab.connect() Africa_river_list = River.objects(continent__icontains="Africa") print("all river in Africa: ", end="") for river in Africa_river_list: print(river.name, end=", ") print() print() S_America_river_list = River.objects(continent__icontains="S. America", length__lt=1000) print("all river in S.America with length less than 1000km: ", end="") for river in S_America_river_list: print(river.name, end=", ")
import mlab from models.river import River mlab7.connect() #Ex8 river_in_Africa = River.objects(continent="Africa") print(river_in_Africa) #Ex9 river_less_than_1000 = River.objects(continent="S. America", length__lt=1000) print(river_less_than_1000)
from models.river import River import mlab7 mlab7.connect() all_river_s = River.objects(continent="S. America", length=1000) for river2 in all_river_s: print(river2.name) print()
def rivers(): africa_river_list = River.objects(continent__icontains="Africa") return render_template("rivers.html", africa_river_list=africa_river_list)
from models.river import River import mlab1 mlab1.connect() rivers = River.objects(continent = "Africa") print ("All river in Africa") for item in rivers: print(item.name) print("-" * 20) print ("All river in S.America with length less than 1000km") short_river = River.objects(continent ="S. America",length__lt = 1000) for item in short_river: print(item.name,':',item.length)
def river_samerica(): river_list = River.objects(continent='S.America',length__lt=100) return render_template('river.html',river_list=river_list)
from ex1 import mlab_connect from models.river import River mlab_connect() rivers = River.objects(continent='S. America', length__lt=1000) if len(rivers) == 0: print("Not found") else: for river in rivers: print(river, river.length)
from models.river import River import mlab7 mlab7.connect() river_in_Africa = River.objects(continent="Africa") for river in river_in_Africa: print(river.name) print(river.length) print("* " * 20)
def river(): name_list = River.objects(continent="Africa") return render_template("ex23.html", name_list=name_list)