示例#1
0
    def test_get_all_scenes_of_an_experience(self):
        orm_exp = ORMExperience.objects.create(title='Exp a',
                                               description='some description')
        orm_sce_1 = ORMScene.objects.create(title='S1',
                                            description='desc 1',
                                            latitude=Decimal('1.2'),
                                            longitude=Decimal('-3.4'),
                                            experience=orm_exp)
        orm_sce_2 = ORMScene.objects.create(title='S2',
                                            description='desc 2',
                                            latitude=Decimal('5.6'),
                                            longitude=Decimal('-7.8'),
                                            experience=orm_exp)
        ORMScene.objects.create(title='other',
                                description='not belongs to experience',
                                latitude=Decimal('5.6'),
                                longitude=Decimal('-7.8'))

        result = SceneRepo().get_scenes(experience_id=orm_exp.id)

        scene_1 = Scene(id=orm_sce_1.id,
                        title='S1',
                        description='desc 1',
                        picture=None,
                        latitude=Decimal('1.2'),
                        longitude=Decimal('-3.4'),
                        experience_id=orm_exp.id)
        scene_2 = Scene(id=orm_sce_2.id,
                        title='S2',
                        description='desc 2',
                        picture=None,
                        latitude=Decimal('5.6'),
                        longitude=Decimal('-7.8'),
                        experience_id=orm_exp.id)
        assert result == [scene_1, scene_2] or result == [scene_2, scene_1]
示例#2
0
    def test_update_scene(self):
        orm_exp = ORMExperience.objects.create(title='Exp a',
                                               description='some description')
        scene = Scene(title='S1',
                      description='desc 1',
                      latitude=Decimal('0.1'),
                      longitude=Decimal('1.2'),
                      experience_id=str(orm_exp.id))
        created_scene = SceneRepo().create_scene(scene)

        updated_scene = Scene(id=created_scene.id,
                              title='T2',
                              description='updated',
                              latitude=Decimal('3.5'),
                              longitude=Decimal('-2.9'),
                              experience_id=created_scene.experience_id)

        SceneRepo().update_scene(updated_scene)

        orm_scene = ORMScene.objects.get(id=created_scene.id)

        assert updated_scene.title == orm_scene.title
        assert updated_scene.description == orm_scene.description
        assert updated_scene.latitude == orm_scene.latitude
        assert updated_scene.longitude == orm_scene.longitude
        assert updated_scene.experience_id == str(orm_scene.experience_id)
        assert not orm_scene.picture
    def test_invalid_scene_returns_error_and_doesnt_update_it(self):
        scene = Scene(id='1',
                      title='',
                      description='',
                      latitude=0,
                      longitude=0,
                      experience_id=0)
        scene_repo = Mock()
        scene_repo.get_scene.return_value = scene
        scene_validator = Mock()
        scene_validator.validate_scene.side_effect = InvalidEntityException(
            source='s', code='c', message='m')
        updated_scene = Scene(id='1',
                              title='Other',
                              description='some',
                              latitude=3,
                              longitude=8,
                              experience_id=1)

        try:
            ModifySceneInteractor(scene_repo, scene_validator) \
                .set_params(id='1', title='Other', description='some',
                            latitude=3, longitude=8, experience_id=1).execute()
            assert False
        except InvalidEntityException as invalid_exc:
            assert invalid_exc.source == 's'
            assert invalid_exc.code == 'c'
            assert str(invalid_exc) == 'm'
            scene_repo.get_scene.assert_called_once_with(id='1')
            scene_repo.update_scene.assert_not_called()
            scene_validator.validate_scene.assert_called_once_with(
                updated_scene)
    def test_gets_modifies_not_none_params_and_returns_scene(self):
        scene = Scene(id='1',
                      title='Title',
                      description='some',
                      latitude=1,
                      longitude=0,
                      experience_id=1)
        scene_repo = Mock()
        scene_repo.get_scene.return_value = scene

        updated_scene = Scene(id='1',
                              title='Title',
                              description='',
                              latitude=1,
                              longitude=8,
                              experience_id=1)
        scene_repo.update_scene.return_value = updated_scene

        scene_validator = Mock()
        scene_validator.validate_scene.return_value = True

        response = ModifySceneInteractor(scene_repo, scene_validator) \
            .set_params(id='1', title=None, description='', latitude=None, longitude=8, experience_id=1).execute()

        scene_repo.get_scene.assert_called_once_with(id='1')
        scene_repo.update_scene.assert_called_once_with(updated_scene)
        scene_validator.validate_scene.assert_called_once_with(updated_scene)
        assert response == updated_scene
 def given_an_scene(self):
     self.created_scene = Scene(title='Title',
                                description='',
                                latitude=1,
                                longitude=0,
                                experience_id=1)
     return self
 def given_two_scenes(self):
     self.scene_a = Scene(id=2,
                          title='',
                          description='',
                          picture=None,
                          latitude=1,
                          longitude=0,
                          experience_id=1)
     self.scene_b = Scene(id=3,
                          title='',
                          description='',
                          picture=None,
                          latitude=1,
                          longitude=0,
                          experience_id=1)
     return self
 def then_create_scene_is_called_with_previous_params(self):
     scene = Scene(title=self.title,
                   description=self.description,
                   latitude=self.latitude,
                   longitude=self.longitude,
                   experience_id=self.experience_id)
     self.scene_repo.create_scene.assert_called_once_with(scene)
     return self
 def given_an_scene(self):
     self.scene = Scene(id='2',
                        title='T',
                        description='s',
                        latitude=2,
                        longitude=8,
                        experience_id=1)
     return self
