Example #1
0
 def test_dashboard(self):
     test = make_account('test')
     cra = load_fixture('cra', manager=test)
     response = self.client.get(url_for('account.dashboard'),
                                query_string={'api_key': test.api_key})
     assert '200' in response.status, response.status
     assert unicode(cra.label) in response.data.decode('utf-8'), [response.data]
Example #2
0
 def setUp(self):
     super(TestDatasetApiController, self).setUp()
     self.cra = load_fixture('cra')
     self.user = make_account('test')
     self.auth_qs = {'api_key': self.user.api_key}
     self.cra.managers.append(self.user)
     db.session.commit()
Example #3
0
    def test_update_managers(self):
        url = url_for('datasets_api.managers', name='cra')
        res = self.client.get(url)
        m = res.json
        user2 = make_account('test2')
        db.session.commit()
        m['managers'].append(user2.name)

        res = self.client.post(url,
                               data=json.dumps(m),
                               headers={'content-type': 'application/json'},
                               query_string={'api_key': self.user.api_key})
        assert '200' in res.status, res.status
        mgrs = [x['name'] for x in res.json['managers']]
        assert len(mgrs) == 2, mgrs
        assert self.user.name in mgrs, res.json
        assert user2.name in mgrs, res.json

        m['managers'] = [user2.name]
        res = self.client.post(url,
                               data=json.dumps(m),
                               headers={'content-type': 'application/json'},
                               query_string={'api_key': self.user.api_key})
        assert '200' in res.status, res.status
        mgrs = [x['name'] for x in res.json['managers']]
        assert len(mgrs) == 2, mgrs
        assert self.user.name in mgrs, res.json
        assert user2.name in mgrs, res.json
Example #4
0
 def setUp(self):
     super(TestDatasetApiController, self).setUp()
     self.cra = load_fixture('cra')
     self.user = make_account('test')
     self.auth_qs = {'api_key': self.user.api_key}
     self.cra.managers.append(self.user)
     db.session.commit()
Example #5
0
    def test_update_managers(self):
        url = url_for('datasets_api.managers', name='cra')
        res = self.client.get(url)
        m = res.json
        user2 = make_account('test2')
        db.session.commit()
        m['managers'].append(user2.name)

        res = self.client.post(url, data=json.dumps(m),
                               headers={'content-type': 'application/json'},
                               query_string={'api_key': self.user.api_key})
        assert '200' in res.status, res.status
        mgrs = [x['name'] for x in res.json['managers']]
        assert len(mgrs) == 2, mgrs
        assert self.user.name in mgrs, res.json
        assert user2.name in mgrs, res.json

        m['managers'] = [user2.name]
        res = self.client.post(url, data=json.dumps(m),
                               headers={'content-type': 'application/json'},
                               query_string={'api_key': self.user.api_key})
        assert '200' in res.status, res.status
        mgrs = [x['name'] for x in res.json['managers']]
        assert len(mgrs) == 2, mgrs
        assert self.user.name in mgrs, res.json
        assert user2.name in mgrs, res.json
Example #6
0
 def test_authz_other_user(self):
     url = url_for('sessions_api.authz')
     user = make_account('foo')
     qs = {'api_key': user.api_key}
     qs['dataset'] = self.cra.name
     res = self.client.get(url, query_string=qs)
     assert res.json.get('read') is True, res.json
     assert res.json.get('update') is False, res.json
Example #7
0
 def test_authz_other_user(self):
     url = url_for('sessions_api.authz')
     user = make_account('foo')
     qs = {'api_key': user.api_key}
     qs['dataset'] = self.cra.name
     res = self.client.get(url, query_string=qs)
     assert res.json.get('read') is True, res.json
     assert res.json.get('update') is False, res.json
Example #8
0
 def setUp(self):
     super(TestSourceApiController, self).setUp()
     self.cra = load_fixture('cra')
     self.user = make_account('test')
     self.auth_qs = {'api_key': self.user.api_key}
     self.cra.managers.append(self.user)
     self.cra_url = csvimport_fixture_path('../data', 'cra.csv')
     db.session.commit()
Example #9
0
 def setUp(self):
     super(TestSourceApiController, self).setUp()
     self.cra = load_fixture('cra')
     self.user = make_account('test')
     self.auth_qs = {'api_key': self.user.api_key}
     self.cra.managers.append(self.user)
     self.cra_url = csvimport_fixture_path('../data', 'cra.csv')
     db.session.commit()
