コード例 #1
0
ファイル: test_status.py プロジェクト: robhudson/standup
    def test_contextual_feeds(self):
        """Test that team/project/user Atom feeds appear as <link> tags."""

        with self.app.app_context():
            user(email='*****@*****.**', save=True)
            u = user(username='******', email="*****@*****.**",
                     name='Buffy Summers', slug='buffy', save=True)
            team(name='Scooby Gang', slug='scoobies', users=[u], save=True)
            project(name='Kill The Master', slug='master', save=True)

        authenticate(self.client, u)

        site_url = self.app.config.get('SITE_URL')

        rv = self.client.get('/')
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/statuses.xml"') % site_url in rv.data
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/project/') % site_url not in rv.data

        rv = self.client.get('/team/scoobies')
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/team/') % site_url in rv.data

        rv = self.client.get('/project/master')
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/project/') % site_url in rv.data

        rv = self.client.get('/user/buffy')
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/user/') % site_url in rv.data
コード例 #2
0
ファイル: test_app.py プロジェクト: uberj/standup
    def test_update_user_by_admins(self):
        """Test that an admin can update another users settings and non-admins
        cannot update other users settings
        """
        u = user(save=True)
        a = user(username="******", slug="admin", email="*****@*****.**", is_admin=True, save=True)

        uid = u.id
        aid = a.id
        username = u.username

        data = json.dumps(
            {
                "api_key": settings.API_KEY,
                "user": a.username,
                "email": "*****@*****.**",
                "github_handle": "test",
                "name": "Test",
            }
        )
        response = self.app.post("/api/v1/user/%s/" % username, data=data, content_type="application/json")
        self.assertEqual(response.status_code, 200)

        u = User.query.get(uid)

        self.assertEqual(u.email, "*****@*****.**")
        self.assertEqual(u.github_handle, "test")
        self.assertEqual(u.name, "Test")

        data = json.dumps({"api_key": settings.API_KEY, "user": username, "email": "*****@*****.**"})
        response = self.app.post("/api/v1/user/%s/" % aid, data=data, content_type="application/json")
        self.assertEqual(response.status_code, 403)
コード例 #3
0
    def test_contextual_feeds(self):
        """Test that team/project/user Atom feeds appear as <link> tags."""

        with self.app.app_context():
            user(email='*****@*****.**', save=True)
            u = user(username='******',
                     email="*****@*****.**",
                     name='Buffy Summers',
                     slug='buffy',
                     save=True)
            team(name='Scooby Gang', slug='scoobies', users=[u], save=True)
            project(name='Kill The Master', slug='master', save=True)

        authenticate(self.client, u)

        site_url = self.app.config.get('SITE_URL')

        rv = self.client.get('/')
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/statuses.xml"') % site_url in rv.data
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/project/') % site_url not in rv.data

        rv = self.client.get('/team/scoobies')
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/team/') % site_url in rv.data

        rv = self.client.get('/project/master')
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/project/') % site_url in rv.data

        rv = self.client.get('/user/buffy')
        assert ('<link rel="alternate" type="application/atom+xml" '
                'href="%s/user/') % site_url in rv.data
コード例 #4
0
    def test_team_recent_statuses(self):
        """Test loading of recent statuses for a project."""
        with self.app.app_context():
            t = team(save=True)
            u = user(teams=[t], save=True)
            u2 = user(username='******',
                      slug='troll',
                      email='*****@*****.**',
                      save=True)

            # Create 30 statuses
            for i in range(30):
                s = status(project=None, user=u, save=True)

            # Create 30 replies
            for i in range(30):
                status(project=None, user=u, reply_to=s, save=True)

            # Create 30 statuses for user not in team
            for i in range(10):
                status(project=None, user=u2, save=True)

            # Should not include replies
            page = t.recent_statuses()
            eq_(page.pages, 2)
コード例 #5
0
ファイル: test_app.py プロジェクト: hsgr/standup
    def test_profile_authenticationified(self):
        """Test that you can see profile page if you are logged in."""
        user(email='*****@*****.**', save=True)
        with app.app.test_client() as tc:
            with tc.session_transaction() as sess:
                sess['email'] = '*****@*****.**'

            rv = tc.get('/profile/')
            eq_(rv.status_code, 200)
