Exemple #1
0
    def obj_create(self, bundle, request=None, **kwargs):
        user_resource = UserResource()
        user_bundle = user_resource.build_bundle(
            data=bundle.data.copy(),
            request=bundle.request)
        user_bundle = user_resource.obj_create(user_bundle, **kwargs)

        client = Client(user=user_bundle.obj, name="divvy_client",
                        client_type=1, url="http://divvy.com")
        client.save()
        scope = 2

        try:
            # Attempt to fetch an existing access token.
            access_token = AccessToken.objects.get(user=user_bundle.obj,
                                                   client=client, scope=scope)
        except AccessToken.DoesNotExist:
            # None found... make a new one!
            access_token = AccessToken.objects.create(user=user_bundle.obj,
                                                      scope=scope,
                                                      client=client)
            RefreshToken.objects.create(user=user_bundle.obj,
                                        access_token=access_token,
                                        client=client)

        bundle.obj = dict2obj({'oauth_consumer_key': access_token})
        bundle.data = {}
        return bundle
Exemple #2
0
def create_api_key(sender, instance, created, **kwargs):
    if created:
        c = Client(user=instance,
                   name="Calories app client",
                   client_type=1,
                   url=PROJECT_URL)
        c.save()
Exemple #3
0
def create_oauth2_client(request):
    user_id = request.GET.get('user_id')
    if not user_id:
        return HttpResponse(content=json.dumps(
            {'error': 'Missing user_id GET param.'}),
                            content_type="application/json")
    try:
        user = User.objects.get(id=user_id)
    except User.DoesNotExist:
        return HttpResponse(content=json.dumps({'error':
                                                'User ID not found.'}),
                            content_type="application/json")
    try:
        client = Client.objects.get(user=user)
        existing = True
    except Client.DoesNotExist:
        client = Client(user=user,
                        name="API Client",
                        client_type=1,
                        url="http://todo.com")
        client.save()
        existing = False
    return HttpResponse(content=json.dumps({
        'client_id': client.client_id,
        'client_secret': client.client_secret,
        'existing': existing
    }),
                        content_type="application/json")
def create_access_token(user_auth, username, password, http_host):
    secret_cli = Client(user=user_auth, name="client", client_type=1, url="")
    secret_cli.save(using=GmApps.AFTERBUY)

    access_token = AccessToken(user=user_auth, client=secret_cli, scope=6)
    AccessToken.objects.filter(user=user_auth, client=secret_cli, scope=6).using(GmApps.AFTERBUY).delete()
    access_token.save(using=GmApps.AFTERBUY)
    return access_token.token
