コード例 #1
0
    def test_update_readonly(self):
        response = self.client.get(
            '/api/1.0/dataset/%s/' % self.dataset.slug,
            content_type='application/json',
            **utils.get_auth_headers('*****@*****.**'))

        data = json.loads(response.content)

        row_count = data['row_count']
        data['row_count'] = 2717

        # Fixes issue with deserialization of users embedded in data_uploads -- is this a bug?
        data['data_uploads'] = [
            du['resource_uri'] for du in data['data_uploads']
        ]

        response = self.client.put(
            '/api/1.0/dataset/%s/' % self.dataset.slug,
            content_type='application/json',
            data=json.dumps(data),
            **utils.get_auth_headers('*****@*****.**'))

        new_data = json.loads(response.content)

        self.assertEqual(new_data['row_count'], row_count)

        # Refresh
        self.dataset = Dataset.objects.get(id=self.dataset.id)

        self.assertEqual(self.dataset.row_count, row_count)
コード例 #2
0
ファイル: test_api_user.py プロジェクト: newsapps/panda
    def test_update_as_different_user(self):
        new_user = {
            'email': '*****@*****.**',
            'password': '******',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        response = self.client.post(
            '/api/1.0/user/',
            content_type='application/json',
            data=json.dumps(new_user),
            **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 201)

        update_user = {
            'email': '*****@*****.**',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        response = self.client.put(
            '/api/1.0/user/%i/' % self.user.id,
            content_type='application/json',
            data=json.dumps(update_user),
            **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 401)
コード例 #3
0
    def test_create_as_new_user(self):
        new_user = {
            'email': '*****@*****.**',
            'password': '******',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        response = self.client.post(
            '/api/1.0/user/',
            content_type='application/json',
            data=json.dumps(new_user),
            **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 201)

        new_dataset = {
            'name': 'New dataset!',
            'description': 'Its got yummy data!'
        }

        response = self.client.post(
            '/api/1.0/dataset/',
            content_type='application/json',
            data=json.dumps(new_dataset),
            **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 201)
コード例 #4
0
ファイル: test_api_user.py プロジェクト: eads/panda
    def test_create_as_admin(self):
        new_user = {"email": "*****@*****.**", "password": "******", "first_name": "Testy", "last_name": "McTester"}

        response = self.client.post(
            "/api/1.0/user/",
            content_type="application/json",
            data=json.dumps(new_user),
            **utils.get_auth_headers("*****@*****.**")
        )

        self.assertEqual(response.status_code, 201)

        body = json.loads(response.content)

        self.assertEqual(body["email"], "*****@*****.**")
        self.assertEqual(body["first_name"], "Testy")
        self.assertEqual(body["last_name"], "McTester")

        new_user = User.objects.get(username="******")

        self.assertEqual(new_user.username, "*****@*****.**")
        self.assertEqual(new_user.email, "*****@*****.**")
        self.assertEqual(new_user.first_name, "Testy")
        self.assertEqual(new_user.last_name, "McTester")
        self.assertEqual(new_user.password[:5], "sha1$")
        self.assertNotEqual(new_user.api_key, None)

        self.assertEqual(list(new_user.groups.all()), [self.panda_user_group])
コード例 #5
0
ファイル: test_api_user.py プロジェクト: newsapps/panda
    def test_create_as_admin(self):
        new_user = {
            'email': '*****@*****.**',
            'password': '******',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        response = self.client.post(
            '/api/1.0/user/',
            content_type='application/json',
            data=json.dumps(new_user),
            **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 201)

        body = json.loads(response.content)

        self.assertEqual(body['email'], '*****@*****.**')
        self.assertEqual(body['first_name'], 'Testy')
        self.assertEqual(body['last_name'], 'McTester')

        new_user = User.objects.get(username='******')

        self.assertEqual(new_user.username, '*****@*****.**')
        self.assertEqual(new_user.email, '*****@*****.**')
        self.assertEqual(new_user.first_name, 'Testy')
        self.assertEqual(new_user.last_name, 'McTester')
        self.assertNotEqual(new_user.api_key, None)

        self.assertEqual(list(new_user.groups.all()), [self.panda_user_group])

        self.assertEqual(
            authenticate(username='******', password='******'),
            new_user)
コード例 #6
0
ファイル: test_api_user.py プロジェクト: newsapps/panda
    def test_update_as_admin(self):
        update_user = {
            'email': '*****@*****.**',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        before_user = self.user

        response = self.client.put(
            '/api/1.0/user/%i/' % self.user.id,
            content_type='application/json',
            data=json.dumps(update_user),
            **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 202)

        after_user = UserProxy.objects.get(id=self.user.id)

        self.assertEqual(after_user.email, '*****@*****.**')
        self.assertEqual(after_user.username, '*****@*****.**')
        self.assertEqual(after_user.first_name, 'Testy')
        self.assertEqual(after_user.last_name, 'McTester')
        self.assertEqual(before_user.date_joined, after_user.date_joined)
        self.assertEqual(before_user.is_active, after_user.is_active)
        self.assertEqual(before_user.last_login, after_user.last_login)
        self.assertEqual(before_user.password, after_user.password)
コード例 #7
0
ファイル: test_api_related_upload.py プロジェクト: eads/panda
    def setUp(self):
        self.user = utils.get_panda_user()
        self.dataset = utils.get_test_dataset(self.user)
        self.upload = utils.get_test_related_upload(self.user, self.dataset)

        self.auth_headers = utils.get_auth_headers()

        self.client = Client()
コード例 #8
0
    def setUp(self):
        self.user = utils.get_panda_user()
        self.dataset = utils.get_test_dataset(self.user)
        self.upload = utils.get_test_data_upload(self.user, self.dataset)

        self.auth_headers = utils.get_auth_headers()

        self.client = Client()
コード例 #9
0
    def test_get_unauthorized(self):
        User.objects.create_user('*****@*****.**', '*****@*****.**', 'password')

        notification = Notification.objects.get(related_dataset=self.dataset)

        response = self.client.get('/api/1.0/notification/%i/' % notification.id, **utils.get_auth_headers('*****@*****.**')) 

        self.assertEqual(response.status_code, 404)
コード例 #10
0
ファイル: test_api_user.py プロジェクト: newsapps/panda
    def setUp(self):
        settings.CELERY_ALWAYS_EAGER = True

        self.user = utils.get_panda_user()
        self.panda_user_group = Group.objects.get(name='panda_user')

        self.auth_headers = utils.get_auth_headers()

        self.client = Client()
コード例 #11
0
ファイル: test_api_user.py プロジェクト: philipn/panda
    def setUp(self):
        settings.CELERY_ALWAYS_EAGER = True

        self.user = utils.get_panda_user() 
        self.panda_user_group = Group.objects.get(name='panda_user')
        
        self.auth_headers = utils.get_auth_headers()

        self.client = Client()
コード例 #12
0
    def setUp(self):
        settings.CELERY_ALWAYS_EAGER = True
        
        self.user = utils.get_panda_user()
        self.dataset = utils.get_test_dataset(self.user)
        self.upload = utils.get_test_data_upload(self.user, self.dataset)

        self.auth_headers = utils.get_auth_headers()

        self.client = Client()
コード例 #13
0
    def test_get_unauthorized(self):
        UserProxy.objects.create_user('*****@*****.**', '*****@*****.**', 'password')

        sub = SearchSubscription.objects.create(
            user=self.user,
            dataset=self.dataset,
            query='*'
        )

        response = self.client.get('/api/1.0/search_subscription/%i/' % sub.id, **utils.get_auth_headers('*****@*****.**')) 

        self.assertEqual(response.status_code, 404)
コード例 #14
0
    def test_get_unauthorized(self):
        UserProxy.objects.create_user('*****@*****.**', '*****@*****.**',
                                      'password')

        sub = SearchSubscription.objects.create(user=self.user,
                                                dataset=self.dataset,
                                                query='*')

        response = self.client.get(
            '/api/1.0/search_subscription/%i/' % sub.id,
            **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 404)
コード例 #15
0
    def test_list_unauthorized(self):
        User.objects.create_user('*****@*****.**', '*****@*****.**', 'password')

        response = self.client.get('/api/1.0/notification/?', data={ 'limit': 5 }, **utils.get_auth_headers('*****@*****.**')) 

        self.assertEqual(response.status_code, 200)

        body = json.loads(response.content)

        self.assertEqual(len(body['objects']), 0)
        self.assertEqual(body['meta']['total_count'], 0)
        self.assertEqual(body['meta']['limit'], 5)
        self.assertEqual(body['meta']['offset'], 0)
        self.assertEqual(body['meta']['next'], None)
        self.assertEqual(body['meta']['previous'], None)
コード例 #16
0
ファイル: test_api_notification.py プロジェクト: niran/panda
    def setUp(self):
        settings.CELERY_ALWAYS_EAGER = True

        utils.setup_test_solr()

        self.user = utils.get_panda_user()
        self.dataset = utils.get_test_dataset(self.user)
        self.upload = utils.get_test_data_upload(self.user, self.dataset)

        self.dataset.import_data(self.user, self.upload, 0)

        utils.wait()

        self.auth_headers = utils.get_auth_headers()

        self.client = Client()
コード例 #17
0
ファイル: test_api_notification.py プロジェクト: niran/panda
    def test_list_unauthorized(self):
        User.objects.create_user("*****@*****.**", "*****@*****.**", "password")

        response = self.client.get(
            "/api/1.0/notification/?", data={"limit": 5}, **utils.get_auth_headers("*****@*****.**")
        )

        self.assertEqual(response.status_code, 200)

        body = json.loads(response.content)

        self.assertEqual(len(body["objects"]), 0)
        self.assertEqual(body["meta"]["total_count"], 0)
        self.assertEqual(body["meta"]["limit"], 5)
        self.assertEqual(body["meta"]["offset"], 0)
        self.assertEqual(body["meta"]["next"], None)
        self.assertEqual(body["meta"]["previous"], None)
コード例 #18
0
    def test_update_unauthorized(self):
        UserProxy.objects.create_user('*****@*****.**', '*****@*****.**',
                                      'password')

        sub = SearchSubscription.objects.create(user=self.user,
                                                dataset=self.dataset,
                                                query='*')

        response = self.client.put(
            '/api/1.0/search_subscription/%i/' % sub.id,
            data=json.dumps({}),
            content_type='application/json',
            **utils.get_auth_headers('*****@*****.**'))
        # This returns 201 (rather than 401), because the PUT fails to match an
        # existing subscription that the user has access to and thus falls
        # back to creating a new one.
        # This is probably not ideal, but works.
        self.assertEqual(response.status_code, 405)
コード例 #19
0
ファイル: test_api_notification.py プロジェクト: niran/panda
    def test_update_unauthorized(self):
        User.objects.create_user("*****@*****.**", "*****@*****.**", "password")

        notification = Notification.objects.get(related_dataset=self.dataset)

        data = json.dumps({"read_at": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")})

        response = self.client.put(
            "/api/1.0/notification/%i/" % notification.id,
            data=data,
            content_type="application/json",
            **utils.get_auth_headers("*****@*****.**")
        )
        # This returns 201 (rather than 401), because the PUT fails to match an
        # existing notification that the user has access to and thus falls
        # back to creating a new one.
        # This is probably not ideal, but works.
        self.assertEqual(response.status_code, 201)
コード例 #20
0
    def test_list_unauthorized(self):
        UserProxy.objects.create_user('*****@*****.**', '*****@*****.**',
                                      'password')

        response = self.client.get(
            '/api/1.0/search_subscription/',
            data={'limit': 5},
            **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 200)

        body = json.loads(response.content)

        self.assertEqual(len(body['objects']), 0)
        self.assertEqual(body['meta']['total_count'], 0)
        self.assertEqual(body['meta']['limit'], 5)
        self.assertEqual(body['meta']['offset'], 0)
        self.assertEqual(body['meta']['next'], None)
        self.assertEqual(body['meta']['previous'], None)
コード例 #21
0
ファイル: test_api_user.py プロジェクト: philipn/panda
    def test_update_as_different_user(self):
        new_user = {
            'email': '*****@*****.**',
            'password': '******',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        response = self.client.post('/api/1.0/user/', content_type='application/json', data=json.dumps(new_user), **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 201)

        update_user = {
            'email': '*****@*****.**',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        response = self.client.put('/api/1.0/user/%i/' % self.user.id, content_type='application/json', data=json.dumps(update_user), **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 401)
コード例 #22
0
ファイル: test_api_dataset.py プロジェクト: NUKnightLab/panda
    def test_update_readonly(self):
        response = self.client.get('/api/1.0/dataset/%s/' % self.dataset.slug, content_type='application/json', **utils.get_auth_headers('*****@*****.**'))

        data = json.loads(response.content)

        row_count = data['row_count']
        data['row_count'] = 2717

        # Fixes issue with deserialization of users embedded in data_uploads -- is this a bug?
        data['data_uploads'] = [du['resource_uri'] for du in data['data_uploads']]

        response = self.client.put('/api/1.0/dataset/%s/' % self.dataset.slug, content_type='application/json', data=json.dumps(data), **utils.get_auth_headers('*****@*****.**'))

        new_data = json.loads(response.content)

        self.assertEqual(new_data['row_count'], row_count)

        # Refresh
        self.dataset = Dataset.objects.get(id=self.dataset.id)

        self.assertEqual(self.dataset.row_count, row_count)
コード例 #23
0
ファイル: test_api_dataset.py プロジェクト: mivanov/panda
    def test_create_as_new_user(self):
        new_user = {
            'email': '*****@*****.**',
            'password': '******',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        response = self.client.post('/api/1.0/user/', content_type='application/json', data=json.dumps(new_user), **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 201)
        
        new_dataset = {
            'name': 'New dataset!',
            'description': 'Its got yummy data!'
        }

        response = self.client.post('/api/1.0/dataset/', content_type='application/json', data=json.dumps(new_dataset), **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 201)        
コード例 #24
0
    def test_update_unauthorized(self):
        UserProxy.objects.create_user('*****@*****.**', '*****@*****.**', 'password')

        sub = SearchSubscription.objects.create(
            user=self.user,
            dataset=self.dataset,
            query='*'
        )

        response = self.client.put('/api/1.0/search_subscription/%i/' % sub.id, data=json.dumps({}), content_type='application/json', **utils.get_auth_headers('*****@*****.**')) 
        # This returns 201 (rather than 401), because the PUT fails to match an
        # existing subscription that the user has access to and thus falls
        # back to creating a new one.
        # This is probably not ideal, but works.
        self.assertEqual(response.status_code, 405)
コード例 #25
0
ファイル: test_api_user.py プロジェクト: philipn/panda
    def test_create_as_admin(self):
        new_user = {
            'email': '*****@*****.**',
            'password': '******',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        response = self.client.post('/api/1.0/user/', content_type='application/json', data=json.dumps(new_user), **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 201)
        
        body = json.loads(response.content)

        self.assertEqual(body['email'], '*****@*****.**')
        self.assertEqual(body['first_name'], 'Testy')
        self.assertEqual(body['last_name'], 'McTester')
        
        new_user = User.objects.get(username='******')

        self.assertEqual(new_user.username, '*****@*****.**')
        self.assertEqual(new_user.email, '*****@*****.**')
        self.assertEqual(new_user.first_name, 'Testy')
        self.assertEqual(new_user.last_name, 'McTester')
        self.assertNotEqual(new_user.api_key, None)

        self.assertEqual(list(new_user.groups.all()), [self.panda_user_group])

        self.assertEqual(authenticate(username='******', password='******'), new_user)
コード例 #26
0
    def test_update_unauthorized(self):
        UserProxy.objects.create_user('*****@*****.**', '*****@*****.**', 'password')

        notification = Notification.objects.all()[0]

        data = json.dumps({ 'read_at': datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S') })

        response = self.client.put('/api/1.0/notification/%i/' % notification.id, data=data, content_type='application/json', **utils.get_auth_headers('*****@*****.**')) 
        # This returns 201 (rather than 401), because the PUT fails to match an
        # existing notification that the user has access to and thus falls
        # back to creating a new one.
        # This is probably not ideal, but works.
        self.assertEqual(response.status_code, 201)
コード例 #27
0
ファイル: test_api_dataset.py プロジェクト: mivanov/panda
    def test_update_readonly(self):
        response = self.client.get('/api/1.0/dataset/%s/' % self.dataset.slug, content_type='application/json', **utils.get_auth_headers('*****@*****.**'))

        data = json.loads(response.content)

        row_count = data['row_count']
        data['row_count'] = 2717

        response = self.client.put('/api/1.0/dataset/%s/' % self.dataset.slug, content_type='application/json', data=json.dumps(data), **utils.get_auth_headers('*****@*****.**'))

        new_data = json.loads(response.content)

        self.assertEqual(new_data['row_count'], row_count)

        # Refresh
        self.dataset = Dataset.objects.get(id=self.dataset.id)

        self.assertEqual(self.dataset.row_count, row_count)
コード例 #28
0
ファイル: test_api_user.py プロジェクト: philipn/panda
    def test_update_as_admin(self):
        update_user = {
            'email': '*****@*****.**',
            'first_name': 'Testy',
            'last_name': 'McTester'
        }

        before_user = self.user

        response = self.client.put('/api/1.0/user/%i/' % self.user.id, content_type='application/json', data=json.dumps(update_user), **utils.get_auth_headers('*****@*****.**'))

        self.assertEqual(response.status_code, 202)

        after_user = User.objects.get(id=self.user.id)

        self.assertEqual(after_user.email, '*****@*****.**')
        self.assertEqual(after_user.username, '*****@*****.**')
        self.assertEqual(after_user.first_name, 'Testy')
        self.assertEqual(after_user.last_name, 'McTester')
        self.assertEqual(before_user.date_joined, after_user.date_joined)
        self.assertEqual(before_user.is_active, after_user.is_active)
        self.assertEqual(before_user.last_login, after_user.last_login)
        self.assertEqual(before_user.password, after_user.password)