コード例 #6
0
ファイル: test_app.py プロジェクト: hsgr/standup
    def test_status(self):
        """Test posting a status."""
        user(email='*****@*****.**', save=True)
        with app.app.test_client() as tc:
            with tc.session_transaction() as sess:
                sess['email'] = '*****@*****.**'

            rv = tc.post('/statusize/',
                         data={'message': 'foo'},
                         follow_redirects=True)
            eq_(rv.status_code, 200)
コード例 #7
0
ファイル: test_api2.py プロジェクト: safwanrahman/standup
    def test_timeline_filters_user(self):
        """Test the timeline only shows the passed in user."""
        with self.app.app_context():
            u = user(save=True)
            status(user=u, project=None, save=True)
            u2 = user(username="******", email="*****@*****.**", slug="janedoe", save=True)
            status(user=u2, project=None, save=True)

        response = self.client.get(self._url())
        data = json.loads(response.data)
        eq_(len(data), 1)
        eq_(data[0]["user"], u.dictify())
コード例 #8
0
ファイル: test_app.py プロジェクト: hsgr/standup
    def test_status_no_message(self):
        """Test posting a status with no message."""
        user(email='*****@*****.**', save=True)
        with app.app.test_client() as tc:
            with tc.session_transaction() as sess:
                sess['email'] = '*****@*****.**'

            rv = tc.post('/statusize/',
                         data={'message': ''},
                         follow_redirects=True)
            # This kicks up a 404, but that's lame.
            eq_(rv.status_code, 404)
コード例 #9
0
    def test_timeline_filters_user(self):
        """Test the timeline only shows the passed in user."""
        with self.app.app_context():
            u = user(save=True)
            status(user=u, project=None, save=True)
            u2 = user(username='******', email='*****@*****.**',
                      slug='janedoe', save=True)
            status(user=u2, project=None, save=True)

        response = self.client.get(self._url())
        data = json.loads(response.data)
        eq_(len(data), 1)
        eq_(data[0]['user'], u.dictify())
コード例 #10
0
ファイル: test_api2.py プロジェクト: chinna1986/standup
    def test_timeline_filters_team(self):
        """Test the timeline only shows the passed in team."""
        with self.app.app_context():
            u = user(save=True, team={})
            u2 = user(username='******', email='*****@*****.**',
                      slug='janedoe', save=True, team={'name': 'XXX',
                                                       'slug': 'xxx'})
            p = project(save=True)
            status(user=u, project=p, save=True)
            status(user=u2, project=p, save=True)

        response = self.client.get(self._url(dict(team_id=u.teams[0].id)))
        data = json.loads(response.data)
        eq_(len(data), 1)
        eq_(data[0]['user'], u.dictify())
コード例 #11
0
    def test_timeline_filters_team(self):
        """Test the timeline only shows the passed in team."""
        with self.app.app_context():
            u = user(save=True, team={})
            u2 = user(username='******', email='*****@*****.**',
                      slug='janedoe', save=True, team={'name': 'XXX',
                                                       'slug': 'xxx'})
            p = project(save=True)
            status(user=u, project=p, save=True)
            status(user=u2, project=p, save=True)

        response = self.client.get(self._url(dict(team_id=u.teams[0].id)))
        data = json.loads(response.data)
        eq_(len(data), 1)
        eq_(data[0]['user'], u.dictify())
コード例 #12
0
ファイル: test_api2.py プロジェクト: safwanrahman/standup
    def test_timeline_filters_team(self):
        """Test the timeline only shows the passed in team."""
        with self.app.app_context():
            u = user(save=True, team={})
            u2 = user(
                username="******", email="*****@*****.**", slug="janedoe", save=True, team={"name": "XXX", "slug": "xxx"}
            )
            p = project(save=True)
            status(user=u, project=p, save=True)
            status(user=u2, project=p, save=True)

        response = self.client.get(self._url(dict(team_id=u.teams[0].id)))
        data = json.loads(response.data)
        eq_(len(data), 1)
        eq_(data[0]["user"], u.dictify())
