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
Esempio n. 2
0
 def then_result_should_be_profile(self, person, username, bio, is_me):
     assert self.result == Profile(person_id=str(self.persons[person -
                                                              1].id),
                                   username=username,
                                   bio=bio,
                                   is_me=is_me)
     return self
Esempio n. 3
0
 def given_a_profile(self, person, username, bio):
     profile = Profile(person_id=str(self.persons[person - 1].id),
                       username=username,
                       bio=bio,
                       is_me=True)
     self.repo.create_profile(profile)
     return self
Esempio n. 4
0
 def given_an_interactor_that_returns_profile(self):
     self.interactor = Mock()
     self.interactor.set_params.return_value = self.interactor
     self.profile = Profile(person_id='4', username='******', bio='b',
                            picture=Picture(tiny_url='t', small_url='s', medium_url='m'),
                            is_me=True)
     self.interactor.execute.return_value = self.profile
     return self
Esempio n. 5
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. 6
0
 def test_correct_username_and_email_when_profile_exists(self):
     TestRegisterUsernameAndEmailInteractor.ScenarioMaker() \
             .given_a_person_validator_that_returns(True) \
             .given_a_person_repo_that_returns_on_get(Person(id='3', email='b', is_email_confirmed=False)) \
             .given_a_person_repo_that_returns_on_update(Person(id='4', email='o', is_email_confirmed=False)) \
             .given_a_profile_validator_that_returns(True) \
             .given_a_profile_repo_that_returns_on_get(Profile(person_id='7', username='******')) \
             .given_a_confirmation_token_repo_that_returns('KT') \
             .when_execute(logged_person_id='1', username='******', email='e') \
             .then_should_call_person_repo_get_with(id='1') \
             .then_should_call_person_validator_with(Person(id='3', email='e', is_email_confirmed=False)) \
             .then_should_call_profile_repo_get_with(person_id='1', logged_person_id='1') \
             .then_should_call_profile_validator_with(Profile(person_id='7', username='******')) \
             .then_should_call_profile_repo_update_with(Profile(person_id='7', username='******')) \
             .then_should_call_person_repo_update_with(Person(id='3', email='e', is_email_confirmed=False)) \
             .then_should_call_confirmation_token_repo_delete_with(person_id='1') \
             .then_should_call_confirmation_token_repo_create_with(person_id='1') \
             .then_should_call_mailer_with(confirmation_token='KT', username='******', email='e') \
             .then_should_return(True)
Esempio n. 7
0
 def _decode_db_profile(self, db_profile, logged_person_id):
     if not db_profile.picture:
         picture = None
     else:
         picture = Picture(tiny_url=db_profile.picture.tiny.url,
                           small_url=db_profile.picture.small.url,
                           medium_url=db_profile.picture.medium.url)
     return Profile(person_id=str(db_profile.person_id),
                    username=db_profile.username,
                    bio=db_profile.bio,
                    picture=picture,
                    is_me=(str(db_profile.person_id) == logged_person_id))
Esempio n. 8
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. 9
0
 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',
                                    saves_count=9,
                                    author_profile=Profile(username='******',
                                                           bio='bb',
                                                           is_me=True))
     return self
Esempio n. 10
0
 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',
                                    saves_count=4,
                                    author_profile=Profile(username='******',
                                                           bio='aa',
                                                           is_me=True))
     return self
Esempio n. 11
0
    def test_post_returns_experience_serialized_and_200(self):
        experience = Experience(id='1',
                                title='B',
                                description='some',
                                author_id='6',
                                saves_count=8,
                                author_profile=Profile(person_id='9',
                                                       username='******',
                                                       bio='b',
                                                       picture=Picture(
                                                           tiny_url='t',
                                                           small_url='s',
                                                           medium_url='m'),
                                                       is_me=True))

        interactor_mock = Mock()
        interactor_mock.set_params.return_value = interactor_mock
        interactor_mock.execute.return_value = experience

        view = ExperiencesView(
            create_new_experience_interactor=interactor_mock)
        body, status = view.post(title='B',
                                 description='some',
                                 logged_person_id='7')

        interactor_mock.set_params.assert_called_once_with(
            title='B', description='some', logged_person_id='7')
        assert status == 201
        assert body == {
            'id': '1',
            'title': 'B',
            'description': 'some',
            'picture': None,
            'author_profile': {
                'username': '******',
                'bio': 'b',
                'picture': {
                    'tiny_url': 't',
                    'small_url': 's',
                    'medium_url': 'm',
                },
                'is_me': True
            },
            'is_mine': False,
            'is_saved': False,
            'saves_count': 8
        }
