Example #1
0
    def test_only_update_notes_that_have_changed(self, mocker, test_notebook, test_tags, test_note_metadata, test_note):
        """
        Test update only changed notes.
        """
        mocker.patch('app.evernote_utils.get_note', return_value=test_note)
        mocker.spy(app.evernote_utils, 'get_note')

        # insert the requisite notebook
        load_notebook(test_notebook)
        db_notebook = Notebook.query.filter_by(guid=test_notebook.guid).first()

        # Load the test tags into the database
        load_tags(test_tags)

        # load test note into the database
        load_notes(test_note_metadata, db_notebook)
        app.evernote_utils.get_note.call_count == 1

        app.evernote_utils.get_note.reset_mock()

        # attempt note reload with no changes
        load_notes(test_note_metadata, db_notebook)
        app.evernote_utils.get_note.call_count == 1

        app.evernote_utils.get_note.reset_mock()

        # attempt note reload with a changed updated timestamp
        new_timestamp = time.time()*1000
        test_note_metadata[0].updated = new_timestamp
        test_note.updated = new_timestamp
        load_notes(test_note_metadata, db_notebook)

        app.evernote_utils.get_note.call_count == 1
Example #2
0
    def test_change_note_title(self, mocker, test_notebook, test_note_metadata, test_note):
        """
        Test change a note title.
        """
        mocker.patch('app.evernote_utils.get_note', return_value=test_note)

        # insert the requisite notebook
        load_notebook(test_notebook)
        db_notebook = Notebook.query.filter_by(guid=test_notebook.guid).first()

        # load test note into the database
        load_notes(test_note_metadata, db_notebook)

        # Change the note title and the updated timestamp
        new_title = "New Note Title"
        test_note.title = new_title
        new_timestamp = time.time()*1000
        test_note_metadata[0].updated = new_timestamp
        test_note.updated = new_timestamp

        # re-load test note into the database
        load_notes(test_note_metadata, db_notebook)

        db_note = Note.query.filter_by(guid=test_note.guid).first()

        assert db_note.title == new_title
Example #3
0
    def test_add_note_tags(self, mocker, test_notebook, test_tags, test_note_metadata, test_note):
        """
        Test add note with tags.
        """
        mocker.patch('app.evernote_utils.get_note', return_value=test_note)

        # insert the requisite notebook
        load_notebook(test_notebook)
        db_notebook = Notebook.query.filter_by(guid=test_notebook.guid).first()

        # load all of the test tags into the database
        load_tags(test_tags)
        assert Tag.query.count() == 3

        # load test note into the database
        load_notes(test_note_metadata, db_notebook)

        # test that tag guids are equal
        instance = Note.query.first()
        assert [tag.guid for tag in instance.tags].sort() == test_note_metadata[0].tagGuids.sort()

        # add a new tag to the note
        new_tag = '02015957-f861-4750-b6cf-74f0802b4be4'
        test_note_metadata[0].tagGuids.append(new_tag)
        test_note.tagGuids.append(new_tag)
        # adding tags does not seem to change the update date

        # load test note into the database
        load_notes(test_note_metadata, db_notebook)

        # test that the tag guids are still equal
        assert new_tag in [tag.guid for tag in instance.tags]
        assert [tag.guid for tag in instance.tags] == test_note_metadata[0].tagGuids
Example #4
0
    def test_change_notebook_name(self, test_notebook):
        """
        Test changing the notebook name
        """
        load_notebook(test_notebook)
        assert test_notebook.guid in [n.guid for n in Notebook.query.all()]

        guid = test_notebook.guid
        test_notebook.name = "New Name"
        load_notebook(test_notebook)
        instance = Notebook.query.filter_by(guid=guid).first()

        assert instance.name == test_notebook.name
Example #5
0
    def test_set_active_notebook(self, test_notebook, test_notebook2):
        """
        Test setting the active notebook.
        """
        # Insert the first notebook
        load_notebook(test_notebook)
        db_notebook = Notebook.query.filter_by(guid=test_notebook.guid).first()

        assert db_notebook.guid == test_notebook.guid
        assert db_notebook.active is True

        # Insert the second notebook
        load_notebook(test_notebook2)
        db_notebook2 = Notebook.query.filter_by(guid=test_notebook2.guid).first()

        assert db_notebook2.guid == test_notebook2.guid
        assert db_notebook2.active is True
        assert len(Notebook.query.filter_by(active=True).all()) == 1, "Should only be one active notebook"
