def done_items_view_model(): return ViewModel( [ Item('to-do-id', 'to-do-title', Status.DONE.value, '5 days done', datetime.now() - timedelta(days=5)), Item('to-do-id', 'to-do-title', Status.DONE.value, '3 hours done', datetime.now() - timedelta(hours=3)), Item('to-do-id', 'to-do-title', Status.DONE.value, 'Just done', datetime.now()), Item('to-do-id', 'to-do-title', Status.DONE.value, '20 days done', datetime.now() - timedelta(days=20)), Item('to-do-id', 'to-do-title', Status.DONE.value, '20 hours done', datetime.now() - timedelta(hours=20)) ], False )
def test_should_show_all_completed_items_if_there_are_three_or_fewer(): items = [ Item(1, 'Task 1', date.today(), 'Done'), Item(2, 'Task 2', date.today(), 'Done'), Item(3, 'Task 3', date.today(), 'Doing'), Item(4, 'Task 4', date.today(), 'Done'), ] view_model = ViewModel(items) assert view_model.show_all_done_items is True
def done_items_view_model(): return ViewModel([ ToDoItem(11, "Title 1", Status.DONE, datetime.now() - timedelta(days=3)), ToDoItem(12, "Title 2", Status.DONE, datetime.now() - timedelta(hours=2)), ToDoItem(13, "Title 3", Status.DONE, datetime.now()), ToDoItem(14, "Title 4", Status.DONE, datetime.now() - timedelta(days=30)), ToDoItem(15, "Title 5", Status.DONE, datetime.now() - timedelta(hours=23)) ])
def test_show_all_completed_items_is_true_for_5_items(self): items = [ Item('id', 'title', COMPLETED, datetime.now()), Item('id', 'title', COMPLETED, datetime.now()), Item('id', 'title', COMPLETED, datetime.now()), Item('id', 'title', COMPLETED, datetime.now()), Item('id', 'title', COMPLETED, datetime.now()), Item('id', 'title', NOT_STARTED, datetime.now()), Item('id', 'title', IN_PROGRESS, datetime.now()) ] view_model = ViewModel(items) assert view_model.show_all_completed_items
def test_recent_items_contain_only_items_last_modified_today(): items = [ Item(1, 'Done Yesterday', datetime(2020, 6, 15, 23, 59, 59), 'Done'), Item(2, 'Done Today', datetime(2020, 6, 16, 0, 0, 0), 'Done'), Item(3, 'Doing Today', datetime(2020, 6, 16, 9, 0, 0), 'Doing'), ] with freeze_time("2020-06-16 09:30:00"): view_model = ViewModel(items) assert view_model.recent_done_items == [ Item(2, 'Done Today', datetime(2020, 6, 16, 0, 0, 0), 'Done'), ]
def main(): vehicle_db = SQLVehicleDB() #vehicle_db = APIVehicleDB() # Replace the SQLVehicleDB with this to use the API - code will be happy vehicle_view_model = ViewModel(vehicle_db) vehicle_view = View(vehicle_view_model) vehicle_view.get_new_vehicles() vehicle_view.update_existing_vehicles() vehicle_view.display_all_data()
def test_show_all_done_items_returns_true_for_small_numbers_of_items(): # Arrange items = [ TodoItem(1, "Started Todo", "Not Started", ""), TodoItem(2, "Doing Todo", "In Progress", ""), TodoItem(3, "Done Todo", "Completed", ""), ] vader = ViewModel(items) # Act result = vader.show_all_done_items # Assert assert result == True
def test_done(): items = ( TodoItem(1, "Started Todo", "Not Started", ""), TodoItem(2, "Doing Todo", "In Progress", ""), TodoItem(3, "Done Todo", "Completed", ""), ) storm = ViewModel(items) done_items = storm.done assert len(done_items) == 1 done_item = done_items[0] assert done_item.status == "Completed" assert done_item.id == 3
def test_items_are_split_into_categories(): items = [ Item(1, 'Task 1', date.today(), 'Other Status'), Item(2, 'Task 2', date.today(), 'To Do'), Item(3, 'Task 3', date.today(), 'Done'), Item(4, 'Task 4', date.today(), 'To Do'), Item(5, 'Task 5', date.today(), 'Doing') ] view_model = ViewModel(items) assert view_model.to_do_items == [ Item(2, 'Task 2', date.today(), 'To Do'), Item(4, 'Task 4', date.today(), 'To Do') ] assert view_model.doing_items == [Item(5, 'Task 5', date.today(), 'Doing')] assert view_model.done_items == [Item(3, 'Task 3', date.today(), 'Done')]
def test_filters_by_status( ): # first test to see if view model item matches each status created_todo = TodoItem(1, "Test in progress Todo", "To Do", datetime.now()) pending_todo = TodoItem(2, "Test Pending Todo", "Pending", datetime.now()) done_todo = TodoItem(3, "Test Done Todo", "Done", datetime.now()) todos = [created_todo, pending_todo, done_todo] # added as part of module 10 project reader = "ReadOnly" view_model = ViewModel(todos, reader) assert view_model.to_do_items == [created_todo] assert view_model.doing_items == [pending_todo] assert view_model.done_items == [done_todo]
def test_show_all_done_items_today(): today = arrow.utcnow().floor('day').format('YYYY-MM-DD') items = (TodoItem(1, "Started Todo", "Not Started", today), TodoItem(2, "Doing Todo", "In Progress", today), TodoItem(3, "Done Todo", "Completed", today), TodoItem(4, "Done Todo", "Completed", "2021-04-06")) egg = ViewModel(items) # Act result = egg.show_all_done_items_today # Assert assert len(result) == 1 done_item = result[0] assert done_item.status == "Completed" assert done_item.id == 3
def test_doing(): # Arrange items = [ TodoItem(1, "Started Todo", "Not Started", ""), TodoItem(2, "Doing Todo", "In Progress", ""), TodoItem(3, "Done Todo", "Completed", ""), ] vader = ViewModel(items) # Act doing_items = vader.doing # Assert assert len(doing_items) == 1 doing_item = doing_items[0] assert doing_item.status == "In Progress" assert doing_item.id == 2
def test_to_do(): # Passing through blank value for the Date Input as not required for this test items = [ TodoItem(1, "Started Todo", "Not Started", ""), TodoItem(2, "Doing Todo", "In Progress", ""), TodoItem(3, "Done Todo", "Completed", ""), ] frank = ViewModel(items) # Act # [TodoItem(1, "Started Todo", "Not Started")] todo_items = frank.to_do # Assert assert len(todo_items) == 1 todo_item = todo_items[0] assert todo_item.status == "Not Started"
def getAll(): #myclient = pymongo.MongoClient('mongodb+srv://%s:%[email protected]/ToDo?retryWrites=true&w=majority' % (MONGO_LOGIN, MONGO_PASS)) #mydb = myclient["ToDo"] #mycollection = mydb["All Items"] myclient = pymongo.MongoClient( 'mongodb://%s:%[email protected]:10255/DefaultDatabase?ssl=true&retrywrites=false&replicaSet=globaldb&maxIdleTimeMS=120000&appName=@module11-cosmos-serverless@' % (MONGO_LOGIN, MONGO_PASS)) mydb = myclient["ToDo"] mycollection = mydb["All Items"] todo_resp = mycollection.find( ) # find method returns a cursor instance for iteration todo_list = [TodoItem.from_mongo_card(card) for card in todo_resp] ## returns list of dict # user authorization user_authorizaion = User(current_user.get_id()) reader = user_authorizaion.get_role() == Role.Reader return render_template('all_items.html', todos=ViewModel(todo_list, reader))
def main(): travel_db = SQLTravelDB() travel_view_model = ViewModel(travel_db) travel_view = View(travel_view_model) travel_view.show_menu()
def __setattr__(self, name, value): super().__setattr__(name, value) ViewModel.__setitem__(self, name, value)
def __init__(self, id): ViewModel().__init__() self.id = id
def setUp(self): self.viewmodel = ViewModel()
class TestColorSpaceConverterViewModel(unittest.TestCase): def setUp(self): self.viewmodel = ViewModel() def tearDown(self): self.viewmodel.logger.clear() def test_button_enabled_by_default(self): self.assertEqual('enabled', self.viewmodel.get_button_convert_state()) def test_when_entered_color_button_enabled(self): self.viewmodel.set_color_in(['0', '0', '0']) self.assertEqual('enabled', self.viewmodel.get_button_convert_state()) def test_when_erased_color_button_disabled(self): self.viewmodel.set_color_in(['', '', '']) self.assertEqual('disabled', self.viewmodel.get_button_convert_state()) def test_when_change_color_in_it_changes(self): self.viewmodel.set_color_in(['10', '100', '80']) self.assertEqual(['10', '100', '80'], self.viewmodel.get_color_in()) def test_when_change_color_space_in_it_changes(self): self.viewmodel.set_color_space_in("HSV") self.assertEqual("HSV", self.viewmodel.get_color_space_in()) def test_when_change_color_space_out_it_changes(self): self.viewmodel.set_color_space_out("HSV") self.assertEqual("HSV", self.viewmodel.get_color_space_out()) def test_convert_button_disabled_incorrect_color_space_in(self): self.viewmodel.set_color_space_in("QQQ") self.assertEqual("disabled", self.viewmodel.get_button_convert_state()) def test_convert_button_disabled_incorrect_color_space_out(self): self.viewmodel.set_color_space_out("QQQ") self.assertEqual("disabled", self.viewmodel.get_button_convert_state()) def test_complains_on_incorrect_color_space_in(self): self.viewmodel.set_color_space_in("QQQ") self.assertEqual("Unsupported color space.", self.viewmodel.get_error_message()) def test_convert_button_disabled_incorrect_color_in(self): self.viewmodel.set_color_in(['', '', '']) self.assertEqual("disabled", self.viewmodel.get_button_convert_state()) def test_complains_on_incorrect_color_in(self): self.viewmodel.set_color_in(['', '', '']) self.assertEqual("Incorrect values.", self.viewmodel.get_error_message()) def test_error_message_is_empty_after_correct_color_in(self): self.viewmodel.set_color_in(['0', '-10', '10']) self.assertEqual("Incorrect values.", self.viewmodel.get_error_message()) self.viewmodel.set_color_in(['0', '10', '10']) self.assertEqual("", self.viewmodel.get_error_message()) def test_convert_button_disabled_incorrect_color_in_text(self): self.viewmodel.set_color_in(['a', 'b', '10']) self.assertEqual("disabled", self.viewmodel.get_button_convert_state()) def test_convert_button_disabled_incorrect_color_in_negative(self): self.viewmodel.set_color_in(['-1', '-1', '300']) self.assertEqual("disabled", self.viewmodel.get_button_convert_state()) def test_complains_on_incorrect_color_in_not_in_range(self): self.viewmodel.set_color_in(['1000', '0', '0']) self.assertEqual("Input values should be in range 0-255.", self.viewmodel.get_error_message()) def test_when_convert_def_rgb_to_rgb_display_it(self): self.viewmodel.set_color_space_in("RGB") self.viewmodel.set_color_space_out("RGB") self.viewmodel.set_color_in(['0', '0', '0']) self.viewmodel.convert() self.assertEqual(['0', '0', '0'], self.viewmodel.get_color_out()) def test_when_convert_rgb_to_hsv_display_it(self): self.viewmodel.set_color_space_in("RGB") self.viewmodel.set_color_space_out("HSV") self.viewmodel.set_color_in(['0', '100', '0']) self.viewmodel.convert() self.assertEqual(['85', '255', '100'], self.viewmodel.get_color_out()) def test_when_convert_lab_to_rgb_display_it(self): self.viewmodel.set_color_space_in("LAB") self.viewmodel.set_color_space_out("RGB") self.viewmodel.set_color_in(['88', '148', '101']) self.viewmodel.convert() self.assertEqual(['90', '72', '124'], self.viewmodel.get_color_out())
def setUp(self): real_logger = Logger("ViewModel_with_Logger_Tests-lab3.log") self.viewmodel = ViewModel(real_logger)
def setUp(self): mockup_logger = MockUpLogger() self.viewmodel = ViewModel(mockup_logger)
def index(): items = trello.get_items() return render_template('index.html', model=ViewModel(items))
from view_model import ViewModel import matplotlib.pyplot as plt import numpy as np # 1 - Initialising things =================================================== ############# # IMPORTANT # ############# token = "" ############# # IMPORTANT # ############# viewRepository = ViewModel(token) # 2 - Getting data numberOfRepositories = viewRepository.getTotalNumberOfRepositories() print("Total Number of Repositories: ") print(numberOfRepositories) numberOfFeatures = viewRepository.getTotalNumberOfFeatures() print("Total Number of Features: ") print(numberOfFeatures) numberOfScenarios = viewRepository.getTotalNumberOfScenarios() print("Total Number of Scenarios: ") print(numberOfScenarios) numberOfSteps = viewRepository.getTotalNumberOfSteps()
def dictify(id_list: Iterable[int]) -> Iterable[ViewModel]: for x in id_list: yield ViewModel({ViewModel.IDKEY: x})
def index(): user = User(current_user.get_id()) reader = (not login_disabled) and user.get_role() == Role.Reader items = get_all_items(collection) return render_template('index.html', view_model=ViewModel(items, reader))
def test_show_all_done_items_false_if_more_than_5_items(): item = TodoItem(3, constants.DONE_LIST_ID, "Completed Item!", datetime.now().isoformat()) model = ViewModel([item] * 6) assert model.show_all_done_items == False
def index(): items = db.get_items() item_view_model = ViewModel(items) return render_template('index.html', view_model=item_view_model)
class TestColorSpaceConverterViewModelMockUpLogger(unittest.TestCase): def setUp(self): mockup_logger = MockUpLogger() self.viewmodel = ViewModel(mockup_logger) def tearDown(self): self.viewmodel.logger.clear() def test_log_is_empty_in_the_beginning(self): log = self.viewmodel.logger.get_log() self.assertEqual(log, "") def test_log_contains_correct_message_for_setting_color_space_in(self): self.viewmodel.set_color_space_in("LAB") log = self.viewmodel.logger.get_log() self.assertEqual(log, 'Input color space: LAB') def test_log_contains_correct_message_for_setting_color_space_out(self): self.viewmodel.set_color_space_out("LAB") log = self.viewmodel.logger.get_log() self.assertEqual(log, 'Output color space: LAB') def test_log_contains_correct_message_for_setting_color(self): self.viewmodel.set_color_in(['88', '148', '101']) log = self.viewmodel.logger.get_log() self.assertEqual(log, "Input color: ['88', '148', '101']") def test_log_contains_correct_message_for_conversion(self): self.viewmodel.set_color_space_in("LAB") self.viewmodel.set_color_space_out("RGB") self.viewmodel.set_color_in(['88', '148', '101']) self.viewmodel.convert() log = self.viewmodel.logger.get_log() expected_messages = [ "Input color space: LAB", "Output color space: RGB", "Input color: ['88', '148', '101']", "Input color: LAB [88, 148, 101] --> Output color: RGB [90, 72, 124]" ] self.assertEqual(log, "\n".join(expected_messages))
async def visit_aggregate(self, query): await self.visit_child(query.child) self._aggregate() self.root = ViewModel({None: self.iter}) self.iter = iter([self.root]) self.parent_iter = None
from view_model import ViewModel import matplotlib.pyplot as plt # 1 - Initialising things =================================================== ############# # IMPORTANT # ############# token = "" ############# # IMPORTANT # ############# viewRepository = ViewModel(token) # 2 - Getting data viewRepository.getReposAsObject()