Example #10
0
 def setUp(self):
     super(TestSlicerApiController, self).setUp()
     self.cra = load_fixture("cra")
     self.user = make_account("test")
     self.auth_qs = {"api_key": self.user.api_key}
     self.cra.managers.append(self.user)
     self.cra_url = csvimport_fixture_path("../data", "cra.csv")
     db.session.commit()
Example #11
0
 def test_reset_get(self):
     response = self.client.get(url_for('account.do_reset',
                                token='huhu',
                                email='*****@*****.**'))
     assert '/login' in response.headers['location'], response.headers
     account = make_account()
     response = self.client.get(url_for('account.do_reset',
                                token=account.token,
                                email=account.email))
     assert '/settings' in response.headers['location'], response.headers
Example #12
0
 def test_reset_get(self):
     response = self.client.get(
         url_for('account_api.do_reset',
                 token='huhu',
                 email='*****@*****.**'))
     assert '/login' in response.headers['location'], response.headers
     account = make_account()
     response = self.client.get(
         url_for('account_api.do_reset',
                 token=account.token,
                 email=account.email))
     assert '/' in response.headers['location'], response.headers
Example #13
0
    def test_feeds(self):
        # Anonymous user with one public dataset
        response = self.client.get(url_for('home.feed_rss'))
        assert 'application/xml' in response.content_type
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' in response.data, response.data
        cra = Dataset.by_name('cra')
        cra.private = True
        db.session.add(cra)
        db.session.commit()

        # Anonymous user with one private dataset
        response = self.client.get(url_for('home.feed_rss'))
        assert 'application/xml' in response.content_type
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' not in response.data

        # Logged in user with one public dataset
        cra.private = False
        db.session.add(cra)
        db.session.commit()
        response = self.client.get(url_for('home.feed_rss'),
                                   query_string={'api_key': self.user.api_key})
        assert 'application/xml' in response.content_type
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' in response.data

        # Logged in user with one private dataset
        cra.private = True
        db.session.add(cra)
        db.session.commit()
        response = self.client.get(url_for('home.feed_rss'),
                                   query_string={'api_key': self.user.api_key})
        assert 'application/xml' in response.content_type
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' not in response.data

        # Logged in admin user with one private dataset
        admin_user = make_account('admin')
        admin_user.admin = True
        db.session.add(admin_user)
        db.session.commit()
        response = self.client.get(url_for('home.feed_rss'),
                                   query_string={'api_key': admin_user.api_key})
        assert '<title>Recently Created Datasets</title>' in response.data
        assert '<item><title>Country Regional Analysis v2009' in response.data
        assert 'application/xml' in response.content_type

        response = self.client.get('/')
        norm = re.sub('\s+', ' ', response.data)
        assert ('<link rel="alternate" type="application/rss+xml" title="'
                'Latest Datasets on SpenDB"' in
                norm)
Example #14
0
 def setUp(self):
     super(TestRunApiController, self).setUp()
     self.cra = load_fixture('cra')
     self.user = make_account('test')
     self.auth_qs = {'api_key': self.user.api_key}
     self.cra.managers.append(self.user)
     db.session.commit()
     url = url_for('sources_api.upload', dataset=self.cra.name)
     fh = data_fixture('cra')
     self.source = self.client.post(url, data={
         'file': (fh, 'cra.csv')
     }, query_string=self.auth_qs).json
Example #15
0
 def setUp(self):
     super(TestRunApiController, self).setUp()
     self.cra = load_fixture('cra')
     self.user = make_account('test')
     self.auth_qs = {'api_key': self.user.api_key}
     self.cra.managers.append(self.user)
     db.session.commit()
     url = url_for('sources_api.upload', dataset=self.cra.name)
     fh = data_fixture('cra')
     self.source = self.client.post(url,
                                    data={
                                        'file': (fh, 'cra.csv')
                                    },
                                    query_string=self.auth_qs).json
Example #16
0
    def test_distinct_json(self):
        test = make_account()
        response = self.client.get(url_for('account.complete'),
                                   query_string={'api_key': test.api_key})
        obj = response.json['results']
        assert 'fullname' in obj[0].keys(), obj
        assert len(obj) == 1, obj
        assert obj[0]['name'] == 'test', obj[0]

        response = self.client.get(url_for('account.complete'),
                                   query_string={'q': 'tes',
                                                 'api_key': test.api_key})
        obj = response.json['results']
        assert len(obj) == 1, obj

        response = self.client.get(url_for('account.complete'),
                                   query_string={'q': 'foo',
                                                 'api_key': test.api_key})
        obj = response.json['results']
        assert len(obj) == 0, obj
