How to use test_todo_list method in SeleniumBase

Best Python code snippet using SeleniumBase

test_app.py

Source:test_app.py Github

copy

Full Screen

1from operator import add2from typing import AsyncContextManager3import json4from flask.testing import FlaskClient5from flask.wrappers import Response6from src.app import *7from flask import url_for8from ..data_access import TodoList, db, app, Base, Users, TodoItem, Ledger, BudgetSummary9from _pytest import monkeypatch10import pytest11from unittest.mock import patch, MagicMock12from .configure_test_app import *13from ..user import *14def test_format_action_type_Deposit():15 logs = [Ledger(Action_ID=1)]16 expected_result = Ledger(Action_ID='Deposit')17 actual_result = format_action_type(logs)[0]18 assert actual_result.Action_ID == expected_result.Action_ID19def test_format_action_type_withdrawal():20 logs = [Ledger(Action_ID=2)]21 expected_result = Ledger(Action_ID='Withdrawal')22 actual_result = format_action_type(logs)[0]23 assert actual_result.Action_ID == expected_result.Action_ID24def test_format_action_type_invalid_action_type():25 logs = [Ledger(Action_ID=7)]26 expected_result = Ledger(Action_ID='Action Type not found')27 actual_result = format_action_type(logs)[0]28 assert actual_result.Action_ID == expected_result.Action_ID29def test_format_action_type_no_action_type():30 logs = [Ledger(Action_ID=None)]31 expected_result = Ledger(Action_ID='Action Type not found')32 actual_result = format_action_type(logs)[0]33 assert actual_result.Action_ID == expected_result.Action_ID34def test_balance_calculator_1_add():35 logs = [Ledger(Action_ID=1, Value_in_GBP=1)]36 expected_result = 1.0037 actual_result = balance_calculator(logs)38 assert actual_result == expected_result39def test_balance_calculator_2_sub():40 logs = [Ledger(Action_ID=2, Value_in_GBP=1)]41 expected_result = -1.0042 actual_result = balance_calculator(logs)43 assert actual_result == expected_result44def test_balance_calculator_1_add2items():45 logs = [46 Ledger(Action_ID=1, Value_in_GBP=1),47 Ledger(Action_ID=1, Value_in_GBP=1)48 ]49 expected_result = 2.0050 actual_result = balance_calculator(logs)51 assert actual_result == expected_result52def test_balance_calculator_add_sub_add2items():53 logs = [54 Ledger(Action_ID=1, Value_in_GBP=3),55 Ledger(Action_ID=2, Value_in_GBP=1)56 ]57 expected_result = 2.0058 actual_result = balance_calculator(logs)59 assert actual_result == expected_result60def test_balance_calculator_None():61 logs = [Ledger(Action_ID=None, Value_in_GBP=None)]62 expected_result = 063 actual_result = balance_calculator(logs)64 assert actual_result == expected_result65def test_balance_calculator_empty_list():66 logs = []67 expected_result = 068 actual_result = balance_calculator(logs)69 assert actual_result == expected_result70def test_performance_calculator_empty():71 logs = []72 todo_items = []73 expected_diff = 074 excepted_percenatge = 075 expected_total_costs = 076 actual_diff, actual_percentage, actal_total_costs = performance_calculator(77 todo_items, logs)78 assert actual_diff == expected_diff79 assert actual_percentage == excepted_percenatge80 assert actal_total_costs == expected_total_costs81def test_performance_calculator_single_todoitem():82 logs = [Ledger(Action_ID=1, Value_in_GBP=2)]83 todo_items = [TodoItem(Costs=4)]84 expected_diff = -285 excepted_percenatge = 5086 expected_total_costs = 487 actual_diff, actual_percentage, actal_total_costs = performance_calculator(88 todo_items, logs)89 assert actual_diff == expected_diff90 assert actual_percentage == excepted_percenatge91 assert actal_total_costs == expected_total_costs92def test_performance_calculator_single_todoitem_minus():93 logs = [Ledger(Action_ID=2, Value_in_GBP=4)]94 todo_items = [TodoItem(Costs=4)]95 expected_diff = -896 excepted_percenatge = -10097 expected_total_costs = 498 actual_diff, actual_percentage, actal_total_costs = performance_calculator(99 todo_items, logs)100 assert actual_diff == expected_diff101 assert actual_percentage == excepted_percenatge102 assert actal_total_costs == expected_total_costs103def test_home_with_username(test_client: FlaskClient):104 response = test_client.get("/home?users=TestUsername&first_name='Luke'")105 assert response.status_code == 200106 assert 'Luke' in response.data.decode("utf-8")107 assert 'users=TestUsername' in response.data.decode("utf-8")108def test_home_with_none_user(test_client: FlaskClient):109 response = test_client.get("/home?users=''")110 assert response.status_code == 200111 assert 'there' in response.data.decode("utf-8")112 assert 'users=' in response.data.decode("utf-8")113def test_home_with_no_query(test_client: FlaskClient):114 response = test_client.get("/home")115 assert response.status_code == 200116 assert 'there' in response.data.decode("utf-8")117 assert 'users=' not in response.data.decode("utf-8")118def test_register_get(test_client: FlaskClient):119 response = test_client.get('/register')120 assert response.status_code == 200121 assert 'Join Today' in response.data.decode('utf-8')122def test_register_get_submit(test_client: FlaskClient):123 response = test_client.get('/register')124 assert response.status_code == 200125 assert 'submit' in response.data.decode('utf-8')126def test_register_get_register(test_client: FlaskClient):127 response = test_client.get('/register')128 assert response.status_code == 200129 assert 'register' in response.data.decode('utf-8')130def test_login_get(test_client: FlaskClient):131 response = test_client.get("/login")132 assert response.status_code == 200133 assert 'username' in response.data.decode("utf-8")134 assert 'there' not in response.data.decode("utf-8")135def test_login_get_remeberme(test_client: FlaskClient):136 response = test_client.get("/login")137 assert response.status_code == 200138 assert 'remember' in response.data.decode("utf-8")139 assert 'Login' in response.data.decode("utf-8")140def test_login_get_sign_up(test_client: FlaskClient):141 response = test_client.get("/login")142 assert response.status_code == 200143 assert 'form-check' in response.data.decode("utf-8")144 assert 'Sign Up Here' in response.data.decode("utf-8")145def test_login_get_methods(test_client: FlaskClient):146 response = test_client.get("/login")147 assert response.status_code == 200148 assert 'POST' in response.data.decode("utf-8")149 assert 'next' in response.data.decode("utf-8")150def test_login_get_methods(test_client: FlaskClient):151 response = test_client.get("/login")152 assert response.status_code == 200153 assert 'POST' in response.data.decode("utf-8")154 assert 'next' in response.data.decode("utf-8")155@pytest.fixture()156def db_data_setup():157 student = Users(Username='sniffy13145',158 first_name='slavoj', last_name='zizek')159 db.session.add(student)160 db.session.commit()161 test_todo_list = TodoList(Username=student.Username, Number_of_items=3)162 db.session.add(test_todo_list)163 db.session.commit()164 test_todo_item_1 = TodoItem(Todo_List_ID=test_todo_list.Todo_List_ID,165 Todo_items_Order=1, Description='fun', Costs=3, Title='pancake')166 test_todo_item_2 = TodoItem(Todo_List_ID=test_todo_list.Todo_List_ID,167 Todo_items_Order=2, Description='debate', Costs=4, Title='china')168 test_todo_item_3 = TodoItem(Todo_List_ID=test_todo_list.Todo_List_ID,169 Todo_items_Order=3, Description='endtime', Costs=5, Title='living')170 db.session.add(test_todo_item_1)171 db.session.add(test_todo_item_2)172 db.session.add(test_todo_item_3)173 db.session.commit()174 test_budgetSummary = BudgetSummary(Username=student.Username, Balance=9)175 db.session.add(test_budgetSummary)176 db.session.commit()177 test_ledger = Ledger(178 Budgeter_ID=test_budgetSummary.Budgeter_Id, Action_ID=1, Value_in_GBP=9)179 db.session.add(test_ledger)180 db.session.commit()181 db.session.flush()182 yield student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger183 # remove / reset the data184 db.session.delete(test_ledger)185 db.session.commit()186 db.session.delete(test_budgetSummary)187 db.session.commit()188 db.session.delete(test_todo_item_3)189 db.session.commit()190 db.session.delete(test_todo_item_2)191 db.session.commit()192 db.session.delete(test_todo_item_1)193 db.session.commit()194 db.session.delete(test_todo_list)195 db.session.commit()196 db.session.delete(student)197 db.session.commit()198 db.session.flush()199def test_bucketList_get_table(test_client: FlaskClient, db_data_setup):200 response = test_client.get("bucketList?users=sniffy13145")201 assert response.status_code == 200202 assert 'Preference' in response.data.decode("utf-8")203 assert 'Title' in response.data.decode("utf-8")204def test_bucketList_get_Description(test_client: FlaskClient, db_data_setup):205 response = test_client.get("bucketList?users=sniffy13145")206 assert response.status_code == 200207 assert 'Description' in response.data.decode("utf-8")208 assert 'Cost' in response.data.decode("utf-8")209def test_bucketList_get_todo_items(test_client: FlaskClient, db_data_setup):210 response = test_client.get("bucketList?users=sniffy13145")211 assert response.status_code == 200212 assert 'china' in response.data.decode("utf-8")213 assert 'fun' in response.data.decode("utf-8")214def test_bucketList_get_action(test_client: FlaskClient, db_data_setup):215 response = test_client.get("bucketList?users=sniffy13145")216 assert response.status_code == 200217 assert 'Delete' in response.data.decode("utf-8")218 assert 'Update' in response.data.decode("utf-8")219def test_get_bucket_list_item(test_client: FlaskClient, db_data_setup):220 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup221 response = test_client.get(222 f"bucketList/{test_todo_list.Todo_List_ID}/item/{test_todo_item_1.Id}?users=sniffy13145")223 assert response.status_code == 200224 assert 'fun' in response.data.decode("utf-8")225 assert 'pancake' in response.data.decode("utf-8")226def test_get_bucket_list_item_data(test_client: FlaskClient, db_data_setup):227 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup228 response = test_client.get(229 f"bucketList/{test_todo_list.Todo_List_ID}/item/{test_todo_item_1.Id}?users=sniffy13145")230 assert response.status_code == 200231 assert '1' in response.data.decode("utf-8")232 assert '3' in response.data.decode("utf-8")233def test_delete_bucket_list_item_items(test_client: FlaskClient, db_data_setup):234 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup235 response = test_client.get(236 f"bucketList/{test_todo_list.Todo_List_ID}/item/{test_todo_item_3.Id}/delete?users=sniffy13145", follow_redirects=True)237 assert response.status_code == 200238 assert 'endtime' not in response.data.decode("utf-8")239 assert 'living' not in response.data.decode("utf-8")240def test_delete_bucket_list_item_numberpfbucketitems(test_client: FlaskClient, db_data_setup):241 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup242 response = test_client.get(243 f"bucketList/{test_todo_list.Todo_List_ID}/item/{test_todo_item_3.Id}/delete?users=sniffy13145", follow_redirects=True)244 assert response.status_code == 200245 assert '2' in response.data.decode("utf-8")246 assert '1' in response.data.decode("utf-8")247def test_get_bucket_list(test_client: FlaskClient, db_data_setup):248 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup249 response = test_client.get(250 f"bucketList/{test_todo_list.Todo_List_ID}/item/{test_todo_item_3.Id}/delete?users=sniffy13145", follow_redirects=True)251 assert response.status_code == 200252 assert 'create' not in response.data.decode("utf-8")253 assert 'Bucket_List' in response.data.decode("utf-8")254def test_budgetSummary_balance(test_client: FlaskClient, db_data_setup):255 response = test_client.get("/budgetSummary?users=sniffy13145")256 assert response.status_code == 200257 assert '9' in response.data.decode("utf-8")258 assert 'balance' in response.data.decode("utf-8")259def test_budgetSummary_Action_ID(test_client: FlaskClient, db_data_setup):260 response = test_client.get("/budgetSummary?users=sniffy13145")261 assert response.status_code == 200262 assert 'Deposit' in response.data.decode("utf-8")263 assert '1' in response.data.decode("utf-8")264def test_budgetSummary_Budgeter_Id(test_client: FlaskClient, db_data_setup):265 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup266 response = test_client.get("/budgetSummary?users=sniffy13145")267 assert response.status_code == 200268 assert str(test_budgetSummary.Budgeter_Id) in response.data.decode("utf-8")269def test_get_budgetLedger(test_client: FlaskClient, db_data_setup):270 response = test_client.get("/budgetSummary?users=sniffy13145")271 assert response.status_code == 200272 assert 'budgetSummary' in response.data.decode("utf-8")273 assert 'budgetAction' not in response.data.decode("utf-8")274def test_get_budgetLedger_title(test_client: FlaskClient, db_data_setup):275 response = test_client.get("/budgetSummary?users=sniffy13145")276 assert response.status_code == 200277 assert 'My_Savings_journey' in response.data.decode("utf-8")278 assert 'Create_saving_Action' not in response.data.decode("utf-8")279def test_budgetSummary_Budgeter_Id(test_client: FlaskClient, db_data_setup):280 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup281 response = test_client.get(282 f"budgetSummary/{test_budgetSummary.Budgeter_Id}/item", follow_redirects=True)283 assert response.status_code == 200284 assert 'budgetSummary' in response.data.decode("utf-8")285 assert 'Add_to_your_Savings' not in response.data.decode("utf-8")286def test_budgetSummary_Budgeter_Id(test_client: FlaskClient, db_data_setup):287 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup288 response = test_client.get(289 f"budgetSummary/{test_budgetSummary.Budgeter_Id}/item", follow_redirects=True)290 assert response.status_code == 200291 assert '9' in response.data.decode("utf-8")292 assert str(test_budgetSummary.Budgeter_Id) not in response.data.decode(293 "utf-8")294def test_my_account_diff(test_client: FlaskClient, db_data_setup):295 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup296 response = test_client.get('/myAccount?users=sniffy13145')297 assert response.status_code == 200298 assert 'myAccount' in response.data.decode("utf-8")299 assert '9' in response.data.decode("utf-8")300def test_get_budgetLedger_none(test_client: FlaskClient, db_data_setup):301 response = get_budgetLedger(logs=None, form=LedgerForm())302 assert 'Action' in response303 assert 'Value/GBP' in response304def test_get_budgetLedger_none_with_not_budget_ID(test_client: FlaskClient, db_data_setup):305 response = get_budgetLedger(306 logs=None, form=LedgerForm(), budgeter_ID=None)307 assert 'Action' in response308 assert 'id' in response309def test_bucketList_None(test_client: FlaskClient, db_data_setup):310 response = test_client.get("bucketList", follow_redirects=True)311 assert response.status_code == 200312 assert 'there' in response.data.decode("utf-8")313 assert 'Hello' in response.data.decode("utf-8")314def test_create_bucke_item_None(test_client: FlaskClient, db_data_setup):315 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup316 response = test_client.get(317 f"bucketList/{test_todo_list.Todo_List_ID}/item", follow_redirects=True)318 assert response.status_code == 200319 assert 'there' in response.data.decode("utf-8")320 assert 'Hello' in response.data.decode("utf-8")321def test_budgetsummary_None(test_client: FlaskClient, db_data_setup):322 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup323 response = test_client.get("budgetSummary", follow_redirects=True)324 assert response.status_code == 200325 assert 'there' in response.data.decode("utf-8")326 assert 'Hello' in response.data.decode("utf-8")327def test_get_bucket_list_noneposts_noid(test_client: FlaskClient, db_data_setup):328 response = get_bucket_list(posts=None, list_id=None, form=TodoItemForm())329 assert 'Create_My_Bucket_Item' in response330 assert 'Preference' in response331def test_get_bucket_list_noneposts(test_client: FlaskClient, db_data_setup):332 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup333 response = get_bucket_list(334 posts=None, form=TodoItemForm(), list_id=test_todo_list.Todo_List_ID)335 assert 'Redirecting' in response.data.decode("utf-8")336def test_budgetAction_get_withuser(test_client: FlaskClient, db_data_setup):337 student, test_todo_list, test_todo_item_1, test_todo_item_2, test_todo_item_3, test_budgetSummary, test_ledger = db_data_setup338 response = test_client.get(339 f"budgetSummary/{test_budgetSummary.Budgeter_Id}/item?users=sniffy13145")340 assert response.status_code == 200341 assert 'Add_to_your_Savings' in response.data.decode("utf-8")342 assert 'Action' in response.data.decode("utf-8")343@pytest.fixture()344def prepare_test_register_post_register():345 user='ThebigOther1314'346 name='slavoj'347 last_name='zizek'348 input_form=dict(username=user, 349 first_name=name,350 last_name=last_name,351 Submit='Sign Up')352 yield input_form, name353 to_delete=db.session.query(Users).filter_by(Username=user).first()354 if to_delete:355 db.session.delete(to_delete)356 db.session.commit()357def test_register_post_register(test_client: FlaskClient, prepare_test_register_post_register): 358 my_form, name = prepare_test_register_post_register359 360 response = test_client.post(url_for('register'), 361 data=my_form,362 content_type='application/x-www-form-urlencoded',363 follow_redirects=True)364 assert response.status_code == 200...

