Esempio n. 1
0
        def given_an_experience_from_blocked_person(self,
                                                    title='',
                                                    description='',
                                                    saves_count=0):
            experience = Experience(id=str(len(self.experiences) + 1),
                                    title=title,
                                    description=description,
                                    author_id=self.orm_blocked_person.id,
                                    author_profile=Profile(
                                        person_id=self.orm_blocked_person.id,
                                        username='******',
                                        bio='cked',
                                        picture=None,
                                        is_me=False),
                                    saves_count=saves_count,
                                    is_mine=False)

            db_experience = ExperienceRepo().create_experience(experience)
            ORMExperience.objects.filter(id=db_experience.id).update(
                saves_count=saves_count)

            experience = experience.builder().id(db_experience.id).build()
            self.experiences.append(experience)

            return self
 def given_another_experience_in_db(self):
     self.orm_experience_b = ORMExperience.objects.create(
         title='Exp b',
         description='other description',
         author=self.orm_person)
     self.experience_b = Experience(
         id=self.orm_experience_b.id,
         title='Exp b',
         description='other description',
         author_id=self.orm_person.id,
         author_username=self.orm_person.username)
     return self
 def given_an_experience_created_by_second_person_in_db(self):
     self.orm_experience_c = ORMExperience.objects.create(
         title='Exp c',
         description='description',
         author=self.second_orm_person)
     self.experience_c = Experience(
         id=self.orm_experience_c.id,
         title='Exp c',
         description='description',
         author_id=self.second_orm_person.id,
         author_username=self.second_orm_person.username)
     return self
 def given_an_experience_in_db(self):
     self.orm_experience_a = ORMExperience.objects.create(
         title='Exp a',
         description='some description',
         author=self.orm_person)
     self.experience_a = Experience(
         id=self.orm_experience_a.id,
         title='Exp a',
         description='some description',
         author_id=self.orm_person.id,
         author_username=self.orm_person.username)
     return self
 def given_an_experience(self):
     self.experience = Experience(id='1',
                                  title='Title',
                                  description='some',
                                  author_id='2',
                                  author_username='******')
     return self
 def then_params_should_be_validated(self):
     experience_params = Experience(title=self.title,
                                    description=self.description,
                                    author_id=self.logged_person_id)
     self.experience_validator.validate_experience.assert_called_once_with(
         experience_params)
     return self
Esempio n. 7
0
    def test_returns_repo_response(self):
        experience_a = Experience(id=1,
                                  title='A',
                                  description='some',
                                  picture=None)
        experience_b = Experience(id=2,
                                  title='B',
                                  description='other',
                                  picture=None)
        experiences_repo = Mock()
        experiences_repo.get_all_experiences = Mock(
            return_value=[experience_a, experience_b])

        response = GetAllExperiencesInteractor(experiences_repo).execute()

        assert response == [experience_a, experience_b]
Esempio n. 8
0
 def given_an_experience_in_db(self):
     self._orm_experience_a = ORMExperience.objects.create(
         title='Exp a', description='some description')
     self._experience_a = Experience(id=self._orm_experience_a.id,
                                     title='Exp a',
                                     description='some description')
     return self
 def given_an_experience_to_create(self):
     self.experience_to_create = Experience(
         id="",
         title='Exp a',
         description='some description',
         author_id=self.orm_person.id)
     return self
Esempio n. 10
0
 def when_create_experience(self, title, description, author):
     orm_author = self.persons[author - 1]
     experience = Experience(title=title,
                             description=description,
                             author_id=str(orm_author.id))
     self.result = self.repo.create_experience(experience)
     return self
Esempio n. 11
0
 def given_an_interactor_that_returns(self, id):
     self.interactor = Mock()
     self.interactor.set_params.return_value = self.interactor
     self.interactor.execute.return_value = Experience(id=id,
                                                       title='',
                                                       description='')
     return self
 def then_repo_create_method_should_be_called_with_params(self):
     experience_params = Experience(title=self.title,
                                    description=self.description,
                                    author_id=self.logged_person_id)
     self.experience_repo.create_experience.assert_called_once_with(
         experience_params)
     return self
Esempio n. 13
0
 def given_another_experience_in_db(self):
     self._orm_experience_b = ORMExperience.objects.create(
         title='Exp b', description='other description')
     self._experience_b = Experience(id=self._orm_experience_b.id,
                                     title='Exp b',
                                     description='other description')
     return self
Esempio n. 14
0
 def given_an_experience_with_different_author_than_logged_person_id(
         self):
     self.experience = Experience(id='1',
                                  title='t',
                                  description='d',
                                  author_id='33')
     return self
 def given_an_updated_experience(self):
     self.updated_experience = Experience(
         id=self.experience_a.id,
         title='T2',
         description='updated',
         author_id=self.orm_person.id,
         author_username=self.orm_person.username)
     return self
Esempio n. 16
0
    def test_get_all_experiences_returns_all_experiences(self):
        orm_exp_a = ORMExperience.objects.create(
            title='Exp a', description='some description')
        orm_exp_b = ORMExperience.objects.create(
            title='Exp b', description='other description')

        result = ExperienceRepo().get_all_experiences()

        exp_a = Experience(id=orm_exp_a.id,
                           title='Exp a',
                           description='some description',
                           picture=None)
        exp_b = Experience(id=orm_exp_b.id,
                           title='Exp b',
                           description='other description',
                           picture=None)
        assert result == [exp_a, exp_b]