Example #17
0
    def test_distinct_json(self):
        test = make_account()
        response = self.client.get(url_for('account_api.complete'),
                                   query_string={'api_key': test.api_key})
        obj = response.json['results']
        assert 'fullname' in obj[0].keys(), obj
        assert len(obj) == 1, obj
        assert obj[0]['name'] == 'test', obj[0]

        response = self.client.get(url_for('account_api.complete'),
                                   query_string={
                                       'q': 'tes',
                                       'api_key': test.api_key
                                   })
        obj = response.json['results']
        assert len(obj) == 1, obj

        response = self.client.get(url_for('account_api.complete'),
                                   query_string={
                                       'q': 'foo',
                                       'api_key': test.api_key
                                   })
        obj = response.json['results']
        assert len(obj) == 0, obj
Example #18
0
 def setUp(self):
     super(TestHomeController, self).setUp()
     self.dataset = load_fixture('cra')
     self.user = make_account('test')
Example #19
0
 def setUp(self):
     super(TestAccountApiController, self).setUp()
     # Create test user
     self.user = make_account('test')
Example #20
0
 def test_account_create_gives_api_key(self):
     account = make_account()
     assert len(account.api_key) == 36
Example #21
0
    def test_profile(self):
        """
        Profile page test
        """

        # Create the test user account using default
        # username is test, fullname is 'Test User',
        # email is [email protected] and twitter handle is testuser
        test = make_account('test')

        # Get the user profile for an anonymous user
        response = self.client.get(url_for('account_api.view', account='test'))

        assert '200' in response.status, \
            'Profile not successfully returned for anonymous user'
        assert 'name' in response.data, \
            'Name heading is not in profile for anonymous user'
        assert 'Test User' in response.data, \
            'User fullname is not in profile for anonymous user'
        assert 'test' in response.data, \
            'Username is not in profile for anonymous user'
        assert 'email' not in response.data, \
            'Email heading is in profile for anonymous user'
        assert '*****@*****.**' not in response.data, \
            'Email of user is in profile for anonymous user'
        assert '@testuser' not in response.data, \
            'Twitter handle is in profile for anonymous user'

        # Display email and twitter handle for the user
        response = self.client.get(url_for('account_api.view', account='test'),
                                   query_string={'api_key': test.api_key})
        print response.data
        assert '200' in response.status, \
            'Profile not successfully returned for user'
        assert 'email' in response.data, \
            'Email heading is not in profile for the user'
        assert '*****@*****.**' in response.data, \
            'Email of user is not in profile for the user'
        assert 'testuser' in response.data, \
            'Twitter handle of user is not in profile for the user'

        # Immitate that the user now makes email address and twitter handle
        # public to all
        test.public_email = True
        test.public_twitter = True
        db.session.add(test)
        db.session.commit()

        # Get the site as an anonymous user
        response = self.client.get(url_for('account_api.view', account='test'))

        assert '200' in response.status, \
            'Profile with public contact info not returned to anonymous user'
        assert 'email' in response.data, \
            'Public email heading not in profile for anonymous user'
        assert '*****@*****.**' in response.data, \
            'Public email not in profile for anonymous user'
        assert 'testuser' in response.data, \
            'Public Twitter handle not in profile for anonymous user'

        # We take it back and hide the email and the twitter handle
        test.public_email = False
        test.public_twitter = False
        db.session.add(test)
        db.session.commit()

        # Create admin user
        admin_user = make_account('admin', 'Admin', '*****@*****.**')
        admin_user.admin = True
        db.session.add(admin_user)
        db.session.commit()

        # Display email for admins
        response = self.client.get(
            url_for('account_api.view', account='test'),
            query_string={'api_key': admin_user.api_key})

        assert '200' in response.status, \
            'Profile not successfully returned for admins'
        assert 'name' in response.data, \
            'Full name heading not in profile for admins'
        assert 'Test User' in response.data, \
            'Full name of user not in profile for admins'
        assert 'test' in response.data, \
            'Username of user not in profile for admins'
        assert 'email' in response.data, \
            'Email heading not in profile for admins'
        assert '*****@*****.**' in response.data, \
            'Email of user not in profile for admins'
        assert 'twitter_handle' in response.data, \
            'Twitter heading not in profile for admins'
        assert 'testuser' in response.data, \
            'Twitter handle of user not in profile for admins'
Example #22
0
 def test_settings(self):
     account = make_account()
     self.client.get(url_for('account.settings'),
                     query_string={'api_key': account.api_key})
