Exemple #1
0
class AstrosTest(TestCase):
    """Test the number of astros API"""
    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_load_astros(self):
        r = self.w.get('/astros.json')
        self.assertFalse(r.flashes)
        r = self.w.get('/astros/')
        self.assertFalse(r.flashes)
        r = self.w.get('/astros/v1')
        self.assertFalse(r.flashes)

    def test_data(self):
        r = self.w.get('/astros.json')
        r.charset = 'utf8'
        try:
            data = json.loads(r.text)
        except:
            self.fail("ISS API not a valid JSON responce")

        # Success message
        self.assertEqual(data['message'], "success",
                         "ISS API Did not return 'sucess' message")

        # data exists
        self.assertTrue('number' in data)
        self.assertEqual(type(data['number']), int)
        self.assertTrue('people' in data)
Exemple #2
0
class IssNowTest(TestCase):
    """Test the ISS-now API"""
    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_load(self):
        # Test the endpoints
        r = self.w.get('/iss-now.json')
        self.assertFalse(r.flashes)
        r = self.w.get('/iss-now/')
        self.assertFalse(r.flashes)
        r = self.w.get('/iss-now/v1')
        self.assertFalse(r.flashes)

    def test_data(self):
        r = self.w.get('/iss-now.json')
        r.charset = 'utf8'
        try:
            data = json.loads(r.text)
        except:
            self.fail("ISS API not a valid JSON responce")

        # Success message
        self.assertEqual(data['message'], "success",
                         "ISS API Did not return 'sucess' message")

        # timestamp exists
        self.assertTrue('timestamp' in data)

        # position data
        self.assertTrue('iss_position' in data)
        self.assertTrue('latitude' in data['iss_position'])
        self.assertTrue('longitude' in data['iss_position'])
Exemple #3
0
class AstrosTest(TestCase):
    """Test the number of astros API"""

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_load_astros(self):
        r = self.w.get('/astros.json')
        self.assertFalse(r.flashes)
        r = self.w.get('/astros/')
        self.assertFalse(r.flashes)
        r = self.w.get('/astros/v1')
        self.assertFalse(r.flashes)

    def test_data(self):
        r = self.w.get('/astros.json')
        r.charset = 'utf8'
        try:
            data = json.loads(r.text)
        except:
            self.fail("ISS API not a valid JSON responce")

        # Success message
        self.assertEqual(data['message'], "success", "ISS API Did not return 'sucess' message")

        # data exists
        self.assertTrue('number' in data)
        self.assertEqual(type(data['number']), int)
        self.assertTrue('people' in data)
Exemple #4
0
class IssPassTest(TestCase):
    """Test ISS-pass API"""
    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)
        self.endpoint = '/iss-pass.json'

    def format_uri(self, lat, lon):
        return self.endpoint + '?lat={0}&lon={1}'.format(lat, lon) 
    
    def test_berkeley(self):
        berkeley = self.format_uri(37.8715926, -122.27274699999998)
        r = self.w.get(berkeley)
        r.charset = 'utf8'
        data = json.loads(r.text)
        self.assertEqual(r.status_code, 200)

    def test_no_passes_found(self):
        mcmurdo_station = self.format_uri(-77.8418779, 166.6863449)
        r = self.w.get(mcmurdo_station)
        self.assertEqual(r.status_code, 200)
        data = r.json
        self.assertEqual(len(data['response']), 0)

    def test_bad_lat(self):
        bad_lat = self.format_uri(-91, 50)
        r = self.w.get(bad_lat, expect_errors=True)
        self.assertEqual(r.status_code, 400)
