def client(): app.app_context().push() db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['TESTING'] = True client = app.test_client() with app.app_context(): db.create_all() yield client os.close(db_fd) os.unlink(app.config['DATABASE'])
def create_basic_database(): os.remove("superform/superform.db") app.app_context().push() models.db.create_all() user = User() user.id = 'myself' user.email = '*****@*****.**' user.name = 'And I' user.first_name = 'Me Myself' user.admin = 1 db.session.add(user) db.session.commit()
def client(): app.app_context().push() db_fd, database = tempfile.mkstemp() app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///" + database + ".db" app.config['TESTING'] = True client = app.test_client() with app.app_context(): db.create_all() yield client clear_data(db.session) os.close(db_fd) app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///superform.db"
def prepare(): if os.path.exists(TESTDB_PATH): os.unlink(TESTDB_PATH) app.app_context().push() models.db.app = app models.db.create_all() pytest.driver = selenium_utils.get_chrome() pytest.now = datetime.datetime.now().strftime("%d%m%Y") pytest.linkedin_title_max = 200 pytest.linkedin_description_max = 256 pytest.slack_title_max = 40000 pytest.slack_description_max = 40000 keepass.set_entry_from_keepass('account_superform') selenium_utils.login(pytest.driver, keepass.KeepassEntry.username, keepass.KeepassEntry.password) connection = sqlite3.connect(TESTDB_PATH) cursor = connection.cursor() sql_command = """ UPDATE user SET admin = 1 WHERE id = 'superego'; """ cursor.execute(sql_command) connection.commit() connection.close() pytest.driver.close() pytest.driver = selenium_utils.get_chrome() selenium_utils.login(pytest.driver, keepass.KeepassEntry.username, keepass.KeepassEntry.password) selenium_utils.create_simple_channel(pytest.driver, 'test_rss', 'rss') selenium_utils.add_authorization(pytest.driver, 'test_rss', 'superego', 2) selenium_utils.create_simple_channel(pytest.driver, 'test_gcal', 'gcal') selenium_utils.add_authorization(pytest.driver, 'test_gcal', 'superego', 2) selenium_utils.modify_config_gcal( pytest.driver, 2, '{"access_token": "ya29.GlxFBgl-MEOI2NojpWSffhjjcfLPhIT55MNauXbQGD4JZQttj45NUKTtaGEd6GpA1GqRUAAhcDYNnK6s7Dyxpx_50N0EPGiKZJrUcPujhrx2eFaRHO94nGrVDpOlVg", "client_id": "408596117278-fkeuv3g0rdkrdpqsch2i1u18h0lgsakm.apps.googleusercontent.com", "client_secret": "EEZoDYXiIq3q-6zoSUrl9ec8", "refresh_token": "1/OEYHMvVkUmfS9C_CVqYccME6zKCANhB_YcU3SwzA2I3VjsBTr4ecnN1CqSchdDXs", "token_expiry": "2018-10-29T17:15:53Z", "token_uri": "https://www.googleapis.com/oauth2/v3/token", "user_agent": None, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": None, "id_token_jwt": None, "token_response": {"access_token": "ya29.GlxFBgl-MEOI2NojpWSffhjjcfLPhIT55MNauXbQGD4JZQttj45NUKTtaGEd6GpA1GqRUAAhcDYNnK6s7Dyxpx_50N0EPGiKZJrUcPujhrx2eFaRHO94nGrVDpOlVg", "expires_in": 3600, "scope": "https://www.googleapis.com/auth/calendar", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/calendar"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": False, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}' ) yield pytest.driver.close()
def test_get_module_ictv(): """ Tests if the module ictv is active :return: """ with app.app_context(): module_name = "ictv" m = get_module_full_name(module_name) assert m == "superform.plugins.ictv"
def test_run(): with app.app_context(): my_publy = Publish(0, "TitleTestForTheICTV_ChannelSlide1", "DescriptionTestForTheICTV_ChannelSlide1", "", None, datetime.datetime.strptime('Jun 29 2018 1:33PM', '%b %d %Y %I:%M%p'), datetime.datetime.strptime('Jun 30 2018 1:33PM', '%b %d %Y %I:%M%p'), {"ictv_list": [{'title-1':{'text': 'Awesome title!'}, 'subtitle-1':{'text': 'Subtile subtitle'}, 'text-1':{'text': 'Very long textual text here'}, 'logo-1':{'src': 'michelfra.svg'}, 'image-1':{"src": "http://thecatapi.com/api/images/get"}, 'background-1':"color", 'duration':5000}] }) run = ictv.run(my_publy,None) assert run == True # GET the capsule /capsules/1 urlData = "http://www.mocky.io/v2/5c099a843500006c00a85e07" webURL = urllib.request.urlopen(urlData) assert 200 == webURL.getcode() data = webURL.read() encoding = webURL.info().get_content_charset('utf-8') # Header data test data_header = json.loads(data.decode(encoding))['slides'][0] assert 5000 == data_header['duration'] assert 1 == data_header['id'] # Content data test data_content = data_header['content'] assert {'text': 'Awesome title!'} == data_content['title-1'] assert {'text': 'Subtile subtitle'} == data_content['subtitle-1'] assert {'text': 'Very long textual text here'} == data_content['text-1'] assert {'src': 'http://thecatapi.com/api/images/get'} == data_content['image-1'] assert {'src': 'michelfra.svg'} == data_content['logo-1'] # DELETE the capsule capsules/1 urlData = "http://www.mocky.io/v2/5c09a10c3500006c00a85e10" webURL = urllib.request.urlopen(urlData) assert 204 == webURL.getcode()