Example #23
0
 def test_account_create_gives_api_key(self):
     account = make_account()
     assert len(account.api_key) == 36
Example #24
0
    def setUp(self):
        super(TestAccountController, self).setUp()

        # Create test user
        self.user = make_account('test')
Example #25
0
    def test_profile(self):
        """
        Profile page test
        """

        # Create the test user account using default
        # username is test, fullname is 'Test User',
        # email is [email protected] and twitter handle is testuser
        test = make_account('test')

        # Get the user profile for an anonymous user
        response = self.client.get(url_for('account.profile', account='test'))

        assert '200' in response.status, \
            'Profile not successfully returned for anonymous user'
        assert 'Name' in response.data, \
            'Name heading is not in profile for anonymous user'
        assert 'Test User' in response.data, \
            'User fullname is not in profile for anonymous user'
        assert 'Username' in response.data, \
            'Username heading is not in profile for anonymous user'
        assert 'test' in response.data, \
            'Username is not in profile for anonymous user'
        assert 'Email' not in response.data, \
            'Email heading is in profile for anonymous user'
        assert '*****@*****.**' not in response.data, \
            'Email of user is in profile for anonymous user'
        assert '@testuser' not in response.data, \
            'Twitter handle is in profile for anonymous user'

        # Display email and twitter handle for the user
        response = self.client.get(url_for('account.profile', account='test'),
                                   query_string={'api_key': test.api_key})

        assert '200' in response.status, \
            'Profile not successfully returned for user'
        assert 'Email' in response.data, \
            'Email heading is not in profile for the user'
        assert '*****@*****.**' in response.data, \
            'Email of user is not in profile for the user'
        assert '@testuser' in response.data, \
            'Twitter handle of user is not in profile for the user'

        # Immitate that the user now makes email address and twitter handle
        # public to all
        test.public_email = True
        test.public_twitter = True
        db.session.add(test)
        db.session.commit()

        # Get the site as an anonymous user
        response = self.client.get(url_for('account.profile', account='test'))

        assert '200' in response.status, \
            'Profile with public contact info not returned to anonymous user'
        assert 'Email' in response.data, \
            'Public email heading not in profile for anonymous user'
        assert '*****@*****.**' in response.data, \
            'Public email not in profile for anonymous user'
        assert '@testuser' in response.data, \
            'Public Twitter handle not in profile for anonymous user'

        # We take it back and hide the email and the twitter handle
        test.public_email = False
        test.public_twitter = False
        db.session.add(test)
        db.session.commit()

        # Create admin user
        admin_user = make_account('admin', 'Admin', '*****@*****.**')
        admin_user.admin = True
        db.session.add(admin_user)
        db.session.commit()

        # Display email for admins
        response = self.client.get(url_for('account.profile', account='test'),
                                   query_string={'api_key': admin_user.api_key})

        assert '200' in response.status, \
            'Profile not successfully returned for admins'
        assert 'Name' in response.data, \
            'Full name heading not in profile for admins'
        assert 'Test User' in response.data, \
            'Full name of user not in profile for admins'
        assert 'Username' in response.data, \
            'Username heading not in profile for admins'
        assert 'test' in response.data, \
            'Username of user not in profile for admins'
        assert 'Email' in response.data, \
            'Email heading not in profile for admins'
        assert '*****@*****.**' in response.data, \
            'Email of user not in profile for admins'
        assert 'Twitter' in response.data, \
            'Twitter heading not in profile for admins'
        assert '@testuser' in response.data, \
            'Twitter handle of user not in profile for admins'

        # Do not display fullname if it's empty
        test.fullname = ''
        db.session.add(test)
        db.session.commit()

        response = self.client.get(url_for('account.profile', account='test'))

        assert '200' in response.status, \
            'Profile page not successfully returned without full name'
        assert 'Name' not in response.data, \
            'Name heading is in profile even though full name is empty'
        # Test if the information is missing or just the full name
        assert 'Username' in response.data, \
            'Username heading is not in profile when full name is empty'
        assert 'test' in response.data, \
            'Username for user is not in profile when full name is empty'

        # Do not display twitter handle if it's empty
        test.twitter_handle = None
        db.session.add(test)
        db.session.commit()

        response = self.client.get(url_for('account.profile', account='test'),
                                   query_string={'api_key': test.api_key})

        # Test if the other information is missing
        assert 'Username' in response.data, \
            'Username heading is not in profile when Twitter handle is empty'
        assert 'test' in response.data, \
            'Username for user is not in profile when Twitter handle is empty'