Exemple #5
0
class IssNowTest(TestCase):
    """Test the ISS-now API"""

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_load(self):
        # Test the endpoints
        r = self.w.get('/iss-now.json')
        self.assertFalse(r.flashes)
        r = self.w.get('/iss-now/')
        self.assertFalse(r.flashes)
        r = self.w.get('/iss-now/v1')
        self.assertFalse(r.flashes)

    def test_data(self):
        r = self.w.get('/iss-now.json')
        r.charset = 'utf8'
        try:
            data = json.loads(r.text)
        except:
            self.fail("ISS API not a valid JSON response")

        # Success message
        self.assertEqual(data['message'], "success", "ISS API Did not return 'sucess' message")

        # timestamp exists
        self.assertTrue('timestamp' in data)

        # position data
        self.assertTrue('iss_position' in data)
        self.assertTrue('latitude' in data['iss_position'])
        self.assertTrue('longitude' in data['iss_position'])
Exemple #6
0
class TestMainFeatures(unittest.TestCase):
    def setUp(self):
        self.app = app1
        self.w = TestApp(self.app)

    def test_single_template(self):
        r = self.w.get('/')
        self.assertFalse(r.flashes)
        self.assertEqual(len(r.contexts), 1)

        self.assertEqual(r.context['text'], 'Hello!')
        self.assertEqual(r.template, 'template.html')
        self.assertNotIn('qwerty', r.session)

    def test_two_templates_and_flash_messages(self):
        r = self.w.get('/').form.submit()
        self.assertEqual(len(r.contexts), 2)

        if flask_gte_0_10:
            self.assertEqual(len(r.flashes), 2)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')

            category, message = r.flashes[1]
            self.assertEqual(message, 'Flash message that will never be shown')
        else:
            self.assertEqual(len(r.flashes), 1)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')

        with self.assertRaises(AssertionError):
            r.context  # Because there are more than one used templates
        self.assertEqual(r.contexts['template.html']['text'], 'Goodbye!')
        self.assertEqual(r.contexts['extra-template.html']['extra_text'],
                         'Some text.')

    def test_session_transaction(self):
        r = self.w.get('/whoami/')
        self.assertEqual(r.body.decode('utf-8'), 'nobody')

        with self.w.session_transaction() as sess:
            sess['username'] = '******'

        r = self.w.get('/whoami/')

        self.assertEqual(r.session['username'], 'aromanovich')
        self.assertEqual(r.body.decode('utf-8'), 'aromanovich')

    def test_init(self):
        w = TestApp(self.app)
        self.assertEqual(w.get('/').status_code, 200)

        original_server_name = self.app.config['SERVER_NAME']
        try:
            self.app.config['SERVER_NAME'] = 'webtest-app.local'
            w = TestApp(self.app)
            self.assertEqual(w.get('/').status_code, 200)
        finally:
            self.app.config['SERVER_NAME'] = original_server_name
Exemple #7
0
    def setUp(self):
        self.app = create_app()
        self.w_without_scoping = TestApp(self.app)
        self.w = TestApp(self.app, db=db, use_session_scopes=True)

        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
Exemple #8
0
    def setUp(self):
        self.app = app2
        self.w_without_scoping = TestApp(self.app)
        self.w = TestApp(self.app, db=db, use_session_scopes=True)

        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
class TestPosts(DbTestCase, LoggedInUserCase):
    def setUp(self):
        self.w = TestApp(self.app)
        self.user = UserFactory(password="******")
        self.user.save()

    def test_can_create(self):
        self._login(self.w, self.user)

        res = self.w.get(url_for("user.add_post"))

        form = res.forms["newPost"]

        form['title'] = "test post please ignore"
        form['subreddit'] = "reddit.com"
        form['body'] = "This is a test post."
        form['distinguish'] = False
        form['sticky'] = False
        form['scheduled_hour'] = 12
        form['scheduled_minute'] = 00

        res = form.submit().follow()
        assert_equal(res.status_code, 200)

    def test_can_submit_edit_form_without_changes(self):
        self._login(self.w, self.user)

        post = PostFactory()

        self.user.posts.append(post)
        self.user.save()

        res = self.w.get(url_for('user.edit_post', id=post.id))
        form = res.forms["newPost"]
        res = form.submit().follow()

    def test_can_edit(self):
        self._login(self.w, self.user)

        post = PostFactory()

        self.user.posts.append(post)
        self.user.save()

        res = self.w.get(url_for('user.edit_post', id=post.id))

        new_title = "this is a test title"

        form = res.forms["newPost"]

        previous_day_value = form['monday']

        form['title'] = new_title
        form['monday'] = not previous_day_value

        res = form.submit().follow()
        assert_equal(post.title, new_title)
        assert_equal(post.days.monday, not previous_day_value)