コード例 #13
0
ファイル: test_api2.py プロジェクト: chinna1986/standup
    def test_timeline_since_id(self):
        """Test the since_id parameter of home_timeline"""
        with self.app.app_context():
            u = user(save=True, team={})
            p = project(save=True)
            for i in range(30):
                status(project=p, user=u, save=True)

        response = self.client.get(self._url(dict(since_id=10, count=20)))
        data = json.loads(response.data)
        eq_(data[19]['id'], 11)

        response = self.client.get(self._url(dict(since_id=10, count=10)))
        data = json.loads(response.data)
        eq_(data[9]['id'], 21)

        response = self.client.get(self._url(dict(since_id=10, count=30)))
        data = json.loads(response.data)
        eq_(len(data), 20)
        eq_(data[19]['id'], 11)

        response = self.client.get(self._url(dict(since_id=0)))
        eq_(response.status_code, 400)

        response = self.client.get(self._url(dict(since_id='a')))
        eq_(response.status_code, 400)
コード例 #14
0
    def test_status_repr(self):
        """Test the __repr__ function of the Status model."""
        with self.app.app_context():
            u = user(username='******', save=True)
            s = status(content='my status update', user=u, save=True)

        eq_(repr(s), '<Status: testuser: my status update>')
コード例 #15
0
    def test_update_user(self):
        """Test that a user can update their own settings"""
        db = get_session(self.app)

        with self.app.app_context():
            u = user(save=True)

        id = u.id

        data = json.dumps({
            'api_key': self.app.config.get('API_KEY'),
            'user': u.username,
            'email': '*****@*****.**',
            'github_handle': 'test',
            'name': 'Test'
        })
        response = self.client.post('/api/v1/user/%s/' % u.username,
                                    data=data,
                                    content_type='application/json')
        eq_(response.status_code, 200)

        u = db.query(User).get(id)

        eq_(u.email, '*****@*****.**')
        eq_(u.github_handle, 'test')
        eq_(u.name, 'Test')
コード例 #16
0
ファイル: test_status.py プロジェクト: robhudson/standup
    def test_status_repr(self):
        """Test the __repr__ function of the Status model."""
        with self.app.app_context():
            u = user(username='******', save=True)
            s = status(content='my status update', user=u, save=True)

        eq_(repr(s), '<Status: testuser: my status update>')
コード例 #17
0
    def test_create_first_status(self):
        """Test creating the very first status for a project and user."""
        db = get_session(self.app)

        with self.app.app_context():
            u = user(username='******', save=True)

        data = json.dumps({
            'api_key': self.app.config.get('API_KEY'),
            'user': u.username,
            'project': 'sumodev',
            'content': 'bug 123456'
        })
        response = self.client.post('/api/v1/status/',
                                    data=data,
                                    content_type='application/json')
        eq_(response.status_code, 200)
        assert 'bug 123456' in response.data

        # Verify the user was created.
        eq_(db.query(User).first().username, 'r1cky')
        # Verify the project was created.
        eq_(db.query(Project).first().slug, 'sumodev')
        # Verify the status was created.
        eq_(db.query(Status).first().content, 'bug 123456')
コード例 #18
0
    def test_timeline_since_id(self):
        """Test the since_id parameter of home_timeline"""
        with self.app.app_context():
            u = user(save=True, team={})
            p = project(save=True)
            for i in range(30):
                status(project=p, user=u, save=True)

        response = self.client.get(self._url(dict(since_id=10, count=20)))
        data = json.loads(response.data)
        eq_(data[19]['id'], 11)

        response = self.client.get(self._url(dict(since_id=10, count=10)))
        data = json.loads(response.data)
        eq_(data[9]['id'], 21)

        response = self.client.get(self._url(dict(since_id=10, count=30)))
        data = json.loads(response.data)
        eq_(len(data), 20)
        eq_(data[19]['id'], 11)

        response = self.client.get(self._url(dict(since_id=0)))
        eq_(response.status_code, 400)

        response = self.client.get(self._url(dict(since_id='a')))
        eq_(response.status_code, 400)
