def test_items(self):
        first_item = ToDoItem("1234", "To Do", "First Test Item", '2021-01-06T21:14:06.518Z')
        second_item = ToDoItem("4321", "Doing", "In progress Item", '2021-01-06T21:14:06.518Z')

        item_list = [first_item, second_item]

        view_model_under_test = ViewModel(item_list)

        assert view_model_under_test.items == item_list
    def test_done(self):
        first_item = ToDoItem("1234", "To Do", "First Test Item", '2021-01-06T21:14:06.518Z')
        second_item = ToDoItem("4321", "Doing", "In progress Item", '2021-01-06T21:14:06.518Z')
        third_item = ToDoItem("1111", "Done", "I hope this test passes", '2021-01-06T21:14:06.518Z')

        item_list = [first_item, second_item, third_item]

        view_model_under_test = ViewModel(item_list)

        assert view_model_under_test.done == [third_item]
    def test_older_done_items(self):
        today = datetime.now()
        yesterday = today + timedelta(days=-1)

        first_item = ToDoItem("1234", "Done", "First Test Item", yesterday)
        second_item = ToDoItem("4321", "Done", "In progress Item", today)
        third_item = ToDoItem("1111", "Done", "I hope this test passes", yesterday)

        item_list = [first_item, second_item, third_item]

        view_model_under_test = ViewModel(item_list)
        assert view_model_under_test.older_done_items == [first_item, third_item]
    def test_items(self):
        first_item = ToDoItem("1234", "First Test Item", "To Do",
                              '2021-01-06 21:14:06.518')
        second_item = ToDoItem("4321", "In progress Item", "Doing",
                               '2021-01-06 21:14:06.518')

        item_list = [first_item, second_item]
        view_model_under_test = ViewModel(item_list, self.test_user)

        diff = set(item_list) ^ set(view_model_under_test.items)

        assert len(item_list) == len(view_model_under_test.items)

        assert not diff
    def test_show_all_done_items_less_than_five(self):
        today = datetime.now()
        yesterday = datetime.now() + timedelta(days=-1)

        one = ToDoItem("1", "Done", "One", today)
        two = ToDoItem("2", "Done", "One", today)
        three = ToDoItem("3", "Done", "One", yesterday)
        four = ToDoItem("4", "Done", "One", yesterday)

        item_list = [one, two, three, four]

        view_model_under_test = ViewModel(item_list)

        assert view_model_under_test.show_all_done_items == [one, two, three, four]
    def test_recent_done_items(self):
        today = datetime.now()
        tomorrow = today + timedelta(days=1)
        yesterday = today + timedelta(days=-1)

        first_item = ToDoItem("1234", "First Test Item", "Done",
                              str(yesterday))
        second_item = ToDoItem("4321", "In progress Item", "Done", str(today))
        third_item = ToDoItem("1111", "I hope this test passes", "Done",
                              str(tomorrow))

        item_list = [first_item, second_item, third_item]

        view_model_under_test = ViewModel(item_list, self.test_user)
        assert view_model_under_test.recent_done_items == [second_item]
Exemple #7
0
    def test_get_from_json(self):
        test_object: dict = ToDoItem.new_item_as_dict(
            "Testing static constructor method")

        collection = MongoClient().db.collection
        collection.insert_one(test_object)
        returned_object = collection.find_one(
            {'title': 'Testing static constructor method'})

        object_to_test: ToDoItem = ToDoItem.from_json(returned_object)

        assert isinstance(object_to_test.item_id, str)
        assert "Testing static constructor method" == object_to_test.title
        assert "To Do" == object_to_test.status
        assert isinstance(object_to_test.last_modified, datetime)