Exemple #5
0
def register_by_access_token(request, backend):
    if backend != 'facebook' and backend != 'google':
        return HttpResponse(status=400, reason='Backend ' + backend + ' not supported')
    token = request.GET.get('access_token')
    print 'token = ', token
    if backend == 'facebook':
        response = requests.get('https://graph.facebook.com/me?access_token=' + token)
    elif backend == 'google':
        response = requests.get('https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + token)
    data_json = response.content
    data_dict = json.loads(data_json)
    print 'data_dict = ', data_dict
    if response.status_code != 200:
        # if data_dict['error']['code'] == 190 and data_dict['error']['error_subcode'] == 463:
        #     return HttpResponse(status=400, reason='Facebook token expired')
        # else:
        return HttpResponse("Invalid access token")
    # try:
    #     e = data_dict['email']
    # except KeyError:
    #     return HttpResponse(status=400, reason="Facebook access token doesn't have email permissions")
    if backend == 'facebook':
        user = EmailUser.objects.filter(source=backend, facebook_id=data_dict['id'])
    elif backend == 'google':
        user = EmailUser.objects.filter(source=backend, google_id=data_dict['id'])
    if user.exists():
        user = user[0]
    else:
        if 'email' in data_dict:
            email = data_dict['email']
        else:
            email = None
        user = EmailUser(name=data_dict['name'],
            email=email, source = backend)
        if backend == 'facebook':
            user.image_url = 'https://graph.facebook.com/v2.3/' + data_dict['id'] + '/picture'
            user.facebook_id = data_dict['id']
        elif backend == 'google':
            user.image_url = data_dict['picture']
            user.google_id = data_dict['id']
        user.save()
    cl = Client(user = user, name = 'opinion', client_type=1, url = 'http://opinion.elasticbeanstalk.com')
    cl.save()
    print 'user = '******' ', user.name, ' ', user.facebook_id, ' ', user.google_id, ' ', user.image_url
    at = AccessTokenView().get_access_token(request, user, scope.to_int('read', 'write'), cl)
    user_data = {'token': at.token}
    user_data['id'] = user.id
    user_data['name'] = user.name
    user_data['email'] = user.email
    print "facebook_id = ", user.facebook_id
    user_data['image_url'] = user.image_url
    print "Serialize Issue: user_data = ", user_data
    if user:
        return HttpResponse(json.dumps(user_data), content_type="application/json")
    else:
        return HttpResponse('ERROR')
Exemple #6
0
def reg_client(request):
    """register client for oauth2"""
    if request.method == "POST":
        form = ClientForm(request.POST)
        if form.is_valid():
            form.cleaned_data['user'] = request.user
            client = Client(**form.cleaned_data)
            client.save()
            return render_to_response('sites/reg_client_done.html',
                RequestContext(request, {'client_id': client.client_id,
                                         'client_secret': client.client_secret}))

    return render_to_response('sites/reg_client.html',
                              RequestContext(request, {'form': ClientForm()}))
Exemple #7
0
 def post(self, request):
     serializer = RegistrationSerializer(data=request.DATA)
     # Check format and unique constraint
     if not serializer.is_valid():
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
     data = serializer.data
     u = User.objects.create(username=data["username"])
     u.set_password(data["password"])
     u.save()
     # Create OAuth2 client
     name = u.username
     client = Client(user=u, name=name, url="" + name, client_id=name, client_secret="", client_type=1)
     client.save()
     return Response(serializer.data, status=status.HTTP_201_CREATED)
Exemple #8
0
    def post(self, request):
        serializer = RegistrationSerializer(data=request.DATA)
        if not serializer.is_valid():
            return Response(serializer.errors, \
                            status=status.HTTP_400_BAD_REQUEST)

        data = serializer.data
        u = User.objects.create(username=data['username'], email=data['email'])
        u.set_password(data['password'])
        u.save()
        name = u.username
        client = Client(user=u, name=name, url='' + name, \
                        client_id=name, client_secret='', client_type=1)
        client.save()

        return Response(serializer.data, status=201)
Exemple #9
0
      def post(self, request):
          serializer = RegistrationSerializer(data=request.DATA)

          if not serializer.is_valid():
             return Response(serializer.errors, status = status.HTTP_400_BAD_REQUEST)
 
          data = serializer.data
          # User creation
          u = User.objects.create(username=data['username'])
          u.set_password(data['password'])
          u.save()

          name = u.username
          client = Client(user=u,name=name,url='' + name,client_id=name, client_secret='',client_type=1)
          client.save()

          return Response(serializer.data,status=status.HTTP_201_CREATED)
Exemple #10
0
    def post(self, request):
        serializer = RegistrationSerializer(data=request.DATA)

        # Check format and unique constraint
        if not serializer.is_valid():
            return Response(serializer.errors,\
                            status=status.HTTP_400_BAD_REQUEST)
        data = serializer.data
        u = User.objects.create(username=data['username'])
        u.set_password(data['password'])
        u.save()

        # Create OAuth2 client
        name = u.username
        client = Client(user=u, name=name, url='' + name,\
                client_id=name, client_secret='', client_type=1)
        client.save()
        return Response(serializer.data, status=status.HTTP_201_CREATED)
Exemple #11
0
    def get_credentials(self, user=None):
        """
        Return dumpheader kwargs for self.api_client.
        e.g :
          return "OAuth cc93eb6b3f609172c90c335033c5ce111c3b4eb6"
          for OAuth2
        """
        if not user:
            user = self.user

        client_ = Client(user=user, name='Fake Client %s' % user.id,
                         client_type=1, url="http://localhost")
        client_.save()

        access_token = AccessToken.objects.create(user=user,
                                                  client=client_,
                                                  scope=6)
        access_token.save()
        return "OAuth %s" % access_token.token
def get_access_token(user_auth, username, password, http_host):
    secret_cli = Client(user=user_auth, name='client', client_type=1, url='')
    secret_cli.save(using=GmApps.AFTERBUY)
    client_id = secret_cli.client_id
    client_secret = secret_cli.client_secret
    page = http_host + '/oauth2/access_token'
    if not 'http://' in page:
        page = 'http://' + page
    raw_params = {'client_id': client_id,
                  'client_secret': client_secret,
                  'grant_type': 'password',
                  'username': username,
                  'password': password,
                  'scope': 'write'
                  }
    params = urllib.urlencode(raw_params)
    oath_request = urllib2.Request(page, params)
    response = urllib2.urlopen(oath_request)
    return json.load(response)
Exemple #13
0
    def create_oauth2(self, user):
        """
        Creates & returns the HTTP ``Authorization`` header for use with Oauth.
        """
        from provider.oauth2.models import Client, AccessToken

        try:
            client = Client.objects.get(user=user)
        except Client.DoesNotExist:
            client = Client(user=user, name="API custom tester", client_type=1, url="http://example.com")
            client.save()

        access_token = AccessToken.objects.create(
            user=user,
            client=client,
            scope= 1 << 1 | 1 << 2 #read + write
        )

        return 'OAuth %s' % access_token.token
def get_access_token(user_auth, username, password, http_host):
    secret_cli = Client(user=user_auth, name="client", client_type=1, url="")
    secret_cli.save(using=GmApps.AFTERBUY)
    client_id = secret_cli.client_id
    client_secret = secret_cli.client_secret
    page = http_host + "/oauth2/access_token"
    if not "http://" in page:
        page = "http://" + page
    raw_params = {
        "client_id": client_id,
        "client_secret": client_secret,
        "grant_type": "password",
        "username": username,
        "password": password,
        "scope": "write",
    }
    params = urllib.urlencode(raw_params)
    oath_request = urllib2.Request(page, params)
    response = urllib2.urlopen(oath_request)
    return json.load(response)
def create_access_token(user_auth, http_host):
    '''
    Used for creating access token
    :param user_auth:
    :type user_auth:
    :param http_host:
    :type http_host:
    '''
    secret_cli = Client(user=user_auth, name='client', client_type=1, url='')
    secret_cli.save(using=settings.BRAND)

    access_token = AccessToken(
        user=user_auth,
        client=secret_cli,
        scope=6
    )
    AccessToken.objects.filter(user=user_auth, client=secret_cli,
                               scope=6).using(settings.BRAND).delete()
    access_token.save(using=settings.BRAND)
    return access_token.token
Exemple #16
0
def create_oauth2_client(request):
    user_id = request.GET.get('user_id')
    if not user_id:
        return HttpResponse(content=json.dumps({'error': 'Missing user_id GET param.'}), content_type="application/json")
    try:
        user = User.objects.get(id=user_id)
    except User.DoesNotExist:
        return HttpResponse(content=json.dumps({'error': 'User ID not found.'}), content_type="application/json")
    try:
        client = Client.objects.get(user=user)
        existing = True
    except Client.DoesNotExist:
        client = Client(user=user,
                        name="API Client",
                        client_type=1,
                        url="http://todo.com")
        client.save()
        existing = False
    return HttpResponse(content=json.dumps({'client_id': client.client_id, 'client_secret': client.client_secret,
                                            'existing': existing}),
                        content_type="application/json")
Exemple #17
0
    def get_credentials(self, user=None):
        """
        Return dumpheader kwargs for self.api_client.
        e.g :
          return "OAuth cc93eb6b3f609172c90c335033c5ce111c3b4eb6"
          for OAuth2
        """
        if not user:
            user = self.user

        client_ = Client(user=user,
                         name='Fake Client %s' % user.id,
                         client_type=1,
                         url="http://localhost")
        client_.save()

        access_token = AccessToken.objects.create(user=user,
                                                  client=client_,
                                                  scope=6)
        access_token.save()
        return "OAuth %s" % access_token.token
Exemple #18
0
class TestGetJARS(unittest.TestCase):
	def setUp(self):
		self.repository = Repository(
			name='TestRepository',
			manager='JARS',
			endpoint='http://localhost:8002',
		)
		self.repository.save()

		self.user = User(
			username = '******',
			password = '******',
		)
		self.user.save()

		self.client = Client(
			user=self.user,
			name="TestUser",
			url="http://asdf.com",
			client_type=0,
			redirect_uri="http://fdsa.com",
			client_id = 'fdasasdfasdf',
			client_secret = 'asdflkjhlkjasdlfjkhasjlksjldkjf',
		)
		self.client.save()

	def test_get(self):
		kwargs = {
			'token': '050814a54ac5c81b990140c3c43278031d391676',
		}
		text = get(self.client, self.repository, jars_uri, **kwargs)

		self.assertIsInstance(text, Text)

		text.content.delete()

	def tearDown(self):
		self.client.delete()
		self.user.delete()
		self.repository.delete()
Exemple #19
0
class TestGetWWW(unittest.TestCase):
	def setUp(self):
		self.repository = Repository(
			name='TestRepository',
			manager='WWW',
			endpoint='',
		)
		self.repository.save()

		self.user = User(
			username = '******',
			password = '******',
		)
		self.user.save()

		self.client = Client(
			user=self.user,
			name="TestUser",
			url="http://asdf.com",
			client_type=0,
			redirect_uri="http://fdsa.com",
			client_id = 'fdasasdfasdf',
			client_secret = 'asdflkjhlkjasdlfjkhasjlksjldkjf',
		)
		self.client.save()

	def test_get(self):
		text = get(self.client, self.repository, wikiURL)

		self.assertIsInstance(text, Text)

		text.content.delete()

	def tearDown(self):
		self.client.delete()
		self.user.delete()
		self.repository.delete()
Exemple #20
0
    def get(self, request):
        data = self.get_data(request)
        code = self.get_data(request, "code")
        error = self.get_data(request, "error")
        client = self.get_data(request, "client")

        # client must be properly deserialized to become a valid instance
        client = Client.deserialize(client)

        # this is an edge case that is caused by making a request with no data
        # it should only happen if this view is called manually, out of the
        # normal capture-authorize-redirect flow.
        if data is None or client is None:
            return self.error_response({
                'error':
                'invalid_data',
                'error_description':
                _('Data has not been captured')
            })

        redirect_uri = data.get('redirect_uri', None) or client.redirect_uri

        parsed = urlparse.urlparse(redirect_uri)

        query = QueryDict('', mutable=True)

        if 'state' in data:
            query['state'] = data['state']

        if error is not None:
            query.update(error)
        elif code is None:
            query['error'] = 'access_denied'
        else:
            query['code'] = code

        parsed = parsed[:4] + (query.urlencode(), '')

        redirect_uri = urlparse.ParseResult(*parsed).geturl()

        self.clear_data(request)

        return HttpResponseRedirect(redirect_uri)
Exemple #21
0
    def get(self, request):
        data = self.get_data(request)
        code = self.get_data(request, "code")
        error = self.get_data(request, "error")
        client = self.get_data(request, "client")

        # client must be properly deserialized to become a valid instance
        client = Client.deserialize(client)

        # this is an edge case that is caused by making a request with no data
        # it should only happen if this view is called manually, out of the
        # normal capture-authorize-redirect flow.
        if data is None or client is None:
            return self.error_response({
                'error': 'invalid_data',
                'error_description': _('Data has not been captured')})

        redirect_uri = data.get('redirect_uri', None) or client.redirect_uri

        parsed = urlparse.urlparse(redirect_uri)

        query = QueryDict('', mutable=True)

        if 'state' in data:
            query['state'] = data['state']

        if error is not None:
            query.update(error)
        elif code is None:
            query['error'] = 'access_denied'
        else:
            query['code'] = code

        parsed = parsed[:4] + (query.urlencode(), '')

        redirect_uri = urlparse.ParseResult(*parsed).geturl()

        self.clear_data(request)

        return HttpResponseRedirect(redirect_uri)
Exemple #22
0
	def setUp(self):
		self.repository = Repository(
			name='TestRepository',
			manager='JARS',
			endpoint='http://localhost:8002',
		)
		self.repository.save()

		self.user = User(
			username = '******',
			password = '******',
		)
		self.user.save()

		self.client = Client(
			user=self.user,
			name="TestUser",
			url="http://asdf.com",
			client_type=0,
			redirect_uri="http://fdsa.com",
			client_id = 'fdasasdfasdf',
			client_secret = 'asdflkjhlkjasdlfjkhasjlksjldkjf',
		)
		self.client.save()
Exemple #23
0
from django.contrib.auth.models import User
from provider.oauth2.models import Client

u = User.objects.create_superuser('admin', '*****@*****.**', 'password12')

c = Client(user=u,
           name='admin',
           url='http://test.url',
           redirect_uri='http://test.url',
           client_id='a27a3bc616b1ed2ff965',
           client_secret='9174b76bcba9ab2188ada16bd6eb7166d2b3c71b',
           client_type=0)

c.save()
Exemple #24
0
class CommunityMapsTest(TestCase):
	geometries = [
		'POINT(-0.15003204345703125 51.55615526777012)',
		'POINT(-0.1544952392578125 51.53074643430678)',
		'POINT(-0.17234802246093747 51.50446860957782)',
		'POINT(-0.11398315429687499 51.52967852566193)',
		'POINT(-0.13149261474609375 51.4950647301436)',
		'POINT(-0.0391387939453125 51.53800754877571)',
		'POINT(-0.06326794624328613 51.55791627866145)',
		'POINT(-0.11020660400390625 51.505750806437874)',
		'POINT(0.00308990478515625 51.50040808149318)',
		'POINT(-0.06557464599609375 51.52562024435108)'
	]

	def _authenticate(self, name):
		return authenticate(username=name, password=name + '123')

	def _getAuthHeader(self, user):
		token = self.client.post('/oauth2/access_token/', {"client_id": self.oauth.client_id, "client_secret": self.oauth.client_secret, "grant_type": "password", "username": user, "password": user + "123"})
		auth_headers = {
			'Authorization': 'Oauth ' + json.loads(token.content).get('access_token'),
		}

		return auth_headers

	def setUp(self):
		User.objects.create_user('eric', '*****@*****.**', 'eric123', first_name='Eric', last_name='Cantona').save()
		User.objects.create_user('george', '*****@*****.**', 'george123', first_name='George', last_name='Best').save()
		User.objects.create_user('mehmet', '*****@*****.**', 'mehmet123', first_name='Mehmet', last_name='Scholl').save()
		User.objects.create_user('zidane', '*****@*****.**', 'zidane123', first_name='Zinedine', last_name='Zidane').save()
		User.objects.create_user('diego', '*****@*****.**', 'diego123', first_name='Diego', last_name='Maradonna').save()
		User.objects.create_user('carlos', '*****@*****.**', 'carlos123', first_name='Carlos', last_name='Valderama').save()
		User.objects.create_user('luis', '*****@*****.**', 'luis123', first_name='Luis', last_name='Figo').save()
		User.objects.create_user('peter', '*****@*****.**', 'peter123', first_name='Peter', last_name='Schmeichel').save()

		eric = self._authenticate('eric')
		george = self._authenticate('george')
		diego = self._authenticate('diego')
		carlos = self._authenticate('carlos')
		zidane = self._authenticate('zidane')
		luis = self._authenticate('luis')
		peter = self._authenticate('peter')

		##################################
		# Helpers
		##################################

		self.client = Client()

		self.oauth = OAuthClient(user=eric, name="Test App", client_type=1, url="http://ucl.ac.uk")
		self.oauth.save()

		self.objectSerializer = ObjectSerializer()


		##################################
		# Set up projects
		##################################

		self.public_project = Factory.createProject('Public project', 'Test description', eric)
		self.public_project.save()

		self.inactive_project = Factory.createProject('Inactive project', 'Test description', eric)
		self.inactive_project.status = STATUS_TYPES['INACTIVE']
		self.inactive_project.admins.addUsers(george)
		self.inactive_project.save()

		self.private_project = Factory.createProject('Private project', 'Test description', eric, isprivate=True)
		self.private_project.admins.addUsers(george)
		self.private_project.contributors.addUsers(diego)
		self.private_project.save()

		self.deleted_project = Factory.createProject('Deleted project', 'Test description', eric)
		self.deleted_project.save()
		self.deleted_project.delete()

		##################################
		# Set up views and user groups
		##################################
		
		self.referenceGroup = self.deleted_project.admins

		self.active_view = View(name='Active View', description='Active view description', project=self.private_project, creator=eric)
		self.active_view.save()

		self.active_view_group = ViewGroup(name='Active View Group', view=self.active_view)
		self.active_view_group.save()
		self.active_view_group.addUsers(carlos, peter)

		self.active_view_two = View(name='Active View 2', description='Active view 2 description', project=self.private_project, creator=eric)
		self.active_view_two.save()

		self.active_view_group_two = ViewGroup(name='Active View Group', view=self.active_view_two)
		self.active_view_group_two.save()
		self.active_view_group_two.addUsers(luis)

		self.deleted_view = View(name='Deleted View', description='Deleted view description', project=self.private_project, creator=eric)
		self.deleted_view.save()

		self.deleted_view_group = ViewGroup(name='Deleted View Group', view=self.deleted_view)
		self.deleted_view_group.save()
		self.deleted_view_group.addUsers(zidane)
		self.deleted_view.delete()

		##################################
		# Feature types and fields
		##################################

		self.active_feature_type = FeatureType(name='Feature type', description='Feature type description', project=self.private_project)
		self.active_feature_type.save()

		self.text_field = TextField(name='Text field', description='Text field description', featuretype=self.active_feature_type)
		self.text_field.save()

		self.lookupfield = LookupField(name='Lookup field', description='Lookup field description', featuretype=self.active_feature_type)
		self.lookupfield.save()
		self.lookupfield.addLookupValues('Gonzo')
		self.lookupvalue = self.lookupfield.lookupvalue_set.filter(name='Gonzo')[0]

		self.inactive_field = TextField(name='Inactive', description='description', featuretype=self.active_feature_type, status=STATUS_TYPES['INACTIVE'])
		self.inactive_field.save()

		self.inactive_feature_type = FeatureType(name='Inactive feature type', description='description', project=self.private_project, status=STATUS_TYPES['INACTIVE'])
		self.inactive_feature_type.save()
		dateField = DateTimeField(name='Date Field', description='Date field description', featuretype=self.inactive_feature_type)
		dateField.save()

		self.inactive_feature_type_two = FeatureType(name='Inactive feature type', description='description', project=self.inactive_project, status=STATUS_TYPES['INACTIVE'])
		self.inactive_feature_type_two.save()


		self.public_feature_type = FeatureType(name='Public feature type', description='description', project=self.public_project)
		self.public_feature_type.save()
		textField = TextField(name='Text field', description='Text field description', featuretype=self.public_feature_type)
		textField.save()
		numericField = NumericField(name='Numeric field', description='Numeric field description', required=True, featuretype=self.public_feature_type)
		numericField.save()
		lookupField = LookupField(name='Lookup field', description='Lookup field description', featuretype=self.public_feature_type)
		lookupField.save()
		lookupField.addLookupValues('Ms. Piggy', 'ist ein', 'dickes', 'Schwein')


		self.private_feature_type = FeatureType(name='Private feature type', description='description', project=self.private_project)
		self.private_feature_type.save()
		textField = TextField(name='Text field', description='Text field description', featuretype=self.private_feature_type)
		textField.save()

	def get(self, url, user):
		self.client.login(username=user, password=user + '123')
		return self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest', content_type='application/json')

	def post(self, url, data, user):
		self.client.login(username=user, password=user + '123')
		return self.client.post(url, json.dumps(data), HTTP_X_REQUESTED_WITH='XMLHttpRequest', content_type='application/json')

	def put(self, url, data, user):
		self.client.login(username=user, password=user + '123')
		return self.client.put(url, json.dumps(data), HTTP_X_REQUESTED_WITH='XMLHttpRequest', content_type='application/json')

	def delete(self, url, user):
		self.client.login(username=user, password=user + '123')
		return self.client.delete(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest', content_type='application/json')

	def get_with_oauth(self, url, user):
		return self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest', **self._getAuthHeader(user))
Exemple #25
0
	def setUp(self):
		User.objects.create_user('eric', '*****@*****.**', 'eric123', first_name='Eric', last_name='Cantona').save()
		User.objects.create_user('george', '*****@*****.**', 'george123', first_name='George', last_name='Best').save()
		User.objects.create_user('mehmet', '*****@*****.**', 'mehmet123', first_name='Mehmet', last_name='Scholl').save()
		User.objects.create_user('zidane', '*****@*****.**', 'zidane123', first_name='Zinedine', last_name='Zidane').save()
		User.objects.create_user('diego', '*****@*****.**', 'diego123', first_name='Diego', last_name='Maradonna').save()
		User.objects.create_user('carlos', '*****@*****.**', 'carlos123', first_name='Carlos', last_name='Valderama').save()
		User.objects.create_user('luis', '*****@*****.**', 'luis123', first_name='Luis', last_name='Figo').save()
		User.objects.create_user('peter', '*****@*****.**', 'peter123', first_name='Peter', last_name='Schmeichel').save()

		eric = self._authenticate('eric')
		george = self._authenticate('george')
		diego = self._authenticate('diego')
		carlos = self._authenticate('carlos')
		zidane = self._authenticate('zidane')
		luis = self._authenticate('luis')
		peter = self._authenticate('peter')

		##################################
		# Helpers
		##################################

		self.client = Client()

		self.oauth = OAuthClient(user=eric, name="Test App", client_type=1, url="http://ucl.ac.uk")
		self.oauth.save()

		self.objectSerializer = ObjectSerializer()


		##################################
		# Set up projects
		##################################

		self.public_project = Factory.createProject('Public project', 'Test description', eric)
		self.public_project.save()

		self.inactive_project = Factory.createProject('Inactive project', 'Test description', eric)
		self.inactive_project.status = STATUS_TYPES['INACTIVE']
		self.inactive_project.admins.addUsers(george)
		self.inactive_project.save()

		self.private_project = Factory.createProject('Private project', 'Test description', eric, isprivate=True)
		self.private_project.admins.addUsers(george)
		self.private_project.contributors.addUsers(diego)
		self.private_project.save()

		self.deleted_project = Factory.createProject('Deleted project', 'Test description', eric)
		self.deleted_project.save()
		self.deleted_project.delete()

		##################################
		# Set up views and user groups
		##################################
		
		self.referenceGroup = self.deleted_project.admins

		self.active_view = View(name='Active View', description='Active view description', project=self.private_project, creator=eric)
		self.active_view.save()

		self.active_view_group = ViewGroup(name='Active View Group', view=self.active_view)
		self.active_view_group.save()
		self.active_view_group.addUsers(carlos, peter)

		self.active_view_two = View(name='Active View 2', description='Active view 2 description', project=self.private_project, creator=eric)
		self.active_view_two.save()

		self.active_view_group_two = ViewGroup(name='Active View Group', view=self.active_view_two)
		self.active_view_group_two.save()
		self.active_view_group_two.addUsers(luis)

		self.deleted_view = View(name='Deleted View', description='Deleted view description', project=self.private_project, creator=eric)
		self.deleted_view.save()

		self.deleted_view_group = ViewGroup(name='Deleted View Group', view=self.deleted_view)
		self.deleted_view_group.save()
		self.deleted_view_group.addUsers(zidane)
		self.deleted_view.delete()

		##################################
		# Feature types and fields
		##################################

		self.active_feature_type = FeatureType(name='Feature type', description='Feature type description', project=self.private_project)
		self.active_feature_type.save()

		self.text_field = TextField(name='Text field', description='Text field description', featuretype=self.active_feature_type)
		self.text_field.save()

		self.lookupfield = LookupField(name='Lookup field', description='Lookup field description', featuretype=self.active_feature_type)
		self.lookupfield.save()
		self.lookupfield.addLookupValues('Gonzo')
		self.lookupvalue = self.lookupfield.lookupvalue_set.filter(name='Gonzo')[0]

		self.inactive_field = TextField(name='Inactive', description='description', featuretype=self.active_feature_type, status=STATUS_TYPES['INACTIVE'])
		self.inactive_field.save()

		self.inactive_feature_type = FeatureType(name='Inactive feature type', description='description', project=self.private_project, status=STATUS_TYPES['INACTIVE'])
		self.inactive_feature_type.save()
		dateField = DateTimeField(name='Date Field', description='Date field description', featuretype=self.inactive_feature_type)
		dateField.save()

		self.inactive_feature_type_two = FeatureType(name='Inactive feature type', description='description', project=self.inactive_project, status=STATUS_TYPES['INACTIVE'])
		self.inactive_feature_type_two.save()


		self.public_feature_type = FeatureType(name='Public feature type', description='description', project=self.public_project)
		self.public_feature_type.save()
		textField = TextField(name='Text field', description='Text field description', featuretype=self.public_feature_type)
		textField.save()
		numericField = NumericField(name='Numeric field', description='Numeric field description', required=True, featuretype=self.public_feature_type)
		numericField.save()
		lookupField = LookupField(name='Lookup field', description='Lookup field description', featuretype=self.public_feature_type)
		lookupField.save()
		lookupField.addLookupValues('Ms. Piggy', 'ist ein', 'dickes', 'Schwein')


		self.private_feature_type = FeatureType(name='Private feature type', description='description', project=self.private_project)
		self.private_feature_type.save()
		textField = TextField(name='Text field', description='Text field description', featuretype=self.private_feature_type)
		textField.save()
from django.contrib.auth.models import User
from provider.oauth2.models import Client

u = User.objects.create_superuser(
	'admin', 
	'*****@*****.**', 
	'password12')

c = Client(user = u, 
	name = 'admin', 
	url = 'http://test.url', 
	redirect_uri = 'http://test.url', 
	client_id = 'a27a3bc616b1ed2ff965',
	client_secret = '9174b76bcba9ab2188ada16bd6eb7166d2b3c71b', 
	client_type = 0)

c.save()