Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
 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__())
Ejemplo n.º 3
0
 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__())
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
 def test_species_get_homeworld(self):
     species = swapi.get_species(1)
     self.assertEquals(type(species.get_homeworld()), Planet)
Ejemplo n.º 6
0
 def test_species_get_films(self):
     species = swapi.get_species(1)
     self.assertEquals(type(species.get_films()), FilmQuerySet)
Ejemplo n.º 7
0
 def test_species_get_people(self):
     species = swapi.get_species(1)
     self.assertEquals(type(species.get_people()), PeopleQuerySet)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 def test_species_get_people(self):
     species = swapi.get_species(1)
     self.assertEquals(type(species.get_people()), PeopleQuerySet)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 def test_species_get_homeworld(self):
     species = swapi.get_species(1)
     self.assertEquals(type(species.get_homeworld()), Planet)
Ejemplo n.º 12
0
 def test_species_get_films(self):
     species = swapi.get_species(1)
     self.assertEquals(type(species.get_films()), FilmQuerySet)