Example #6
0
    def test_update_resources(self, mocker, test_notebook, test_note_metadata, test_note):
        """
        Test inserting a note and its resources
        """
        mocker.patch('app.evernote_utils.get_note', return_value=test_note)

        # insert the requisite notebook
        load_notebook(test_notebook)
        db_notebook = Notebook.query.filter_by(guid=test_notebook.guid).first()

        # load the notes into the database
        load_notes(test_note_metadata, db_notebook)

        # Test for one note in the database
        assert Note.query.count() == 1

        # Make sure it has one resource associated with it.
        assert Note.query.first().resources.count() == 1
Example #7
0
    def test_update_resources3(self, mocker, test_notebook, test_note_metadata, test_note):
        """
        Test that resources are removed from the database if a note is deleted
        """
        mocker.patch('app.evernote_utils.get_note', return_value=test_note)

        # insert the requisite notebook
        load_notebook(test_notebook)
        db_notebook = Notebook.query.filter_by(guid=test_notebook.guid).first()

        # load the notes and resources into the database
        load_notes(test_note_metadata, db_notebook)

        assert Note.query.first().resources.count() == 1, "Note with one resource should be present in the database"

        # Simulate that we are removing all notes
        delete_notes([], db_notebook)

        assert Resource.query.count() == 0, "Deleting all notes should also remove all resources."
Example #8
0
    def test_load_notes(self, mocker, test_notebook, test_note_metadata, test_note):
        """
        Test load notes into the database.
        """
        mocker.patch('app.evernote_utils.get_note', return_value=test_note)

        # insert the requisite notebook
        load_notebook(test_notebook)

        # load test note into the database
        db_notebook = Notebook.query.filter_by(guid=test_notebook.guid).first()
        load_notes(test_note_metadata, db_notebook)

        # Test that the notes were inserted into the database
        db_notes = Note.query.all()

        assert [n.guid for n in db_notes] == [n.guid for n in test_note_metadata]

        # Test that each note has its notebook_id set
        for n in db_notes:
            assert db_notebook.id == n.notebook_id
Example #9
0
    def test_update_resources2(self, mocker, test_notebook, test_note_metadata, test_note):
        """
        Test removing resources from an existing note
        """
        mocker.patch('app.evernote_utils.get_note', return_value=test_note)

        # insert the requisite notebook
        load_notebook(test_notebook)
        db_notebook = Notebook.query.filter_by(guid=test_notebook.guid).first()

        # load the notes and resources into the database
        load_notes(test_note_metadata, db_notebook)

        assert Note.query.first().resources.count() == 1

        # Simulate removing all resources from the note
        test_note.resources = None
        new_timestamp = time.time()*1000
        test_note_metadata[0].updated = new_timestamp
        test_note.updated = new_timestamp
        delete_resources(test_note_metadata)

        assert Note.query.first().resources.count() == 0
Example #10
0
    def test_delete_notes(self, mocker, test_notebook, test_note_metadata, test_note):
        """
        Test deleting notes.
        """
        mocker.patch('app.evernote_utils.get_note', return_value=test_note)

        # insert the requisite notebook
        load_notebook(test_notebook)
        db_notebook = Notebook.query.filter_by(guid=test_notebook.guid).first()

        # load the notes into the database
        load_notes(test_note_metadata, db_notebook)

        # test that the notes loaded successfully
        db_notes = db_notebook.notes
        assert len(db_notes) == len(test_note_metadata)

        # simulate deleting all notes from the notebook
        test_note_metadata = []
        delete_notes(test_note_metadata, db_notebook)

        # test that the notes have been removed
        assert len(Note.query.all()) == 0
Example #11
0
 def test_load_notebook(self, test_notebook):
     """
     Test inserting notebook into the database
     """
     load_notebook(test_notebook)
     assert test_notebook.guid in [n.guid for n in Notebook.query.all()]