Esempio n. 12
0
 def test_incorrect_username_raises_invalid_entity_exception(self):
     TestRegisterUsernameAndEmailInteractor.ScenarioMaker() \
             .given_a_person_validator_that_returns(True) \
             .given_a_person_repo_that_returns_on_get(Person(id='3', email='b', is_email_confirmed=False)) \
             .given_a_profile_validator_that_returns(
                     error=InvalidEntityException(source='u', code='i', message='m')) \
             .given_a_profile_repo_that_returns_on_get(False) \
             .when_execute(logged_person_id='1', username='******', email='e') \
             .then_should_call_person_repo_get_with(id='1') \
             .then_should_call_person_validator_with(Person(id='3', email='e', is_email_confirmed=False)) \
             .then_should_call_profile_repo_get_with(person_id='1', logged_person_id='1') \
             .then_should_call_profile_validator_with(Profile(person_id='1', username='******')) \
             .then_should_call_profile_repo_update_with(False) \
             .then_should_call_person_repo_update_with(False) \
             .then_should_call_confirmation_token_repo_delete_with(False) \
             .then_should_call_confirmation_token_repo_create_with(False) \
             .then_should_call_mailer_with(False) \
             .then_should_raise(InvalidEntityException(source='u', code='i', message='m'))
Esempio n. 13
0
 def then_should_call_repo_update_profile_with(self, bio):
     expected_profile = Profile(person_id=self.profile.person_id,
                                username=self.profile.username,
                                bio=bio)
     self.repo.update_profile.assert_called_once_with(expected_profile)
     return self
Esempio n. 14
0
 def given_a_profile_on_repo_for_get(self):
     self.profile = Profile(person_id='9', username='******', bio='o')
     self.repo = Mock()
     self.repo.get_profile.return_value = self.profile
     return self
Esempio n. 15
0
 def given_a_profile_on_repo_for_update(self):
     self.updated_profile = Profile(person_id='2',
                                    username='******',
                                    bio='m')
     self.repo.update_profile.return_value = self.updated_profile
     return self
Esempio n. 16
0
 def given_a_second_profile_with_that_params(self):
     self.second_profile = Profile(person_id='2', username=self.username, bio=self.bio)
     return self
Esempio n. 17
0
 def when_update_profile(self, person, username, bio):
     profile = Profile(person_id=str(self.persons[person - 1].id),
                       username=username,
                       bio=bio)
     self.result = self.repo.update_profile(profile)
     return self
Esempio n. 18
0
 def given_a_profile(self):
     self.profile = Profile(person_id='4', username='******', bio='b',
                            picture=Picture(tiny_url='t', small_url='s', medium_url='m'),
                            is_me=True)
     return self
Esempio n. 19
0
 def given_a_profile_on_repo_attach_picture(self):
     self.profile = Profile(person_id='4')
     self.repo = Mock()
     self.repo.attach_picture_to_profile.return_value = self.profile
     return self
Esempio n. 20
0
 def given_a_profile_repo_that_returns_profile_with_person_id(
         self, person_id):
     self.profile_repo.get_profile.return_value = Profile(
         person_id=person_id)
     return self
Esempio n. 21
0
 def given_a_profile_on_repo(self, id):
     self.profile = Profile(person_id=id, username='******', bio='o')
     self.repo = Mock()
     self.repo.get_profile.return_value = self.profile
     return self
Esempio n. 22
0
 def given_a_profile(self):
     self.profile = Profile(person_id=self.person.id, username='******')
     return self