class TestLoggingIn(DbTestCase):

    def setUp(self):
        self.w = TestApp(self.app)
        self.user = UserFactory(password="******")
        self.user.save()

    def test_can_log_in(self):
        # Goes to homepage
        res = self.w.get("/")
        # Fills out login form in navbar
        form = res.forms['loginForm']
        form['username'] = self.user.username
        form['password'] = '******'
        # Submits
        res = form.submit().maybe_follow()
        assert_equal(res.status_code, 200)

    def _login(self, username, password):
        res = self.w.get("/")
        # Fills out login form in navbar
        form = res.forms['loginForm']
        form['username'] = username
        form['password'] = password
        # Submits
        res = form.submit().maybe_follow()
        return res

    def test_sees_alert_on_log_out(self):
        res = self._login(self.user.username, 'myprecious')
        res = self.w.get(url_for('public.logout')).maybe_follow()
        # sees alert
        assert_in('You are logged out.', res)

    def test_sees_error_message_if_password_is_incorrect(self):
        # Goes to homepage
        res = self.w.get("/")
        # Fills out login form, password incorrect
        form = res.forms['loginForm']
        form['username'] = self.user.username
        form['password'] = '******'
        # Submits
        res = form.submit()
        # sees error
        assert_in("Invalid password", res)

    def test_sees_error_message_if_username_doesnt_exist(self):
        # Goes to homepage
        res = self.w.get("/")
        # Fills out login form, password incorrect
        form = res.forms['loginForm']
        form['username'] = '******'
        form['password'] = '******'
        # Submits
        res = form.submit()
        # sees error
        assert_in("Unknown user", res)
class TestLoggingIn(DbTestCase):
    def setUp(self):
        self.w = TestApp(self.app)
        self.user = UserFactory(password="******")
        self.user.save()

    def test_can_log_in(self):
        # Goes to homepage
        res = self.w.get("/")
        # Fills out login form in navbar
        form = res.forms['loginForm']
        form['username'] = self.user.username
        form['password'] = '******'
        # Submits
        res = form.submit().follow()
        assert_equal(res.status_code, 200)

    def _login(self, username, password):
        res = self.w.get("/")
        # Fills out login form in navbar
        form = res.forms['loginForm']
        form['username'] = username
        form['password'] = password
        # Submits
        res = form.submit().follow()
        return res

    def test_sees_alert_on_log_out(self):
        res = self._login(self.user.username, 'myprecious')
        res = self.w.get(url_for('public.logout')).follow()
        # sees alert
        assert_in('You are logged out.', res)

    def test_sees_error_message_if_password_is_incorrect(self):
        # Goes to homepage
        res = self.w.get("/")
        # Fills out login form, password incorrect
        form = res.forms['loginForm']
        form['username'] = self.user.username
        form['password'] = '******'
        # Submits
        res = form.submit()
        # sees error
        assert_in("Invalid password", res)

    def test_sees_error_message_if_username_doesnt_exist(self):
        # Goes to homepage
        res = self.w.get("/")
        # Fills out login form, password incorrect
        form = res.forms['loginForm']
        form['username'] = '******'
        form['password'] = '******'
        # Submits
        res = form.submit()
        # sees error
        assert_in("Unknown user", res)