示例#9
0
 def given_an_scene(self):
     self._scene = Scene(id='1',
                         title='B',
                         description='some',
                         latitude=Decimal('1.2'),
                         longitude=Decimal('-3.4'),
                         experience_id='1')
     return self
 def given_an_scene(self):
     self.scene = Scene(id='1',
                        title='Title',
                        description='some',
                        latitude=1,
                        longitude=0,
                        experience_id=1)
     return self
示例#11
0
 def given_an_scene(self, id, experience_id):
     self.scenes.append(
         Scene(id=id,
               title='',
               description='',
               latitude=0,
               longitude=0,
               experience_id=experience_id))
     return self
示例#12
0
    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 then_update_scene_should_be_called_with_new_description_an_longitude(
         self):
     new_scene = Scene(id=self.scene.id,
                       title=self.scene.title,
                       description=self.description,
                       latitude=self.scene.latitude,
                       longitude=self.longitude,
                       experience_id=self.scene.experience_id)
     self.scene_repo.update_scene.assert_called_once_with(new_scene)
     return self
示例#14
0
 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
示例#15
0
 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
示例#16
0
 def given_an_scene(self,
                    title='Valid Title',
                    description=None,
                    latitude=1,
                    longitude=1,
                    experience_id=1):
     scene = Scene(title=title,
                   description=description,
                   latitude=latitude,
                   longitude=longitude,
                   experience_id=experience_id)
     self._scene = scene
     return self
    def test_returns_scenes(self):
        scene_a = Scene(id=2,
                        title='',
                        description='',
                        picture=None,
                        latitude=1,
                        longitude=0,
                        experience_id=1)
        scene_b = Scene(id=3,
                        title='',
                        description='',
                        picture=None,
                        latitude=1,
                        longitude=0,
                        experience_id=1)
        scene_repo = Mock()
        scene_repo.get_scenes.return_value = [scene_a, scene_b]

        response = GetScenesFromExperienceInteractor(scene_repo).set_params(
            experience_id=1).execute()

        scene_repo.get_scenes.assert_called_once_with(experience_id=1)
        assert response == [scene_a, scene_b]
示例#18
0
 def given_an_scene(self,
                    title='',
                    description='',
                    latitude=0.0,
                    longitude=0.0,
                    experience_id_of_number=1):
     scene = Scene(
         id=str(len(self.scenes) + 1),
         title=title,
         description=description,
         latitude=latitude,
         longitude=longitude,
         experience_id=self.experiences[experience_id_of_number - 1].id)
     self.scenes.append(scene)
     return self
    def test_creates_and_returns_scene(self):
        scene = Scene(title='Title',
                      description='',
                      latitude=1,
                      longitude=0,
                      experience_id=1)
        scene_repo = Mock()
        scene_repo.create_scene.return_value = scene

        scene_validator = Mock()
        scene_validator.validate_scene.return_value = True

        response = CreateNewSceneInteractor(scene_repo, scene_validator) \
            .set_params(title='Title', description='', latitude=1, longitude=0, experience_id=1).execute()

        scene_repo.create_scene.assert_called_once_with(scene)
        scene_validator.validate_scene.assert_called_once_with(scene)
        assert response == scene
示例#20
0
    def test_get_scene(self):
        orm_exp = ORMExperience.objects.create(title='Exp a',
                                               description='some description')
        orm_sce_1 = ORMScene.objects.create(title='S1',
                                            description='desc 1',
                                            latitude=Decimal('1.2'),
                                            longitude=Decimal('-3.4'),
                                            experience=orm_exp)

        result = SceneRepo().get_scene(id=orm_sce_1.id)

        scene_1 = Scene(id=orm_sce_1.id,
                        title='S1',
                        description='desc 1',
                        picture=None,
                        latitude=Decimal('1.2'),
                        longitude=Decimal('-3.4'),
                        experience_id=orm_exp.id)
        assert result == scene_1
    def test_invalid_scene_returns_error_and_doesnt_create_it(self):
        scene = Scene(title='',
                      description='',
                      latitude=0,
                      longitude=0,
                      experience_id=0)
        scene_repo = Mock()
        scene_validator = Mock()
        scene_validator.validate_scene.side_effect = InvalidEntityException(
            source='s', code='c', message='m')

        try:
            CreateNewSceneInteractor(scene_repo, scene_validator) \
                .set_params(title='', description='', latitude=0, longitude=0, experience_id=0).execute()
            assert False
        except InvalidEntityException as invalid_exc:
            assert invalid_exc.source == 's'
            assert invalid_exc.code == 'c'
            assert str(invalid_exc) == 'm'
            scene_repo.create_scene.assert_not_called()
            scene_validator.validate_scene.assert_called_once_with(scene)
    def test_create_new_scene(self):
        orm_person = ORMPerson.objects.create(username='******')
        orm_exp = ORMExperience.objects.create(title='Exp a',
                                               description='some description',
                                               author=orm_person)
        scene = Scene(title='S1',
                      description='desc 1',
                      latitude=Decimal('0.1'),
                      longitude=Decimal('1.2'),
                      experience_id=str(orm_exp.id))

        created_scene = SceneRepo().create_scene(scene)

        orm_scene = ORMScene.objects.get(id=created_scene.id)

        assert scene.title == orm_scene.title
        assert scene.description == orm_scene.description
        assert scene.latitude == orm_scene.latitude
        assert scene.longitude == orm_scene.longitude
        assert scene.experience_id == str(orm_scene.experience_id)
        assert not orm_scene.picture