コード例 #19
0
    def test_timeline_count(self):
        """Test the count parameter of home_timeline"""
        self.app.config['API2_TIMELINE_MAX_RESULTS'] = 50
        with self.app.app_context():
            u = user(save=True, team={})
            p = project(save=True)
            for i in range(60):
                status(project=p, user=u, save=True)

        response = self.client.get(self._url())
        data = json.loads(response.data)
        eq_(len(data), 20)

        # Test with an acceptable count
        response = self.client.get(self._url(dict(count=50)))
        data = json.loads(response.data)
        eq_(len(data), 50)

        # Test with a count that is too large
        response = self.client.get(self._url(dict(count=60)))
        eq_(response.status_code, 400)

        # Test with a count that is too small
        response = self.client.get(self._url(dict(count=0)))
        eq_(response.status_code, 400)

        # Test with an invalid count
        response = self.client.get(self._url(dict(count='a')))
        eq_(response.status_code, 400)
コード例 #20
0
ファイル: test_api2.py プロジェクト: chinna1986/standup
    def test_timeline_count(self):
        """Test the count parameter of home_timeline"""
        self.app.config['API2_TIMELINE_MAX_RESULTS'] = 50
        with self.app.app_context():
            u = user(save=True, team={})
            p = project(save=True)
            for i in range(60):
                status(project=p, user=u, save=True)

        response = self.client.get(self._url())
        data = json.loads(response.data)
        eq_(len(data), 20)

        # Test with an acceptable count
        response = self.client.get(self._url(dict(count=50)))
        data = json.loads(response.data)
        eq_(len(data), 50)

        # Test with a count that is too large
        response = self.client.get(self._url(dict(count=60)))
        eq_(response.status_code, 400)

        # Test with a count that is too small
        response = self.client.get(self._url(dict(count=0)))
        eq_(response.status_code, 400)

        # Test with an invalid count
        response = self.client.get(self._url(dict(count='a')))
        eq_(response.status_code, 400)
コード例 #21
0
ファイル: test_app.py プロジェクト: groovecoder/standup
 def test_udate_user_invalid_api_key(self):
     """Request with invalid API key should return 403"""
     u = user(save=True)
     data = json.dumps({'user': u.username})
     response = self.app.post(
         '/api/v1/user/%s/' % u.id, data=data,
         content_type='application/json')
     self.assertEqual(response.status_code, 403)
コード例 #22
0
ファイル: test_app.py プロジェクト: hsgr/standup
    def test_status_with_project(self):
        """Test posting a status with no message."""
        user(email='*****@*****.**', save=True)

        p = Project(name='blackhole', slug='blackhole')
        app.db.session.add(p)
        app.db.session.commit()
        pid = p.id

        with app.app.test_client() as tc:
            with tc.session_transaction() as sess:
                sess['email'] = '*****@*****.**'

            rv = tc.post('/statusize/',
                         data={'message': 'r1cky rocks!', 'project': pid},
                         follow_redirects=True)
            eq_(rv.status_code, 200)
コード例 #23
0
ファイル: test_app.py プロジェクト: uberj/standup
    def test_update_user_validation(self):
        """Verify validation of required fields"""
        u = user(save=True)

        # Missing user
        data = json.dumps({"api_key": settings.API_KEY})
        response = self.app.post("/api/v1/user/%s/" % u.id, data=data, content_type="application/json")
        self.assertEqual(response.status_code, 400)
コード例 #24
0
    def setUp(self):
        super(TimesinceLastUpdateTestCase, self).setUp()

        with self.app.app_context():
            self.user = user(save=True)

        self.url = '/api/v2/info/timesince_last_update.json'
        self.query = {'screen_name': self.user.username}
