def test_returns_experiences_serialized_and_200(self): picture_a = Picture(small_url='small.a', medium_url='medium.a', large_url='large.a') experience_a = Experience(id=1, title='A', description='some', picture=picture_a) picture_b = Picture(small_url='small.b', medium_url='medium.b', large_url='large.b') experience_b = Experience(id=2, title='B', description='other', picture=picture_b) interactor_mock = Mock() interactor_mock.execute.return_value = [experience_a, experience_b] body, status = ExperiencesView( get_all_experiences_interactor=interactor_mock).get() assert status == 200 assert body == [ { 'id': '1', 'title': 'A', 'description': 'some', 'picture': { 'small_url': 'small.a', 'medium_url': 'medium.a', 'large_url': 'large.a' } }, { 'id': '2', 'title': 'B', 'description': 'other', 'picture': { 'small_url': 'small.b', 'medium_url': 'medium.b', 'large_url': 'large.b' } }, ]
def test_returns_scenes_serialized_and_200(self): picture_b = Picture(small_url='small.b', medium_url='medium.b', large_url='large.b') picture_c = Picture(small_url='small.c', medium_url='medium.c', large_url='large.c') scene_b = Scene(id=1, title='B', description='some', picture=picture_b, latitude=Decimal('1.2'), longitude=Decimal('-3.4'), experience_id=1) scene_c = Scene(id=2, title='C', description='other', picture=picture_c, latitude=Decimal('5.6'), longitude=Decimal('-7.8'), experience_id=1) interactor_mock = Mock() interactor_mock.set_params.return_value = interactor_mock interactor_mock.execute.return_value = [scene_b, scene_c] body, status = ScenesView(interactor_mock).get(experience='1') interactor_mock.set_params.assert_called_once_with(experience_id='1') assert status == 200 assert body == [ { 'id': '1', 'title': 'B', 'description': 'some', 'picture': { 'small_url': 'small.b', 'medium_url': 'medium.b', 'large_url': 'large.b', }, 'latitude': 1.2, 'longitude': -3.4, 'experience_id': '1', }, { 'id': '2', 'title': 'C', 'description': 'other', 'picture': { 'small_url': 'small.c', 'medium_url': 'medium.c', 'large_url': 'large.c', }, 'latitude': 5.6, 'longitude': -7.8, 'experience_id': '1', } ]
def _decode_db_experience(self, db_experience): if not db_experience.picture: picture = None else: picture = Picture(small_url=db_experience.picture.small.url, medium_url=db_experience.picture.medium.url, large_url=db_experience.picture.large.url) return Experience(id=db_experience.id, title=db_experience.title, description=db_experience.description, picture=picture)
def given_another_scene(self): pic = Picture(small_url='small.c', medium_url='medium.c', large_url='large.c') self._second_scene = Scene(id=2, title='C', description='other', picture=pic, latitude=Decimal('5.6'), longitude=Decimal('-7.8'), experience_id=1) return self
def given_an_scene(self): pic = Picture(small_url='small.b', medium_url='medium.b', large_url='large.b') self._scene = Scene(id='1', title='B', description='some', picture=pic, latitude=Decimal('1.2'), longitude=Decimal('-3.4'), experience_id='1') return self
def _decode_db_scene(self, db_scene): if not db_scene.picture: picture = None else: picture = Picture(small_url=db_scene.picture.small.url, medium_url=db_scene.picture.medium.url, large_url=db_scene.picture.large.url) return Scene(id=db_scene.id, title=db_scene.title, description=db_scene.description, picture=picture, latitude=db_scene.latitude, longitude=db_scene.longitude, experience_id=db_scene.experience_id)
def _decode_db_experience(self, db_experience, is_mine=False, is_saved=False): if not db_experience.picture: picture = None else: picture = Picture(small_url=db_experience.picture.small.url, medium_url=db_experience.picture.medium.url, large_url=db_experience.picture.large.url) return Experience(id=db_experience.id, title=db_experience.title, description=db_experience.description, picture=picture, author_id=db_experience.author.id, author_username=db_experience.author.username, is_mine=is_mine, is_saved=is_saved)
def given_an_experience_b(self): picture_b = Picture(small_url='small.b', medium_url='medium.b', large_url='large.b') self.experience_b = Experience(id=2, title='B', description='other', picture=picture_b, author_id='5', author_username='******') return self
def given_an_experience_a(self): picture_a = Picture(small_url='small.a', medium_url='medium.a', large_url='large.a') self.experience_a = Experience(id=1, title='A', description='some', picture=picture_a, author_id='4', author_username='******') return self