Exemple #12
0
    def test_init(self):
        w = TestApp(self.app)
        self.assertEqual(w.get('/').status_code, 200)

        original_server_name = self.app.config['SERVER_NAME']
        try:
            self.app.config['SERVER_NAME'] = 'webtest-app.local'
            w = TestApp(self.app)
            self.assertEqual(w.get('/').status_code, 200)
        finally:
            self.app.config['SERVER_NAME'] = original_server_name
Exemple #13
0
class ApiTests(TestCase):
    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_cassini(self):
        r = self.w.get('/probes/cassini')
        self.assertFalse(r.flashes)

    def test_cassini_mass(self):
        r = self.w.get('/probes/cassini/mass')
        self.assertFalse(r.flashes)
class TestRegistering(DbTestCase):

    def setUp(self):
        self.w = TestApp(self.app)

    def test_can_register(self):
        # Goes to homepage
        res = self.w.get("/")
        # Clicks Create Account button
        res = res.click("Create account")
        # Fills out the form
        form = res.forms["registerForm"]
        form['username'] = '******'
        form['email'] = '*****@*****.**'
        form['password'] = '******'
        form['confirm'] = 'secret'
        # Submits
        res = form.submit().maybe_follow()
        assert_equal(res.status_code, 200)
        # A new user was created
        assert_equal(len(User.query.all()), 1)

    def test_sees_error_message_if_passwords_dont_match(self):
        # Goes to registration page
        res = self.w.get(url_for("public.register"))
        # Fills out form, but passwords don't match
        form = res.forms["registerForm"]
        form['username'] = '******'
        form['email'] = '*****@*****.**'
        form['password'] = '******'
        form['confirm'] = 'secrets'
        # Submits
        res = form.submit()
        # sees error message
        assert_in("Passwords must match", res)

    def test_sees_error_message_if_user_already_registered(self):
        user = UserFactory(active=True)  # A registered user
        user.save()
        # Goes to registration page
        res = self.w.get(url_for("public.register"))
        # Fills out form, but username is already registered
        form = res.forms["registerForm"]
        form['username'] = user.username
        form['email'] = '*****@*****.**'
        form['password'] = '******'
        form['confirm'] = 'secret'
        # Submits
        res = form.submit()
        # sees error
        assert_in("Username already registered", res)
class TestRegistering(DbTestCase):
    def setUp(self):
        self.w = TestApp(self.app)

    def test_can_register(self):
        # Goes to homepage
        res = self.w.get("/")
        # Clicks Create Account button
        res = res.click("Create account")
        # Fills out the form
        form = res.forms["registerForm"]
        form['username'] = '******'
        form['email'] = '*****@*****.**'
        form['password'] = '******'
        form['confirm'] = 'secret'
        # Submits
        res = form.submit().follow()
        assert_equal(res.status_code, 200)
        # A new user was created
        assert_equal(len(User.query.all()), 1)

    def test_sees_error_message_if_passwords_dont_match(self):
        # Goes to registration page
        res = self.w.get(url_for("public.register"))
        # Fills out form, but passwords don't match
        form = res.forms["registerForm"]
        form['username'] = '******'
        form['email'] = '*****@*****.**'
        form['password'] = '******'
        form['confirm'] = 'secrets'
        # Submits
        res = form.submit()
        # sees error message
        assert_in("Passwords must match", res)

    def test_sees_error_message_if_user_already_registered(self):
        user = UserFactory(active=True)  # A registered user
        user.save()
        # Goes to registration page
        res = self.w.get(url_for("public.register"))
        # Fills out form, but username is already registered
        form = res.forms["registerForm"]
        form['username'] = user.username
        form['email'] = '*****@*****.**'
        form['password'] = '******'
        form['confirm'] = 'secret'
        # Submits
        res = form.submit()
        # sees error
        assert_in("Username already registered", res)