コード例 #25
0
ファイル: test_status.py プロジェクト: rlr/standup
 def test_status_week_end(self):
     """Test the week_end function of the Status model."""
     d = datetime(2014, 5, 8, 17, 17, 51, 0)
     with self.app.app_context():
         u = user(username='******', save=True)
         s = status(content='my status update', created=d, user=u, save=True)
     d_actual = s.week_end.strftime("%Y-%m-%d")
     eq_(d_actual, "2014-05-11") # Happy Mother's Day!
コード例 #26
0
ファイル: test_status.py プロジェクト: rlr/standup
 def test_status_weeks_at_year_start(self):
     """Test the week_{start|end} function around the start of the year."""
     d = datetime(2013, 12, 31, 12, 13, 45, 0)
     with self.app.app_context():
         u = user(username='******', save=True)
         s = status(content='my status update', created=d, user=u, save=True)
     eq_(s.week_start.strftime("%Y-%m-%d"), "2013-12-30")
     eq_(s.week_end.strftime("%Y-%m-%d"), "2014-01-05")
コード例 #27
0
ファイル: test_api2.py プロジェクト: chinna1986/standup
    def setUp(self):
        super(TimesinceLastUpdateTestCase, self).setUp()

        with self.app.app_context():
            self.user = user(save=True)

        self.url = '/api/v2/info/timesince_last_update.json'
        self.query = {'screen_name': self.user.username}
コード例 #28
0
    def test_update_user_by_admins(self):
        """Test that an admin can update another users settings and
        non-admins cannot update other users settings
        """
        db = get_session(self.app)

        with self.app.app_context():
            u = user(save=True)
            a = user(username='******',
                     slug='admin',
                     email='*****@*****.**',
                     is_admin=True,
                     save=True)

        uid = u.id
        username = u.username
        adminname = a.username

        data = json.dumps({
            'api_key': self.app.config.get('API_KEY'),
            'user': a.username,
            'email': '*****@*****.**',
            'github_handle': 'test',
            'name': 'Test'
        })
        response = self.client.post('/api/v1/user/%s/' % username,
                                    data=data,
                                    content_type='application/json')
        eq_(response.status_code, 200)

        u = db.query(User).get(uid)

        eq_(u.email, '*****@*****.**')
        eq_(u.github_handle, 'test')
        eq_(u.name, 'Test')

        data = json.dumps({
            'api_key': self.app.config.get('API_KEY'),
            'user': username,
            'email': '*****@*****.**'
        })
        response = self.client.post('/api/v1/user/%s/' % adminname,
                                    data=data,
                                    content_type='application/json')
        eq_(response.status_code, 403)
コード例 #29
0
ファイル: test_database.py プロジェクト: Ms2ger/standup
    def setUp(self):
        super(HelpersTestCase, self).setUp()
        with self.app.app_context():
            u = user(username='******', save=True)
            for i in range(100):
                status(project=None, user=u, save=True)

        db = get_session(self.app)
        self.query = db.query(Status).order_by(Status.id)
コード例 #30
0
ファイル: test_users.py プロジェクト: Ms2ger/standup
    def test_profile_authenticated(self):
        """Test that you can see profile page if you are logged in."""
        with self.app.app_context():
            u = user(email='*****@*****.**', save=True)

        authenticate(self.client, u)

        response = self.client.get('/profile/')
        eq_(response.status_code, 200)
コード例 #31
0
 def test_timeline(self):
     """Test the home_timeline endpoint"""
     with self.app.app_context():
         u = user(save=True, team={})
         p = project(save=True)
         status(user=u, project=p, save=True)
     response = self.client.get(self._url())
     eq_(response.status_code, 200)
     eq_(response.content_type, 'application/json')
コード例 #32
0
ファイル: test_status.py プロジェクト: robhudson/standup
    def test_status_reply_count(self):
        """Test the reply_count property of the Status model."""
        with self.app.app_context():
            u = user(save=True)
            s = status(user=u, project=None, save=True)
            for i in range(5):
                status(user=u, project=None, reply_to=s, save=True)

            eq_(s.reply_count, 5)