Exemple #8
0
def test_index_page():
    file_path = find_dotenv('.env.test', usecwd=True)
    load_dotenv(file_path, override=True)

    database_config = DatabaseConfig()
    auth_config = AuthConfig()
    flask_config = FlaskConfig()

    mocked_client = mongomock.MongoClient()
    mock_db = mocked_client.get_database(database_config.db_name)
    client = AtlasClient(database_config, mocked_client)
    login_manager = LoginManager()
    login_manager.anonymous_user = TestUser

    #Create the new app.
    test_app = create_app(client, auth_config, login_manager)
    test_app.config.from_object(flask_config)
    test_app.config['LOGIN_DISABLED'] = True

    mock_item_response = ToDoItem.new_item_as_dict(
        "Hello form the integration tests")

    mock_db.get_collection("test_collection_name").insert_one(
        mock_item_response)

    response = test_app.test_client().get("/")
    assert 200 == response.status_code
    assert "Hello form the integration tests" in response.data.decode()
Exemple #9
0
    def test_new_item_as_dict_returns_correct_object(self):
        dict_to_test = ToDoItem.new_item_as_dict(
            "Testing static builder method")
        date_time_obj = datetime.strptime(dict_to_test["last_modified"],
                                          '%Y-%m-%d %H:%M:%S.%f')

        assert "Testing static builder method" == dict_to_test["title"]
        assert "To Do" == dict_to_test["status"]
        assert isinstance(date_time_obj, datetime)
 def mark_complete(self, item_id: str) -> ToDoItem:
     query: dict = {"_id": ObjectId(item_id)}
     new_status: dict = {
         "$set": {
             "status": "Done",
             "last_modified": str(datetime.now())
         }
     }
     return ToDoItem.from_json(
         self._collection.find_one_and_update(
             query, new_status, return_document=ReturnDocument.AFTER))
    def test_show_all_done_items_more_than_five(self):
        today = datetime.now()
        yesterday = datetime.now() + timedelta(days=-1)

        one = ToDoItem("1", "One", "Done", str(today))
        two = ToDoItem("2", "One", "Done", str(today))
        three = ToDoItem("3", "One", "Done", str(yesterday))
        four = ToDoItem("4", "One", "Done", str(yesterday))
        five = ToDoItem("5", "One", "Done", str(yesterday))
        six = ToDoItem("6", "One", "Done", str(yesterday))

        item_list = [one, two, three, four, five, six]

        view_model_under_test = ViewModel(item_list, self.test_user)

        assert view_model_under_test.show_all_done_items == [one, two]
Exemple #12
0
    def get_items(self) -> list:
        """
        Fetches all saved items from the trello api.

        Returns:
            list: The list of items.
        """

        cards_request = requests.get(self.base_request_url + 'cards' +
                                     self.request_credentials)

        cards_json = json.loads(cards_request.content)
        list_id_dict = self.get_lists()

        items = []
        for node in cards_json:
            date_in_datetime = datetime.strptime(node['dateLastActivity'],
                                                 '%Y-%m-%dT%H:%M:%S.%fZ')
            items.append(
                ToDoItem(node['id'], list_id_dict[node['idList']],
                         node['name'], date_in_datetime))

        return items
Exemple #13
0
    def test_to_do_item_str(self):
        item = ToDoItem('123', 'To Do', 'Title', '2021-01-06T21:14:06.518Z')

        assert str(item) == 'Title-To Do-2021-01-06T21:14:06.518Z'
Exemple #14
0
    def test_to_do_item_str(self):
        item = ToDoItem('123', 'Title', 'To Do', '2021-05-10 10:30:42.000123')

        assert str(item) == 'Title-To Do-2021-05-10 10:30:42.000123'
 def delete_item_by_id(self, item_id: str) -> ToDoItem:
     return ToDoItem.from_json(
         self._collection.find_one_and_delete({"_id": ObjectId(item_id)}))
 def get_items(self) -> List[ToDoItem]:
     return list(
         map(lambda doc: ToDoItem.from_json(doc), self._collection.find()))  # pylint:disable=unnecessary-lambda
 def add_item(self, title: str) -> str:
     return str(
         self._collection.insert_one(
             ToDoItem.new_item_as_dict(title)).inserted_id)
 def get_item(self, item_id: str) -> ToDoItem:
     return ToDoItem.from_json(
         self._collection.find_one({"_id": ObjectId(item_id)}))