def test_when_object_does_exist_returns_a_credential(self, mocker):
        account_uuid = uuid4()
        mockset = MockSet(
            UserAccount(
                uuid=account_uuid,
                username='******',
                password=
                '******',
                is_active=True))

        class FakeModel:
            objects = mockset

        repository = DjangoCredentialRepository(FakeModel())
        result = repository.find(account_uuid)
        assert isinstance(result, Credential)
    def setup_method(self):
        uuid = uuid4()
        old_password = '******'

        self._instance = UserAccount(uuid=uuid,
                                     username='******',
                                     password=old_password,
                                     is_active=True)

        mockset = MockSet(self._instance, **{'model': UserAccount})

        class FakeModel:
            objects = mockset

        repository = DjangoCredentialRepository(FakeModel())
        self._credential = repository.find(uuid)
        self._credential.set_password('P@sssword99')

        self._result = repository.update_password(self._credential)
Exemplo n.º 3
0
    def save(self):
        account = UserAccount(email_address=self.validated_data['email_address'],
                          first_name=self.validated_data['first_name'],
                          last_name=self.validated_data['last_name'],
                          )
        password = self.validated_data['password']

        is_password_valid = validate_password(password)

        if not is_password_valid:
            raise serializers.ValidationError({'password': '******'})

        account.set_password(password)
        account.save()
        return account   
Exemplo n.º 4
0
    def save(self):

        user = User.objects.create_user(username=self.cleaned_data['email'], email=self.cleaned_data['email'])
        user.set_password(self.cleaned_data['password'])

        user.first_name = self.cleaned_data['first_name']
        user.last_name = self.cleaned_data['last_name']

        account = UserAccount()
        account.user = user
        user.profile = account
        user.save()

        account.age = self.cleaned_data['age']
        account.gender = self.cleaned_data['sex']
        account.zip = self.cleaned_data['zip']

        account.save()
        return user
    def test_update_active(self):
        uuid = uuid4()

        instance = UserAccount(
            uuid=uuid,
            username='******',
            password=
            '******',
            is_active=True)

        mockset = MockSet(instance, **{'model': UserAccount})

        class FakeModel:
            objects = mockset

        repository = DjangoCredentialRepository(FakeModel())
        credential = repository.find(uuid)
        credential.deactivate()

        result = repository.update(credential)

        assert instance.is_active is False
    def test_persist_create(self, mocker):
        uuid = uuid4()

        credential = Credential.factory(
            uuid=uuid,
            username='******',
            password=
            '******',
            active=True)
        mock_manager = mocker.Mock()
        mock_manager.create = mocker.MagicMock(return_value=UserAccount(
            uuid=credential.uuid,
            username=credential.username,
            password=credential.password,
            is_active=credential.active,
        ))

        class FakeModel:
            objects = mock_manager

        repository = DjangoCredentialRepository(FakeModel())
        result = repository.create(credential)

        assert result == credential
Exemplo n.º 7
0
    def save(self):
        email = self.cleaned_data["email"]
        try:
            user = UserAccount.objects.get(email=email)
        except UserAccount.DoesNotExist:
            user = UserAccount()
            first_name = self.cleaned_data["name"].split()[0]
            last_name = self.cleaned_data["name"].split()[1]
            password = self.cleaned_data["password"]
            user.first_name = first_name
            user.last_name = last_name
            user.username = email
            user.email = email
            user.set_password(password)
            user.zip = self.cleaned_data["zip"]
            user.gender = self.cleaned_data["gender"]
            user.save()

        return user
Exemplo n.º 8
0
    def authenticate(self, access_token, expires):
        fields = "first_name,last_name,email,gender,id"

        response = urllib2.urlopen('https://graph.facebook.com/me?fields='+fields+'&access_token='+access_token)
        profile = json.loads(response.read())
        id = profile['id']

        try:
            user = UserAccount.objects.get(facebook_uid=id)

        except UserAccount.DoesNotExist:
            user = UserAccount()
            user.facebook_uid = id
            user.first_name = profile['first_name']
            user.last_name = profile['last_name']
            user.gender = profile['gender']
            user.email = profile['email']
            user.username = profile['email']

            user.type = 'user'
            user.set_unusable_password()
            user.save()

            joinUpdate = UserUpdate(action='join', user=user)
            joinUpdate.save()


        user.access_token = access_token
        user.token_expiration_date = datetime.datetime.now() + datetime.timedelta(seconds=int(expires))

        user.save()
        return user