Full Screen

Full Screen

test_scrape.py

Source:test_scrape.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# ***********************************************************************3# ****************** CANADIAN ASTRONOMY DATA CENTRE *******************4# ************* CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES **************5#6# (c) 2018. (c) 2018.7# Government of Canada Gouvernement du Canada8# National Research Council Conseil national de recherches9# Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R610# All rights reserved Tous droits réservés11#12# NRC disclaims any warranties, Le CNRC dénie toute garantie13# expressed, implied, or énoncée, implicite ou légale,14# statutory, of any kind with de quelque nature que ce15# respect to the software, soit, concernant le logiciel,16# including without limitation y compris sans restriction17# any warranty of merchantability toute garantie de valeur18# or fitness for a particular marchande ou de pertinence19# purpose. NRC shall not be pour un usage particulier.20# liable in any event for any Le CNRC ne pourra en aucun cas21# damages, whether direct or être tenu responsable de tout22# indirect, special or general, dommage, direct ou indirect,23# consequential or incidental, particulier ou général,24# arising from the use of the accessoire ou fortuit, résultant25# software. Neither the name de l'utilisation du logiciel. Ni26# of the National Research le nom du Conseil National de27# Council of Canada nor the Recherches du Canada ni les noms28# names of its contributors may de ses participants ne peuvent29# be used to endorse or promote être utilisés pour approuver ou30# products derived from this promouvoir les produits dérivés31# software without specific prior de ce logiciel sans autorisation32# written permission. préalable et particulière33# par écrit.34#35# This file is part of the Ce fichier fait partie du projet36# OpenCADC project. OpenCADC.37#38# OpenCADC is free software: OpenCADC est un logiciel libre ;39# you can redistribute it and/or vous pouvez le redistribuer ou le40# modify it under the terms of modifier suivant les termes de41# the GNU Affero General Public la “GNU Affero General Public42# License as published by the License” telle que publiée43# Free Software Foundation, par la Free Software Foundation44# either version 3 of the : soit la version 3 de cette45# License, or (at your option) licence, soit (à votre gré)46# any later version. toute version ultérieure.47#48# OpenCADC is distributed in the OpenCADC est distribué49# hope that it will be useful, dans l’espoir qu’il vous50# but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE51# without even the implied GARANTIE : sans même la garantie52# warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ53# or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF54# PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence55# General Public License for Générale Publique GNU Affero56# more details. pour plus de détails.57#58# You should have received Vous devriez avoir reçu une59# a copy of the GNU Affero copie de la Licence Générale60# General Public License along Publique GNU Affero avec61# with OpenCADC. If not, see OpenCADC ; si ce n’est62# <http://www.gnu.org/licenses/>. pas le cas, consultez :63# <http://www.gnu.org/licenses/>.64#65# $Revision: 4 $66#67# ***********************************************************************68#69import os70import stat71import shutil72from mock import patch, Mock73from caom2pipe import manage_composable as mc74from neossat2caom2 import scrape75import test_main_app76TEST_DIRS = [77 '/tmp/astro',78 '/tmp/astro/2017',79 '/tmp/astro/2018',80 '/tmp/astro/2019',81 '/tmp/astro/2017/125',82 '/tmp/astro/2017/127',83 '/tmp/astro/2017/125/dark',84 '/tmp/astro/2017/125/dark/fine_point',85 '/tmp/astro/2017/125/m31',86 '/tmp/astro/2017/125/m31/reacquire',87]88TEST_END_TIME = 1570485900089MOCK_DIR = '/users/OpenData_DonneesOuvertes/pub/NEOSSAT/ASTRO/M32'90EXISTING_MOCK_DIR = '/users/OpenData_DonneesOuvertes/pub/NEOSSAT/ASTRO/M33'91@patch('neossat2caom2.scrape.FTPHost')92def test_append_todo(ftp_mock):93 _make_test_dirs()94 ftp_mock.return_value.__enter__.return_value.listdir.side_effect = (95 _list_dirs96 )97 ftp_mock.return_value.__enter__.return_value.stat.side_effect = (98 _entry_stats99 )100 test_start = TEST_END_TIME - 1000101 test_result = scrape._append_todo(102 test_start, '/usr/src/app', 'localhost', '/tmp/astro', {}, {}103 )104 assert test_result is not None, 'expected result'105 assert len(test_result) == 14, 'wrong length of all the entries'106 test_todo_list, test_max = scrape._remove_dir_names(107 test_result, test_start108 )109 assert test_todo_list is not None, 'expect a todo list'110 assert test_max is not None, 'expect a max time'111 assert test_max == TEST_END_TIME, 'wrong max time'112 assert len(test_todo_list) == 5, 'wrong length of file entries'113 assert (114 '/tmp/astro/2017/125/dark/fine_point/a.fits' in test_todo_list115 ), 'missing leafiest entry'116 assert (117 '/tmp/astro/2017/127/e.fits' in test_todo_list118 ), 'missing less leafy entry'119@patch('neossat2caom2.scrape.FTPHost')120def test_list_for_validate(ftp_mock):121 # put some test appending files in place - these files indicate122 # a 'No Exceptions' ending to list_for_validate occurred last123 # time124 cache_fqn = os.path.join(test_main_app.TEST_DATA_DIR, scrape.NEOSSAT_CACHE)125 if os.path.exists(cache_fqn):126 os.unlink(cache_fqn)127 source_list_fqn = os.path.join(128 test_main_app.TEST_DATA_DIR, scrape.NEOSSAT_SOURCE_LIST129 )130 source_fqn = os.path.join(131 test_main_app.TEST_DATA_DIR, 'test_source_listing.yml'132 )133 shutil.copy(source_fqn, source_list_fqn)134 _execute_and_check_list_for_validate(ftp_mock, source_list_fqn, 8, 2)135@patch('neossat2caom2.scrape.FTPHost')136def test_list_for_validate_exceptional_ending(ftp_mock):137 # put some test appending files in place - these files indicate138 # an FTPOSError ending to list_for_validate occurred last139 # time140 source_list_fqn = os.path.join(141 test_main_app.TEST_DATA_DIR, scrape.NEOSSAT_SOURCE_LIST142 )143 if os.path.exists(source_list_fqn):144 os.unlink(source_list_fqn)145 cache_fqn = os.path.join(test_main_app.TEST_DATA_DIR, scrape.NEOSSAT_CACHE)146 source_fqn = os.path.join(147 test_main_app.TEST_DATA_DIR, 'test_cache_listing.csv'148 )149 shutil.copy(source_fqn, cache_fqn)150 _execute_and_check_list_for_validate(ftp_mock, source_list_fqn, 17, 14)151class StatMock(object):152 def __init__(self, mtime, mode):153 self.st_mtime = mtime154 self.st_mode = mode155def _execute_and_check_list_for_validate(156 ftp_mock, source_list_fqn, result_count, cache_count157):158 source_dir_fqn = os.path.join(159 test_main_app.TEST_DATA_DIR, scrape.NEOSSAT_DIR_LIST160 )161 source_fqn = os.path.join(162 test_main_app.TEST_DATA_DIR, 'test_source_dir_listing.csv'163 )164 shutil.copy(source_fqn, source_dir_fqn)165 ftp_mock.return_value.__enter__.return_value.listdir.side_effect = (166 _list_dirs167 )168 ftp_mock.return_value.__enter__.return_value.stat.side_effect = (169 _entry_stats170 )171 getcwd_orig = os.getcwd172 os.getcwd = Mock(return_value=test_main_app.TEST_DATA_DIR)173 try:174 test_config = mc.Config()175 test_config.get_executors()176 scrape.list_for_validate(test_config)177 result = mc.read_as_yaml(source_list_fqn)178 assert result is not None, 'expect a file record'179 assert len(result) == result_count, 'wrong number of entries'180 assert (181 f'{MOCK_DIR}/NEOS_SCI_2017213215701_cord.fits' in result182 ), 'wrong content'183 cache_result = scrape._read_cache(test_config.working_directory)184 assert cache_result is not None, 'expected return value'185 assert (186 len(cache_result) == cache_count187 ), 'wrong number of cached entries'188 assert (189 f'{MOCK_DIR}/NEOS_SCI_2017213215701.fits' in cache_result190 ), 'wrong content'191 finally:192 os.getcwd = getcwd_orig193def _entry_stats(fqn):194 dir_mode = stat.S_IFDIR195 file_mode = stat.S_IFREG196 if fqn in TEST_DIRS or fqn == MOCK_DIR or fqn == EXISTING_MOCK_DIR:197 result = StatMock(mtime=TEST_END_TIME, mode=dir_mode)198 else:199 result = StatMock(mtime=TEST_END_TIME, mode=file_mode)200 return result201def _list_dirs(dir_name):202 if dir_name == '/tmp/astro':203 return ['2017', '2018', '2019']204 elif dir_name == '/tmp/astro/2017':205 return ['125', '127']206 elif dir_name == '/tmp/astro/2017/125':207 return ['dark', 'm31']208 elif dir_name == '/tmp/astro/2017/125/dark':209 return ['fine_point']210 elif dir_name == '/tmp/astro/2017/125/m31':211 return ['reacquire']212 elif dir_name == '/tmp/astro/2017/125/dark/fine_point':213 return ['a.fits', 'b.fits']214 elif dir_name == '/tmp/astro/2017/125/m31/reacquire':215 return ['c.fits', 'd.fits']216 elif dir_name == '/tmp/astro/2017/127':217 return ['e.fits']218 elif dir_name == '/users/OpenData_DonneesOuvertes/pub/NEOSSAT/ASTRO':219 return [220 'NEOS_SCI_2019213215700_cord.fits',221 'NEOS_SCI_2019213215700.fits',222 'NEOS_SCI_2019213215700_clean.fits',223 'M32', # new content224 'M33',225 ] # already in list226 elif dir_name == MOCK_DIR:227 return [228 'NEOS_SCI_2017213215701_cord.fits',229 'NEOS_SCI_2017213215701.fits',230 ]231 else:232 return []233def _make_test_dirs():234 if not os.path.exists('/tmp/astro'):235 for dir_name in TEST_DIRS:236 os.mkdir(dir_name)237 with open('/tmp/astro/2017/125/dark/fine_point/a.fits', 'w') as f:238 f.write('abc')239 with open('/tmp/astro/2017/125/dark/fine_point/b.fits', 'w') as f:240 f.write('abc')241 with open('/tmp/astro/2017/125/m31/reacquire/c.fits', 'w') as f:242 f.write('abc')243 with open('/tmp/astro/2017/125/m31/reacquire/d.fits', 'w') as f:244 f.write('abc')245 with open('/tmp/astro/2017/127/e.fits', 'w') as f:...

Full Screen

Full Screen

test_todo_list.py

Source:test_todo_list.py Github

copy

Full Screen

1from tasks.list_tasks.todo_list import add_by_index2def test_todo_list(new_list):3 add_by_index(new_list, 3, "new")4 assert "new" in new_list...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful