def test_route_index_logged_in(test_session, test_upload_session):

    with app.test_request_context("/"):
        session.update(test_session)
        assert not has_upload_rights()

    with app.test_request_context("/"):
        session.update(test_upload_session)
        assert has_upload_rights()
def test_user_has_a_valid_role(test_session):
    with app.test_request_context("/"):
        session.update(test_session)
        assert not user_has_a_valid_role(["admin-full"])
        assert user_has_a_valid_role(["standard-download"])
        assert not user_has_a_valid_role(["admin-power", "admin-full"])
        assert user_has_a_valid_role(["standard-upload", "standard-download"])
コード例 #3
0
ファイル: tests.py プロジェクト: jsphyin/idb
    def test_add_Game1(self):

        with app.test_request_context():
            game1 = Game(id=1000000,
                         is_expansion=False,
                         primary_name="game1",
                         alt_names="alt_game1",
                         image="www.test_image.com",
                         desc="This is a test game.",
                         raw_desc="Test game",
                         year=2000,
                         min_players=0,
                         max_players=1,
                         rating=4.321)
            db.session.add(game1)
            db.session.commit()

            gamequery = db.session.query(Game).filter_by(id="1000000").first()
            self.assertEqual(gamequery.id, 1000000)
            self.assertEqual(gamequery.is_expansion, False)
            self.assertEqual(gamequery.primary_name, "game1")
            self.assertEqual(gamequery.alt_names, "alt_game1")

            db.session.delete(game1)
            db.session.commit()
コード例 #4
0
 def test_right_request(self):
     with app.test_request_context('?aircraft=100,141&distance=125,500'):
         aircraft = get_splitted_array('aircraft')
         distance = get_splitted_array('distance')
         self.assertEqual(len(aircraft), 2)
         self.assertEqual(len(distance), 2)
         self.assertEqual(aircraft, ['100', '141'])
コード例 #5
0
 def setUp(self):
     with app.test_request_context():
         # Initializes the database and
         # adds all ideas and users
         db.init()
         register_all_users()
         post_ideas()
コード例 #6
0
def client():
    app.config['TESTING'] = True

    ctx = app.test_request_context()
    ctx.push()

    return app.test_client()
コード例 #7
0
ファイル: tests.py プロジェクト: jsphyin/idb
    def test_add_Game2(self):

        with app.test_request_context():
            game2 = Game(id=1000000,
                         is_expansion=True,
                         primary_name="game2",
                         alt_names="alt_game2",
                         image="www.test_image2.com",
                         desc="This is a test game 2.",
                         raw_desc="Test game 2",
                         year=1997,
                         min_players=2,
                         max_players=4,
                         rating=3.21)
            db.session.add(game2)
            db.session.commit()

            gamequery = db.session.query(Game).filter_by(id="1000000").first()
            self.assertEqual(gamequery.image, "www.test_image2.com")
            self.assertEqual(gamequery.desc, "This is a test game 2.")
            self.assertEqual(gamequery.raw_desc, "Test game 2")
            self.assertEqual(gamequery.year, 1997)

            db.session.delete(game2)
            db.session.commit()
コード例 #8
0
    def test_request_args_to_dict(self, test_input_query: dict) -> None:
        """Test the flask.request.args are converted into a dictionary."""

        # Assert the requests arguments when visiting the /badge page are correct
        with app.test_request_context(path="/badge",
                                      query_string=test_input_query):
            assert request.args.to_dict() == test_input_query
コード例 #9
0
    def test_get_following(self):
        with app.test_request_context():
            user1 = TEST_USERS[0]
            user2 = TEST_USERS[1]
            user3 = TEST_USERS[2]
            user_name1 = user1[0]
            user_name2 = user2[0]
            user_name3 = user3[0]
            main.add_follower(user_name1, user_name3)
            main.add_follower(user_name2, user_name3)
            following_resp = main.get_following(user_name3)

            def correct_following():
                # Creates lists representing the data
                # of users retrieved from the database
                # when fetching a user as a follower
                stored_user1 = user1.copy()
                stored_user2 = user2.copy()
                # Removes the password from the list
                stored_user1.remove(user1[1])
                stored_user2.remove(user2[1])
                # Adds the number of followers, which in
                # this case is 1 since user3 is following
                # both user1 and user2
                stored_user1 += [1]
                stored_user1.remove("image")
                stored_user2 += [1]
                stored_user2.remove("image")
                return following_resp["following"] == [stored_user1, stored_user2]

            self.failIf(not correct_following())
コード例 #10
0
 def setUp(self):
     prepare_db_for_tests()
     self.app = FlaskClient(app, response_wrapper=FormWrapper)
     self.app.application.config["CSRF_ENABLED"] = False
     self.depute = Depute(test_depute).save()
     self.user = create_user("test", "test")
     self.ctx = app.test_request_context()
     self.ctx.push()
コード例 #11
0
 def setUp(self):
     prepare_db_for_tests()
     self.app = FlaskClient(app, response_wrapper=FormWrapper)
     self.app.application.config["CSRF_ENABLED"] = False
     self.depute = Depute(test_depute).save()
     self.user = create_user("test", "test")
     self.ctx = app.test_request_context()
     self.ctx.push()
コード例 #12
0
    def test_user_registration(self):
        with app.test_request_context():
            response = register_user(TEST_USERS[0])

            def user_registered():
                return response["response"] == "Success"

            self.failIf(not user_registered())
コード例 #13
0
def test_get_issues_ETA():
    import requests as req
    from main import app
    from main import tc
    api = taiga_login()
    with app.test_request_context():
        res = tc.get(api + "/issues/by_ref?ref=142&project=2")
        assert res
コード例 #14
0
ファイル: utils.py プロジェクト: SonyPony/pybots-server
    def test_args_to_kwargs(self):
        params = dict(foo='bar', bar='foo', c='6')

        def view(**kwargs):
            self.assertDictEqual(params, kwargs)

        with app.test_request_context('/?{}'.format(url_encode(params))):
            decorated = args_to_kwargs(view)
            decorated()
コード例 #15
0
ファイル: models.py プロジェクト: makerscraft/sweeps
 def sweep(self, asof, _verbose=True):
     if _verbose: print "Sweeping %s %s asof %s" % (self.__class__.__name__, self.name, asof)
     num_swept = 0
     with app.test_request_context():
         for instance in self.get_instances(asof):
             if self.allowed_to_run(instance):
                 self._run_one(instance)
                 num_swept+=1
     if _verbose: print "Swept %s." % (num_swept)
コード例 #16
0
ファイル: conftest.py プロジェクト: tupm2208/soundchat_server
def app(request):
    ctx = _app.test_request_context()
    ctx.push()

    def teardown():
        ctx.pop()

    request.addfinalizer(teardown)
    return app
コード例 #17
0
 def setUp(self):
     app = Flask(__name__)
     Babel(app, default_domain='all')
     app.config['BABEL_DEFAULT_LOCALE'] = 'en'
     app.config['BABEL_TRANSLATION_DIRECTORIES'] = '../i18n'
     # TODO(beets): Change language codes in this test back to zh once
     # that's added to the AVAILABLE_LANGUAGES
     self.context = app.test_request_context(
         '/api/landingpage/data/geoId/06?hl=ru')
コード例 #18
0
def taiga_login():
    from main import app
    from main import tc
    username = '******'
    password = '******'
    api = app.config['API_URL']
    with app.test_request_context():
        tc.login(username, password)
    return api
コード例 #19
0
ファイル: utils.py プロジェクト: SonyPony/pybots-server
    def test_form_to_kwargs(self):
        params = dict(bar='bar', foo='foo', ba='5')

        def view(**kwargs):
            self.assertDictEqual(params, kwargs)

        with app.test_request_context('/', method='POST', data=params):
            decorated = form_to_kwargs(view)
            decorated()
コード例 #20
0
 def setUp(self):
     with app.test_request_context():
         # Initializes the database
         # and adds all users
         db.init()
         register_all_users()
         post_ideas()
         send_messages()
         post_comments()
コード例 #21
0
    def test_login_incorrect_password(self):
        with app.test_request_context():
            user = TEST_USERS[0]
            register_user(user)
            response = main.login_user(user[0], "foo")

            def login_failed():
                return response["response"] == "Incorrect Password"

            self.failIf(not login_failed())
コード例 #22
0
    def test_get_avatar_image(self):
        with app.test_request_context():
            user = TEST_USERS[0]
            register_user(user)
            response = main.get_avatar_image(user[0])

            def correct_img_string():
                return response["avatar_image"] == "image"

            self.failIf(not correct_img_string())
コード例 #23
0
 def test_wrong_request(self):
     with app.test_request_context('?aircraft=100&distance=125'):
         aircraft = get_splitted_array('aircraft')
         distance = get_splitted_array('distance')
         res = get_info_from_database(aircraft, distance)
         self.assertEqual(res, [{
             "Aircraft_number": "100",
             "co2": 1296,
             "km": "125"
         }])
コード例 #24
0
ファイル: test_auth.py プロジェクト: muellert/taigabuddy
def test_admin_login():
    """Testing the login process with a test client"""
    from main import app
    from main.auth import User, user_factory
    User.set_url(app.config['AUTH_URL'])
    with app.test_request_context():
        u = user_factory("admin")
        assert u
        u.login("admin", "123123")
        assert u.is_authenticated
コード例 #25
0
    def test_existing_user_name(self):
        with app.test_request_context():
            register_user(TEST_USERS[0])
            existing_user_name = TEST_USERS[0][0]
            response = main.register_user(existing_user_name, "foo", "bar", "foo", "bar", "img")

            def user_name_exists():
                return response["response"] == "User Name Taken"

            self.failIf(not user_name_exists())
コード例 #26
0
    def test_existing_e_mail(self):
        with app.test_request_context():
            register_user(TEST_USERS[0])
            existing_e_mail = TEST_USERS[0][2]
            response = main.register_user("foo", "bar", existing_e_mail, "foo", "bar", "img")

            def e_mail_exists():
                return response["response"] == "E-Mail Already Registered"

            self.failIf(not e_mail_exists())
コード例 #27
0
    def test_is_following(self):
        with app.test_request_context():
            user1 = TEST_USERS[0][0]
            user2 = TEST_USERS[1][0]
            main.add_follower(user1, user2)
            is_following_resp = main.user_is_following(user2, user1)

            def user_is_following():
                return is_following_resp["is_following"]

            self.failIf(not user_is_following())
コード例 #28
0
ファイル: tests.py プロジェクト: jsphyin/idb
    def test_get_Event2(self):

        with app.test_request_context():
            res = requests.get(self.events_url + "/" + str(387),
                               headers=self.headers)
            self.assertEqual(res.status_code, 200)
            json_res = json.loads(res.text)
            db_res = db.session.query(Event).get(387)

            self.assertEqual(json_res['location'], db_res.location)
            self.assertEqual(json_res['link'], db_res.link)
コード例 #29
0
ファイル: tests.py プロジェクト: jsphyin/idb
    def test_get_Developer1(self):

        with app.test_request_context():
            res = requests.get(self.developers_url + "/" + str(81),
                               headers=self.headers)
            self.assertEqual(res.status_code, 200)
            json_res = json.loads(res.text)
            db_res = db.session.query(Developer).get(81)

            self.assertEqual(json_res['id'], db_res.id)
            self.assertEqual(json_res['img'], db_res.image)
コード例 #30
0
    def test_get_message_feed(self):
        with app.test_request_context():
            # Gets the the most recent message
            # sent by any user to the given user
            # ordered by most recent message sent
            message_feed = main.get_message_feed("Bender")

            def correct_message_feed():
                return message_feed["messages"] == [TEST_MESSAGES[3], TEST_MESSAGES[1]]

        self.failIf(not correct_message_feed())
