예제 #1
0
파일: tests.py 프로젝트: RestAuth/server
    def test_skip_existing_users(self):
        backend.create_user(username2)
        backend.set_property(user=username2, key=propkey1, value=propval3)
        backend.set_property(user=username2, key="date joined", value=propval3)

        path = os.path.join(self.base, 'users1.json')
        with capture() as (stdout, stderr):
            restauth_import(['--skip-existing-users', path])
        self.assertProperties(username2, {propkey1: propval3, })
예제 #2
0
    def put(self, request, largs, name, subname):
        """Set value of a single property."""

        if not request.user.has_perm('Users.prop_set'):
            return HttpResponseForbidden()

        # If BadRequest: 400 Bad Request
        value = self._parse_put(request)

        # If UserNotFound: 404 Not Found
        old_value = backend.set_property(user=name, key=subname, value=value)

        if old_value is None:  # new property
            self.log.info('Set to "%s"', value, extra=largs)
            return HttpResponseCreated()
        else:  # existing property
            self.log.info('Changed from "%s" to "%s"', old_value, value, extra=largs)

            if request.version < (0, 7):
                return HttpRestAuthResponse(request, old_value)
            else:
                return HttpRestAuthResponse(request, {'value': old_value})