Exemple #16
0
class RouteTestCase(BaseTestCase):
    """
    Base test class for dealing with HTTP route handlers.
    """
    def setUp(self):
        super(RouteTestCase, self).setUp()

        # Setup app for testing
        self.app = TestApp(app, db=db, use_session_scopes=True)
        self.app_context = app.app_context()
        self.app_context.push()

        # Setup database for testing
        self.db = db
        self.db.create_all()

        # Create a new user
        user = User(
            email='*****@*****.**',
            password='******')

        self.db.session.add(user)
        self.db.session.commit()

        # Assign the user to the session
        with self.app.session_transaction() as sess:
            sess['user_id'] = user.id

    def tearDown(self):
        # Clean up the test app and database
        db.drop_all()
        self.app_context.pop()
Exemple #17
0
class ResourcesTestCase(TestCase):

    app = app.create_app()
    web_client = TestApp(app)

    def setUp(self):
        super(ResourcesTestCase, self).setUp()
Exemple #18
0
def get_test_app():

    def test_loader(app):
        return load_themes_from(os.path.join(os.path.dirname(__file__), '../themes/'))

    Themes(main.app, app_identifier='yelplove', loaders=[test_loader])

    return TestApp(main.app)
class MyTests(TestCase):

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_base_url_returns_response(self):
        r = self.w.get('/')
        self.assertFalse(r.flashes)
class ViewsTestCase(TestCase):

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test_home(self):

        r = self.w.get('/')

        self.assertEquals(r.status_code, 200)
Exemple #21
0
class TestMainFeatures(unittest.TestCase):
    def setUp(self):
        self.app = app1
        self.w = TestApp(self.app)

    def test_single_template(self):
        r = self.w.get('/')
        self.assertFalse(r.flashes)
        self.assertEqual(len(r.contexts), 1)

        self.assertEqual(r.context['text'], 'Hello!')
        self.assertEqual(r.template, 'template.html')
        self.assertNotIn('qwerty', r.session)

    def test_two_templates_and_flash_messages(self):
        r = self.w.get('/').form.submit()
        self.assertEqual(len(r.contexts), 2)

        if flask_gte_0_10:
            self.assertEqual(len(r.flashes), 2)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')
            
            category, message = r.flashes[1]
            self.assertEqual(message, 'Flash message that will never be shown')
        else:
            self.assertEqual(len(r.flashes), 1)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')

        with self.assertRaises(AssertionError):
            r.context  # Because there are more than one used templates
        self.assertEqual(
            r.contexts['template.html']['text'],
            'Goodbye!')
        self.assertEqual(
            r.contexts['extra-template.html']['extra_text'],
            'Some text.')
Exemple #22
0
class FrontPageTest(TestCase):
    """Test that the front page is rendering"""
    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test(self):
        r = self.w.get('/')

        # Assert there was no messages flashed
        self.assertFalse(r.flashes)

        # Assert that we got an index template
        self.assertEqual(r.template, 'index.html')
Exemple #23
0
class FrontPageTest(TestCase):
    """Test that the front page is rendering"""

    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)

    def test(self):
        r = self.w.get('/')

        # Assert there was no messages flashed
        self.assertFalse(r.flashes)

        # Assert that we got an index template
        self.assertEqual(r.template, 'index.html')
Exemple #24
0
    def test_init(self):
        w = TestApp(self.app)
        self.assertEqual(w.get('/').status_code, 200)

        original_server_name = self.app.config['SERVER_NAME']
        try:
            self.app.config['SERVER_NAME'] = 'webtest-app.local'
            w = TestApp(self.app)
            self.assertEqual(w.get('/').status_code, 200)
        finally:
            self.app.config['SERVER_NAME'] = original_server_name
Exemple #25
0
class WebTestMixin(object):
    def create_app(self):
        config = os.environ.get('KOZMIC_CONFIG', 'kozmic.config.TestingConfig')
        return create_app(config)

    def setup_app_and_ctx(self):
        self.app = self.create_app()
        self.ctx = self.app.app_context()
        self.ctx.push()
        self.w = TestApp(self.app)

    def teardown_app_and_ctx(self):
        self.ctx.pop()

    def login(self, user_id):
        with self.w.session_transaction() as sess:
            sess['user_id'] = user_id