コード例 #31
0
    def test_add_follower(self):
        with app.test_request_context():
            user1 = TEST_USERS[0][0]
            user2 = TEST_USERS[1][0]
            main.add_follower(user1, user2)
            user_data = main.get_user_data(user1)

            def follower_added():
                return user_data["followers"] == 1

        self.failIf(not follower_added())
コード例 #32
0
    def test_add_comment(self):
        with app.test_request_context():
            post_comment(TEST_COMMENTS[0])
            post_comment(TEST_COMMENTS[1])
            post_comment(TEST_COMMENTS[2])

            def comments_posted_correctly():
                scen_1 = main.get_comments(1)["comments"] == [RETURNED_TEST_COMMENTS[0], RETURNED_TEST_COMMENTS[1]]
                scen_2 = main.get_comments(2)["comments"] == [RETURNED_TEST_COMMENTS[2]]
                return scen_1 and scen_2

            self.failIf(not comments_posted_correctly())
コード例 #33
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_existing_e_mail_update(self):
        with app.test_request_context():
            user1 = TEST_USERS[0]
            user2 = TEST_USERS[1]
            response = main.update_user_data(user1[0], user1[2],  # Original user name and e-mail
                                             user1[0], user2[2],  # New user name and email
                                             user1[1], user1[3], user1[4], "Not set", user1[5])

            def correct_response():
                return response["response"] == "E-Mail Exists"

            self.failIf(not correct_response())
コード例 #34
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_idea_feed_fetch(self):
        with app.test_request_context():
            user1 = TEST_USERS[0]
            user2 = TEST_USERS[1]
            post_ideas()
            # Make user1 follow user2
            main.add_follower(user2[0], user1[0])
            response = main.get_idea_feed(user1[0])

            def correct_idea_feed():
                return response["ideas"] == [STORED_TEST_IDEAS[0], STORED_TEST_IDEAS[1]]

            self.failIf(not correct_idea_feed())
コード例 #35
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_login_user(self):
        with app.test_request_context():
            user = TEST_USERS[0]
            register_user(user)
            user_name_response = main.login_user(user[0], user[1])
            e_mail_response = main.login_user(user[2], user[1])

            def login_succeeded():
                scen_1 = user_name_response["response"] == "Success"
                scen_2 = e_mail_response["response"] == "Success"
                return scen_1 and scen_2

            self.failIf(not login_succeeded())
コード例 #36
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_get_conversation(self):
        with app.test_request_context():
            # Gets the messages sent between
            # the two given people, ordered by
            # the most recent message sent
            conversation1 = main.get_conversation("John", "Sterling Archer")
            conversation2 = main.get_conversation("Sterling Archer", "John")

            def correct_conversation():
                cond_1 = conversation1["messages"] == [TEST_MESSAGES[0], TEST_MESSAGES[4]]
                cond_2 = conversation1["messages"] == conversation2["messages"]
                return cond_1 and cond_2

            self.failIf(not correct_conversation())
コード例 #37
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_login_nonexistent_user(self):
        with app.test_request_context():
            user1 = TEST_USERS[0]
            user2 = TEST_USERS[1]
            register_user(user1)
            user_name_response = main.login_user(user2[0], user2[1])
            e_mail_response = main.login_user(user2[2], user2[1])

            def login_failed():
                scen_1 = user_name_response["response"] == "User doesn't exist"
                scen_2 = e_mail_response["response"] == "User doesn't exist"
                return scen_1 and scen_2

            self.failIf(not login_failed())