コード例 #33
0
ファイル: test_api2.py プロジェクト: safwanrahman/standup
    def setUp(self):
        super(TeamMembersTestCase, self).setUp()

        self.query = {"slug": "test"}
        self.url = "/api/v2/teams/members.json"

        with self.app.app_context():
            self.team = team(slug=self.query["slug"], name="Test Team", save=True)
            self.user = user(save=True)
コード例 #34
0
    def test_profile_authenticated(self):
        """Test that you can see profile page if you are logged in."""
        with self.app.app_context():
            u = user(email='*****@*****.**', save=True)

        authenticate(self.client, u)

        response = self.client.get('/profile/')
        eq_(response.status_code, 200)
コード例 #35
0
ファイル: test_api2.py プロジェクト: chinna1986/standup
 def test_timeline(self):
     """Test the home_timeline endpoint"""
     with self.app.app_context():
         u = user(save=True, team={})
         p = project(save=True)
         status(user=u, project=p, save=True)
     response = self.client.get(self._url())
     eq_(response.status_code, 200)
     eq_(response.content_type, 'application/json')
コード例 #36
0
    def test_status_reply_count(self):
        """Test the reply_count property of the Status model."""
        with self.app.app_context():
            u = user(save=True)
            s = status(user=u, project=None, save=True)
            for i in range(5):
                status(user=u, project=None, reply_to=s, save=True)

            eq_(s.reply_count, 5)
コード例 #37
0
ファイル: test_database.py プロジェクト: safwanrahman/standup
    def setUp(self):
        super(HelpersTestCase, self).setUp()
        with self.app.app_context():
            u = user(username='******', save=True)
            for i in range(100):
                status(project=None, user=u, save=True)

        db = get_session(self.app)
        self.query = db.query(Status).order_by(Status.id)
コード例 #38
0
ファイル: test_status.py プロジェクト: robhudson/standup
    def test_status(self):
        """Test posting a status."""
        with self.app.app_context():
            u = user(email='*****@*****.**', save=True)

        authenticate(self.client, u)

        rv = self.client.post('/statusize/', data={'message': 'foo'},
                              follow_redirects=True)
        eq_(rv.status_code, 200)
コード例 #39
0
    def test_user_view(self):
        """Make sure the user view works like it's supposed to."""
        with self.app.app_context():
            u = user(save=True)

        response = self.client.get('/user/%s' % u.slug)
        eq_(response.status_code, 200)

        response = self.client.get('/user/not-a-real-user')
        eq_(response.status_code, 404)
コード例 #40
0
ファイル: test_api.py プロジェクト: chinna1986/standup
    def test_update_user_validation(self):
        """Verify validation of required fields when updating a user"""
        with self.app.app_context():
            u = user(save=True)

        # Missing user
        data = json.dumps({'api_key': self.app.config.get('API_KEY')})
        response = self.client.post('/api/v1/user/%s/' % u.id, data=data,
                                    content_type='application/json')
        eq_(response.status_code, 400)
コード例 #41
0
ファイル: test_api2.py プロジェクト: chinna1986/standup
    def setUp(self):
        super(TeamMembersTestCase, self).setUp()

        self.query = {'slug': 'test'}
        self.url = '/api/v2/teams/members.json'

        with self.app.app_context():
            self.team = team(slug=self.query['slug'], name='Test Team',
                             save=True)
            self.user = user(save=True)
コード例 #42
0
ファイル: test_status.py プロジェクト: robhudson/standup
    def test_user_view(self):
        """Make sure the user view works like it's supposed to."""
        with self.app.app_context():
            u = user(save=True)

        response = self.client.get('/user/%s' % u.slug)
        eq_(response.status_code, 200)

        response = self.client.get('/user/not-a-real-user')
        eq_(response.status_code, 404)
コード例 #43
0
    def setUp(self):
        super(TeamMembersTestCase, self).setUp()

        self.query = {'slug': 'test'}
        self.url = '/api/v2/teams/members.json'

        with self.app.app_context():
            self.team = team(slug=self.query['slug'], name='Test Team',
                             save=True)
            self.user = user(save=True)
