def get(attribute, value): if attribute == "films": return swapi.get_film(value).title if attribute == "species": return swapi.get_species(value).name if attribute == "starships": return swapi.get_starship(value).name if attribute == "vehicles": return swapi.get_vehicle(value).name
def test_repr_(self): starship = swapi.get_starship(3) self.assertEquals('<Starship - Star Destroyer>', starship.__repr__()) vehicle = swapi.get_vehicle(4) self.assertEquals('<Vehicle - Sand Crawler>', vehicle.__repr__()) film = swapi.get_film(1) self.assertEquals('<Film - A New Hope>', film.__repr__()) planet = swapi.get_planet(1) self.assertEquals('<Planet - Tatooine>', planet.__repr__()) species = swapi.get_species(1) self.assertEquals('<Species - Human>', species.__repr__())
def gen_dict_info_from_movie(id): movie = swapi.get_film(id) characters = [] planets = [] species = [] spaceships = [] vehicles = [] """ get all characters from a movie and store them """ for person in movie.characters: person_id = person.split('/')[5] characters.append((swapi.get_person(person_id)).name) #print (characters) #print(len(characters)) """ get all planets from a movie and store them """ for planet in movie.planets: planet_id = planet.split('/')[5] planets.append((swapi.get_planet(planet_id)).name) #print (planets) """ get all species from a movie and store them """ for specie in movie.species: specie_id = specie.split('/')[5] species.append((swapi.get_species(specie_id)).name) """ get all starships from a movie and store them """ for spaceship in movie.starships: ship_id = spaceship.split('/')[5] spaceships.append((swapi.get_starship(ship_id)).name) """ get all vehicles from a movie and store them """ for vehicle in movie.vehicles: vehicle_id = vehicle.split('/')[5] vehicles.append((swapi.get_vehicle(vehicle_id)).name) dict = { 'title': movie.title, 'characters': characters, 'planets': planets, 'species': species, 'spaceships': spaceships, 'vehicles': vehicles } return dict
def test_species_get_homeworld(self): species = swapi.get_species(1) self.assertEquals(type(species.get_homeworld()), Planet)
def test_species_get_films(self): species = swapi.get_species(1) self.assertEquals(type(species.get_films()), FilmQuerySet)
def test_species_get_people(self): species = swapi.get_species(1) self.assertEquals(type(species.get_people()), PeopleQuerySet)
def test_get_person_species(self): luke = swapi.get_person(1) species = swapi.get_species(1) human = luke.get_species() self.assertEquals(type(species), Species)