コード例 #38
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_get_user_data(self):
        with app.test_request_context():
            user = TEST_USERS[0]
            register_user(user)
            user_data1 = main.get_user_data(user[0])
            user_data2 = main.get_user_data(user[2])

            def correct_data():
                corr_user_name = user_data1["user_name"] == user_data2["user_name"] == user[0]
                corr_e_mail = user_data1["e_mail"] == user_data2["e_mail"] == user[2]
                corr_country = user_data1["country"] == user_data2["country"] == user[3]
                corr_city = user_data1["city"] == user_data2["city"] == user[4]
                corr_followers = user_data1["followers"] == user_data2["followers"] == 0
                corr_location = user_data1["location"] == user_data2["location"] == "Not set"
                return corr_user_name and corr_e_mail and corr_country and corr_city and corr_followers and corr_location

            self.failIf(not correct_data())
コード例 #39
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_other_user_idea_fetch(self):
        with app.test_request_context():
            user1 = TEST_USERS[0]
            user2 = TEST_USERS[1]
            post_ideas()
            # Make user1 follow user2
            main.add_follower(user2[0], user1[0])
            # Fetches the ideas posted by both users
            user1_response = main.get_other_user_recent_ideas(user1[0])
            user2_response = main.get_other_user_recent_ideas(user2[0])

            def correct_ideas_fetched():
                scen_1 = user1_response["ideas"] == [STORED_TEST_IDEAS[0]]
                scen_2 = user2_response["ideas"] == [STORED_TEST_IDEAS[1]]
                return scen_1 and scen_2

            self.failIf(not correct_ideas_fetched())
コード例 #40
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_add_approving(self):
        with app.test_request_context():
            user1 = TEST_USERS[0][0]
            user2 = TEST_USERS[1][0]
            main.add_approving(user1, 1)
            main.add_approving(user1, 2)
            main.add_approving(user2, 1)

            def approving_added_correctly():
                scen_1 = main.user_is_approving(user1, 1)["approving"]
                scen_2 = main.user_is_approving(user1, 2)["approving"]
                scen_3 = main.user_is_approving(user2, 1)["approving"]
                scen_4 = main.get_approving(user1)["approving"] == [STORED_TEST_IDEAS[0], STORED_TEST_IDEAS[1]]
                scen_5 = main.get_approving(user2)["approving"] == [STORED_TEST_IDEAS[0]]
                return scen_1 and scen_2 and scen_3 and scen_4 and scen_5

            self.failIf(not approving_added_correctly())
コード例 #41
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_update_user_data(self):
        with app.test_request_context():
            user = TEST_USERS[0]
            response = main.update_user_data(user[0], user[2],  # Original user name and e-mail
                                             "new_user_name", "new_e_mail",
                                             "new_password", "new_country", "new_city", "new_location", "new_image")

            def correct_response():
                # Checks that the data has been updated in the users table
                user_data1 = main.get_user_data("new_user_name")
                user_data2 = main.get_user_data("new_e_mail")
                scen_1 = user_data1["user_name"] == user_data2["user_name"] == "new_user_name"
                scen_2 = user_data1["e_mail"] == user_data2["e_mail"] == "new_e_mail"
                scen_3 = user_data1["country"] == user_data2["country"] == "new_country"
                scen_4 = user_data1["city"] == user_data2["city"] == "new_city"
                scen_5 = user_data1["location"] == user_data2["location"] == "new_location"
                scen_6 = user_data1["avatar_image"] == user_data2["avatar_image"] == "new_image"
                scen_7 = response["response"] == "Success"
                users_updated = scen_1 and scen_2 and scen_3 and scen_4 and scen_5 and scen_6 and scen_7

                # Checks that the data has been updated in the ideas table
                # Since an idea by the user who's user name has been updated
                # had posted an idea, the function get_most_recent_idea returns
                # a non-empty list when using the new user name as parameter
                ideas_updated = db.get_most_recent_idea("new_user_name") != []

                # Checks that the data has been updated in the messages table
                # Since the original user has sent a message, the return value
                # from get conversation using the new user name and the other
                # user's name has to return a non-empty list
                messages_updated = db.get_conversation("new_user_name", "TestUser2") != []

                # Checks that the data has been updated in the comments table
                # The user who's name was changed posted a comment on the idea with id 2
                comments_updated = False
                for comment in db.get_comments(2):
                    if "new_user_name" in comment:
                        comments_updated = True

                return users_updated and ideas_updated and messages_updated and comments_updated

            self.failIf(not correct_response())