コード例 #44
0
    def test_udate_user_invalid_api_key(self):
        """Request with invalid API key should return 403"""
        with self.app.app_context():
            u = user(save=True)

        data = json.dumps({'user': u.username})
        response = self.client.post('/api/v1/user/%s/' % u.id,
                                    data=data,
                                    content_type='application/json')
        eq_(response.status_code, 403)
コード例 #45
0
ファイル: test_status.py プロジェクト: robhudson/standup
    def test_status_no_message(self):
        """Test posting a status with no message."""
        with self.app.app_context():
            u = user(email='*****@*****.**', save=True)

        authenticate(self.client, u)

        rv = self.client.post('/statusize/', data={'message': ''},
                              follow_redirects=True)
        # This kicks up a 404, but that's lame.
        eq_(rv.status_code, 404)
コード例 #46
0
ファイル: test_api2.py プロジェクト: chinna1986/standup
    def setUp(self):
        super(CreateTeamMemberTestCase, self).setUp()

        with self.app.app_context():
            self.user = user(save=True)
            self.team = team(save=True)

        self.url = '/api/v2/teams/members/create.json'
        self.data = {'slug': self.team.slug,
                     'screen_name': self.user.username,
                     'api_key': self.app.config.get('API_KEY')}
コード例 #47
0
ファイル: test_api.py プロジェクト: chinna1986/standup
    def test_update_user_invalid_api_key(self):
        """Request with invalid API key should return 403"""
        with self.app.app_context():
            u = user(save=True)

        data = json.dumps({
            'api_key': self.app.config.get('API_KEY') + '123',
            'user': u.username})
        response = self.client.post('/api/v1/user/%s/' % u.id, data=data,
                                    content_type='application/json')
        eq_(response.status_code, 403)
コード例 #48
0
    def test_update_user_validation(self):
        """Verify validation of required fields when updating a user"""
        with self.app.app_context():
            u = user(save=True)

        # Missing user
        data = json.dumps({'api_key': self.app.config.get('API_KEY')})
        response = self.client.post('/api/v1/user/%s/' % u.id,
                                    data=data,
                                    content_type='application/json')
        eq_(response.status_code, 400)
コード例 #49
0
    def setUp(self):
        super(CreateTeamMemberTestCase, self).setUp()

        with self.app.app_context():
            self.user = user(save=True)
            self.team = team(save=True)

        self.url = '/api/v2/teams/members/create.json'
        self.data = {'slug': self.team.slug,
                     'screen_name': self.user.username,
                     'api_key': self.app.config.get('API_KEY')}
コード例 #50
0
ファイル: test_api.py プロジェクト: chinna1986/standup
    def test_delete_status_does_not_exist(self):
        """Request to delete a non existent status should return 400"""
        with self.app.app_context():
            u = user(save=True)

        data = json.dumps({
            'api_key': self.app.config.get('API_KEY'),
            'user': u.username})
        response = self.client.delete('/api/v1/status/%s/' % 9999, data=data,
                                      content_type='application/json')
        eq_(response.status_code, 400)
コード例 #51
0
    def test_team_view(self):
        """Make sure the project view works like it's supposed to."""
        with self.app.app_context():
            u = user(save=True)
            t = team(users=[u], save=True)

        response = self.client.get('/team/%s' % t.slug)
        eq_(response.status_code, 200)

        response = self.client.get('/team/not-a-real-team')
        eq_(response.status_code, 404)
コード例 #52
0
    def test_status_with_project(self):
        """Test posting a status with a project."""
        with self.app.app_context():
            u = user(email='*****@*****.**', save=True)
            p = project(name='blackhole', slug='blackhole', save=True)
            data = {'message': 'r1cky rocks!', 'project': p.id}

        authenticate(self.client, u)

        rv = self.client.post('/statusize/', follow_redirects=True, data=data)
        eq_(rv.status_code, 200)
コード例 #53
0
    def test_status(self):
        """Test posting a status."""
        with self.app.app_context():
            u = user(email='*****@*****.**', save=True)

        authenticate(self.client, u)

        rv = self.client.post('/statusize/',
                              data={'message': 'foo'},
                              follow_redirects=True)
        eq_(rv.status_code, 200)