Exemple #26
0
class WebTestMixin(object):
    def create_app(self):
        config = os.environ.get('KOZMIC_CONFIG', 'kozmic.config.TestingConfig')
        return create_app(config)

    def setup_app_and_ctx(self):
        self.app = self.create_app()
        self.ctx = self.app.app_context()
        self.ctx.push()
        self.w = TestApp(self.app)

    def teardown_app_and_ctx(self):
        self.ctx.pop()

    def login(self, user_id):
        with self.w.session_transaction() as sess:
            sess['user_id'] = user_id
Exemple #27
0
class TestSQLAlchemyFeatures(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.w_without_scoping = TestApp(self.app)
        self.w = TestApp(self.app, db=db, use_session_scopes=True)

        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()

    def tearDown(self):
        db.drop_all()
        self.app_context.pop()

    def test_1(self):
        user = User(name='Anton')
        db.session.add(user)
        db.session.commit()

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

        # Note: we did not commit the change to `user`!
        user.name = 'Petr'

        r = self.w_without_scoping.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Petr!')

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

    def test_2(self):
        user = User(name='Anton')
        db.session.add(user)
        db.session.commit()

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

        r = self.w.post('/user/%i/preview/' % user.id, {
            'greeting': 'Hi, %s.',
        })
        self.assertEqual(r.body, 'Hi, Anton.')
        db.session.refresh(user)

        r = self.w_without_scoping.post('/user/%i/preview/' % user.id, {
            'greeting': 'Hi, %s.',
        })
        self.assertEqual(r.body, 'Hi, Anton.')
        self.assertRaises(
            sqlalchemy.exc.InvalidRequestError,
            lambda: db.session.refresh(user))
Exemple #28
0
class TestSQLAlchemyFeatures(unittest.TestCase):
    def setUp(self):
        self.app = app2
        self.w_without_scoping = TestApp(self.app)
        self.w = TestApp(self.app, db=db, use_session_scopes=True)

        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()

    def tearDown(self):
        db.drop_all()
        self.app_context.pop()

    def test_1(self):
        user = User(name='Anton')
        db.session.add(user)
        db.session.commit()

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

        # Note: we did not commit the change to `user`!
        user.name = 'Petr'

        r = self.w_without_scoping.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Petr!')

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

    def test_2(self):
        user = User(name='Anton')
        db.session.add(user)
        db.session.commit()

        r = self.w.get('/user/%i/' % user.id)
        self.assertEqual(r.body, 'Hello, Anton!')

        r = self.w.post('/user/%i/preview/' % user.id, {
            'greeting': 'Hi, %s.',
        })
        self.assertEqual(r.body, 'Hi, Anton.')
        db.session.refresh(user)

        r = self.w_without_scoping.post('/user/%i/preview/' % user.id, {
            'greeting': 'Hi, %s.',
        })
        self.assertEqual(r.body, 'Hi, Anton.')
        self.assertRaises(
            sqlalchemy.exc.InvalidRequestError,
            lambda: db.session.refresh(user))
Exemple #29
0
    def setUp(self):
        super(RouteTestCase, self).setUp()

        # Setup app for testing
        self.app = TestApp(app, db=db, use_session_scopes=True)
        self.app_context = app.app_context()
        self.app_context.push()

        # Setup database for testing
        self.db = db
        self.db.create_all()

        # Create a new user
        user = User(
            email='*****@*****.**',
            password='******')

        self.db.session.add(user)
        self.db.session.commit()

        # Assign the user to the session
        with self.app.session_transaction() as sess:
            sess['user_id'] = user.id
 def setUp(self):
     self.w = TestApp(self.app)
     self.user = UserFactory(password="******")
     self.user.save()
Exemple #31
0
def client(app):
    client = TestApp(app)
    return client
Exemple #32
0
 def setup_class(cls):
     cls.appcls.testing_prep()
     cls.app = flask.current_app
     cls.testapp = TestApp(flask.current_app)
Exemple #33
0
class TestMainFeatures(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.w = TestApp(self.app)
        self.app.config['TESTING'] = True

    def login(self, username, password):
        return self.w.post('/account/login', {
            'email': username,
            'password': password
        })

    def logout(self):
        return self.w.get('/account/logout')

    def test_home(self):
        r = self.w.get('/entry/')
        self.assertFalse(r.flashes)
        self.assertEqual(r.json, {u'code': ResultCode.SUCCESS})

    def test_curd(self):
        # add

        # 登录
        # r = self.login('*****@*****.**', 'admin888')
        # print r
        # assert 'You were logged in' in r.data

        r = self.w.post('/entry/v1/create?category_id=1', {
            'creater_id': 1,
            'modifier_id': 1,

            'entry_type': EntryType.software,

            'title': '文章测试123',
            'content': '文章测试内容123',
            'summary': '123',
            'tags': 'tag1,tag2,tag3',

            'logo': '/1.gif',
            'feature_image': '/1.png',

            'source_title': '',
            'source_url': '',

            'source_type': EntrySourceType.original,

            'slug': 'ar/1',

            'recommend': 1

        })

        if r.json['code'] != ResultCode.SUCCESS:
            print r.json['message']

        print r

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'], [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])

        # update
        r = self.w.post('/entry/v1/edit?category_id=1&entry_id=1', {
            'title': '文章测试123, edit',
        })

        print r
        if r.json['code'] != ResultCode.SUCCESS:
            print r.json['message']

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'], [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])

        return
        # get
        r = self.w.get('/device/%s' % device_id)

        self.assertFalse(r.flashes)
        self.assertEqual(r.json['code'], ResultCode.SUCCESS)
        self.assertTrue(r.json['metadata'])

        # get_list
        r = self.w.get('/device/list?search=%s' % 'len')

        self.assertFalse(r.flashes)
        self.assertEqual(r.json['code'], ResultCode.SUCCESS)
        self.assertTrue(r.json['device_total'] >= 0)

        # del
        r = self.w.post('/device/delete', {
            'device_id': device_id, })

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'], [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])
Exemple #34
0
 def setup_app_and_ctx(self):
     self.app = self.create_app()
     self.ctx = self.app.app_context()
     self.ctx.push()
     self.w = TestApp(self.app)
def webapp():
    return TestApp(_app)
Exemple #36
0
 def setUp(self):
     self.app = create_app()
     self.w = TestApp(self.app)
     self.app.config['TESTING'] = True
Exemple #37
0
 def setUp(self):
     self.app = create_app()
     self.w = TestApp(self.app)
 def setUp(self):
     self.w = TestApp(self.app)
Exemple #39
0
 def setUp(self):
     self.app = app
     self.w = TestApp(self.app)
     self.endpoint = '/iss-pass.json'
Exemple #40
0
class TestMainFeatures(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.w = TestApp(self.app)
        self.app.config['TESTING'] = True

    def login(self, username, password):
        return self.w.post('/account/login', {
            'email': username,
            'password': password
        })

    def logout(self):
        return self.w.get('/account/logout')

    def test_home(self):
        r = self.w.get('/entry/')
        self.assertFalse(r.flashes)
        self.assertEqual(r.json, {u'code': ResultCode.SUCCESS})

    def test_curd(self):
        # add

        # 登录
        # r = self.login('*****@*****.**', 'admin888')
        # print r
        # assert 'You were logged in' in r.data

        r = self.w.post(
            '/entry/v1/create?category_id=1', {
                'creater_id': 1,
                'modifier_id': 1,
                'entry_type': EntryType.software,
                'title': '文章测试123',
                'content': '文章测试内容123',
                'summary': '123',
                'tags': 'tag1,tag2,tag3',
                'logo': '/1.gif',
                'feature_image': '/1.png',
                'source_title': '',
                'source_url': '',
                'source_type': EntrySourceType.original,
                'slug': 'ar/1',
                'recommend': 1
            })

        if r.json['code'] != ResultCode.SUCCESS:
            print r.json['message']

        print r

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'],
                      [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])

        # update
        r = self.w.post('/entry/v1/edit?category_id=1&entry_id=1', {
            'title': '文章测试123, edit',
        })

        print r
        if r.json['code'] != ResultCode.SUCCESS:
            print r.json['message']

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'],
                      [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])

        return
        # get
        r = self.w.get('/device/%s' % device_id)

        self.assertFalse(r.flashes)
        self.assertEqual(r.json['code'], ResultCode.SUCCESS)
        self.assertTrue(r.json['metadata'])

        # get_list
        r = self.w.get('/device/list?search=%s' % 'len')

        self.assertFalse(r.flashes)
        self.assertEqual(r.json['code'], ResultCode.SUCCESS)
        self.assertTrue(r.json['device_total'] >= 0)

        # del
        r = self.w.post('/device/delete', {
            'device_id': device_id,
        })

        self.assertFalse(r.flashes)
        self.assertIn(r.json['code'],
                      [ResultCode.SUCCESS, ResultCode.DATA_EXISTED])
Exemple #41
0
class TestMainFeatures(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.w = TestApp(self.app)

    def test_single_template(self):
        r = self.w.get('/')
        self.assertFalse(r.flashes)
        self.assertEqual(len(r.contexts), 1)

        self.assertEqual(r.context['text'], 'Hello!')
        self.assertEqual(r.template, 'template.html')
        self.assertNotIn('qwerty', r.session)

    def test_two_templates_and_flash_messages(self):
        r = self.w.get('/').form.submit()
        self.assertEqual(len(r.contexts), 2)

        if flask_gte_0_10:
            self.assertEqual(len(r.flashes), 2)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')

            category, message = r.flashes[1]
            self.assertEqual(message, 'Flash message that will never be shown')
        else:
            self.assertEqual(len(r.flashes), 1)
            category, message = r.flashes[0]
            self.assertEqual(message, 'You have pressed "Quit"...')

        with self.assertRaises(AssertionError):
            r.context  # Because there are more than one used templates
        self.assertEqual(
            r.contexts['template.html']['text'],
            'Goodbye!')
        self.assertEqual(
            r.contexts['extra-template.html']['extra_text'],
            'Some text.')

    def test_session_transaction(self):
        r = self.w.get('/whoami/')
        self.assertEqual(r.body, 'nobody')

        with self.w.session_transaction() as sess:
            sess['username'] = '******'

        r = self.w.get('/whoami/')

        self.assertEqual(r.session['username'], 'aromanovich')
        self.assertEqual(r.body, 'aromanovich')

    def test_init(self):
        w = TestApp(self.app)
        self.assertEqual(w.get('/').status_code, 200)

        original_server_name = self.app.config['SERVER_NAME']
        try:
            self.app.config['SERVER_NAME'] = 'webtest-app.local'
            w = TestApp(self.app)
            self.assertEqual(w.get('/').status_code, 200)
        finally:
            self.app.config['SERVER_NAME'] = original_server_name
 def setUp(self):
     self.w = TestApp(self.app)
     self.user = UserFactory(password="******")
     self.user.save()
def client(app):
    client = TestApp(app, db=models.db, use_session_scopes=True)
    return client
Exemple #44
0
 def setup_app_and_ctx(self):
     self.app = self.create_app()
     self.ctx = self.app.app_context()
     self.ctx.push()
     self.w = TestApp(self.app)
 def setUp(self):
     self.w = TestApp(self.app)
Exemple #46
0
 def setUp(self):
     self.app = create_app()
     self.w = TestApp(self.app)
     self.app.config['TESTING'] = True