Esempio n. 17
0
 def given_an_experience(self, title='', description='', saves_count=0):
     experience = Experience(id=str(len(self.experiences) + 1),
                             title=title,
                             description=description,
                             author_id='0',
                             saves_count=saves_count)
     self.experiences.append(experience)
     return self
Esempio n. 18
0
 def given_an_experience(self,
                         title='Valid Title',
                         description=None,
                         author_id='2'):
     self._experience = Experience(title=title,
                                   description=description,
                                   author_id=author_id)
     return self
 def given_an_experience_repo_that_returns_own_experience(self):
     others_experience = Experience(id='4',
                                    title='t',
                                    description='d',
                                    author_id=self.logged_person_id)
     self.experience_repo = Mock()
     self.experience_repo.get_experience.return_value = others_experience
     return self
 def given_another_experience(self):
     self.experience_b = Experience(id=2,
                                    title='B',
                                    description='other',
                                    picture=None,
                                    author_id='1',
                                    author_username='******')
     return self
 def given_an_experience(self):
     self.experience_a = Experience(id=1,
                                    title='A',
                                    description='some',
                                    picture=None,
                                    author_id='1',
                                    author_username='******')
     return self
 def given_another_experience_updated_with_that_params(self):
     self.updated_experience = Experience(
         id=self.experience.id,
         title=self.experience.title,
         description=self.description,
         author_id=self.experience.author_id,
         author_username=self.experience.author_username)
     return self
Esempio n. 23
0
    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'
                }
            },
        ]
Esempio n. 24
0
 def given_an_experience(self):
     self._experience = Experience(id='1',
                                   title='B',
                                   description='some',
                                   author_id='3',
                                   author_profile=Profile(username='******',
                                                          bio='bb',
                                                          is_me=True))
     return self
Esempio n. 25
0
 def execute(self):
     self.permissions_validator.validate_permissions(
         logged_person_id=self.logged_person_id,
         wants_to_create_content=True)
     experience = Experience(title=self.title,
                             description=self.description,
                             author_id=self.logged_person_id)
     self.experience_validator.validate_experience(experience)
     return self.experience_repo.create_experience(experience)
 def given_an_experience_repo_that_returns_true_on_save_and_others_experience(
         self):
     others_experience = Experience(id='4',
                                    title='t',
                                    description='d',
                                    author_id='3')
     self.experience_repo = Mock()
     self.experience_repo.save_experience.return_value = True
     self.experience_repo.get_experience.return_value = others_experience
     return self
Esempio n. 27
0
    def test_gets_modifies_not_none_params_and_returns_experience(self):
        experience = Experience(id='1', title='Title', description='some')
        experience_repo = Mock()
        experience_repo.get_experience.return_value = experience

        updated_experience = Experience(id='1', title='Title', description='')
        experience_repo.update_experience.return_value = updated_experience

        experience_validator = Mock()
        experience_validator.validate_experience.return_value = True

        response = ModifyExperienceInteractor(experience_repo, experience_validator) \
            .set_params(id='1', title=None, description='').execute()

        experience_repo.get_experience.assert_called_once_with(id='1')
        experience_repo.update_experience.assert_called_once_with(
            updated_experience)
        experience_validator.validate_experience.assert_called_once_with(
            updated_experience)
        assert response == updated_experience
Esempio n. 28
0
 def given_an_interactor_that_returns_experience(self):
     self.interactor = Mock()
     self.interactor.set_params.return_value = self.interactor
     self.experience = Experience(id='9',
                                  title='as',
                                  description='er',
                                  author_id='9',
                                  author_profile=Profile(username='******',
                                                         bio='bb',
                                                         is_me=True))
     self.interactor.execute.return_value = self.experience
     return self
Esempio n. 29
0
    def execute(self):
        experience = self.experience_repo.get_experience(id=self.id)

        new_title = self.title if self.title is not None else experience.title
        new_description = self.description if self.description is not None else experience.description
        updated_experience = Experience(id=experience.id,
                                        title=new_title,
                                        description=new_description)

        self.experience_validator.validate_experience(updated_experience)

        return self.experience_repo.update_experience(updated_experience)
Esempio n. 30
0
    def test_invalid_experience_returns_error_and_doesnt_update_it(self):
        experience = Experience(id='1', title='', description='')
        experience_repo = Mock()
        experience_repo.get_experience.return_value = experience
        experience_validator = Mock()
        experience_validator.validate_experience.side_effect = InvalidEntityException(
            source='s', code='c', message='m')
        updated_experience = Experience(id='1',
                                        title='Other',
                                        description='some')

        try:
            ModifyExperienceInteractor(experience_repo, experience_validator) \
                .set_params(id='1', title='Other', description='some').execute()
            assert False
        except InvalidEntityException as invalid_exc:
            assert invalid_exc.source == 's'
            assert invalid_exc.code == 'c'
            assert str(invalid_exc) == 'm'
            experience_repo.get_experience.assert_called_once_with(id='1')
            experience_repo.update_experience.assert_not_called()
            experience_validator.validate_experience.assert_called_once_with(
                updated_experience)