コード例 #54
0
 def test_status_weeks_at_year_start(self):
     """Test the week_{start|end} function around the start of the year."""
     d = datetime(2013, 12, 31, 12, 13, 45, 0)
     with self.app.app_context():
         u = user(username='******', save=True)
         s = status(content='my status update',
                    created=d,
                    user=u,
                    save=True)
     eq_(s.week_start.strftime("%Y-%m-%d"), "2013-12-30")
     eq_(s.week_end.strftime("%Y-%m-%d"), "2014-01-05")
コード例 #55
0
 def test_status_week_end(self):
     """Test the week_end function of the Status model."""
     d = datetime(2014, 5, 8, 17, 17, 51, 0)
     with self.app.app_context():
         u = user(username='******', save=True)
         s = status(content='my status update',
                    created=d,
                    user=u,
                    save=True)
     d_actual = s.week_end.strftime("%Y-%m-%d")
     eq_(d_actual, "2014-05-11")  # Happy Mother's Day!
コード例 #56
0
    def test_status_no_message(self):
        """Test posting a status with no message."""
        with self.app.app_context():
            u = user(email='*****@*****.**', save=True)

        authenticate(self.client, u)

        rv = self.client.post('/statusize/',
                              data={'message': ''},
                              follow_redirects=True)
        # This kicks up a 404, but that's lame.
        eq_(rv.status_code, 404)
コード例 #57
0
    def test_delete_status_does_not_exist(self):
        """Request to delete a non existent status should return 400"""
        with self.app.app_context():
            u = user(save=True)

        data = json.dumps({
            'api_key': self.app.config.get('API_KEY'),
            'user': u.username
        })
        response = self.client.delete('/api/v1/status/%s/' % 9999,
                                      data=data,
                                      content_type='application/json')
        eq_(response.status_code, 400)
コード例 #58
0
    def test_status_replies(self):
        """Test the loading of replies for a status."""
        with self.app.app_context():
            p = project(save=True)
            u = user(save=True)
            s = status(project=p, user=u, save=True)

            for i in range(30):
                status(project=p, user=u, reply_to=s, save=True)

            page = s.replies()

        eq_(page.pages, 2)
コード例 #59
0
    def test_create_reply(self):
        """Test creation of replies"""
        db = get_session(self.app)

        with self.app.app_context():
            u = user(save=True)
            s = status(user=u, save=True)
            sid = s.id

            data = json.dumps({
                'api_key': self.app.config.get('API_KEY'),
                'user': u.username,
                'content': 'reply to status',
                'reply_to': sid
            })
            response = self.client.post('/api/v1/status/',
                                        data=data,
                                        content_type='application/json')
            eq_(response.status_code, 200)

            # Verify that the status is actually a reply
            r = db.query(Status).filter(Status.reply_to_id == sid).first()
            eq_(r.content, 'reply to status')

            # Verify that the reply is included in the list of replies
            s = db.query(Status).get(sid)
            assert r in s.replies().items

            # You should not be able to reply to the reply
            data = json.dumps({
                'api_key': self.app.config.get('API_KEY'),
                'user': '******',
                'content': 'should not work',
                'reply_to': r.id
            })
            response = self.client.post('/api/v1/status/',
                                        data=data,
                                        content_type='application/json')
            eq_(response.status_code, 400)

            # You should not be able to reply to a status that does not exist
            data = json.dumps({
                'api_key': self.app.config.get('API_KEY'),
                'user': '******',
                'content': 'reply to status',
                'reply_to': 9999
            })
            response = self.client.post('/api/v1/status/',
                                        data=data,
                                        content_type='application/json')
            eq_(response.status_code, 400)
コード例 #60
0
    def test_login(self):
        """Test the login view."""
        with self.app.app_context():
            u = user(save=True)

        authenticate(self.client, u)

        response = self.client.post('/logout')
        eq_(response.status_code, 200)
        assert 'logout successful' in response.data

        with self.client.session_transaction() as sess:
            assert 'email' not in sess
            assert 'user_id' not in sess