コード例 #42
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_search_people(self):
        with app.test_request_context():
            # Search on user name
            search1 = main.search_people("John")
            # Search on e-mail
            search2 = main.search_people("*****@*****.**")
            # Search on country
            search3 = main.search_people("United States")
            # Search on city
            search4 = main.search_people("Test-City")
            # Search on two identifiers
            search5 = main.search_people("TestUser1&nbhtUnited States")
            # Search on three identifiers
            search6 = main.search_people("Sterling Archer&[email protected]&nbhtNew New York")

            def correct_search_results():
                user1 = TEST_USERS[0]
                user2 = TEST_USERS[1]
                user3 = TEST_USERS[2]
                user4 = TEST_USERS[3]
                user5 = TEST_USERS[4]
                user6 = TEST_USERS[5]
                user7 = TEST_USERS[6]
                scen_1 = search1["people"] == [[user2[0], user2[2], user2[3], user2[4], 0]]
                scen_2 = search2["people"] == [[user3[0], user3[2], user3[3], user3[4], 0]]
                scen_3 = search3["people"] == [[user4[0], user4[2], user4[3], user4[4], 0],
                                               [user5[0], user5[2], user5[3], user5[4], 0],
                                               [user6[0], user6[2], user6[3], user6[4], 0]]
                scen_4 = search4["people"] == [[user1[0], user1[2], user1[3], user1[4], 0],
                                               [user7[0], user7[2], user7[3], user7[4], 0]]
                scen_5 = search5["people"] == [[user1[0], user1[2], user1[3], user1[4], 0],
                                               [user4[0], user4[2], user4[3], user4[4], 0],
                                               [user5[0], user5[2], user5[3], user5[4], 0],
                                               [user6[0], user6[2], user6[3], user6[4], 0]]
                scen_6 = search6["people"] == [[user4[0], user4[2], user4[3], user4[4], 0],
                                               [user6[0], user6[2], user6[3], user6[4], 0],
                                               [user5[0], user5[2], user5[3], user5[4], 0]]
                return scen_1 and scen_2 and scen_3 and scen_4 and scen_5 and scen_6

            self.failIf(not correct_search_results())
コード例 #43
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
    def test_search_ideas(self):
        with app.test_request_context():
            # Searches for ideas with the tag idea
            search1 = main.search_ideas("&nbhtidea")
            # Searches for ideas with the tag long_idea
            search2 = main.search_ideas("&nbhtlong_idea")
            # Searches for ideas with the tags idea or test
            search3 = main.search_ideas("&nbhtidea&nbhttest")
            # Searches for ideas with the tags idea, test or long_idea
            search4 = main.search_ideas("&nbhtidea&nbhtlong_idea&nbhttest")
            # Searches for a non-existent tag
            search5 = main.search_ideas("&nbhtfoo")

            def correct_search_results():
                scen_1 = search1["ideas"] == [STORED_TEST_IDEAS[0], STORED_TEST_IDEAS[1]]
                scen_2 = search2["ideas"] == [STORED_TEST_IDEAS[2]]
                scen_3 = search3["ideas"] == STORED_TEST_IDEAS
                scen_4 = search4["ideas"] == STORED_TEST_IDEAS
                scen_5 = search5["ideas"] == []
                return scen_1 and scen_2 and scen_3 and scen_4 and scen_5

            self.failIf(not correct_search_results())
コード例 #44
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
 def tearDown(self):
     with app.test_request_context():
         # Destroys and closes the database
         db.destroy()
         db.close()
コード例 #45
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
 def setUp(self):
     with app.test_request_context():
         # Sets up the database
         db.init()
コード例 #46
0
ファイル: unit_test.py プロジェクト: Bobberclobber/agora
 def setUp(self):
     with app.test_request_context():
         db.init()
         register_all_users()