Example #1
0
    def test_hide_note(self):
        NotesService.upsert_note(VALID_ID, "Hello, world!", utils.now())

        note = NotesService.get_note(VALID_ID)
        self.assertFalse(note.hidden)

        NotesService.hide_note(VALID_ID)
        note = NotesService.get_note(VALID_ID)
        self.assertTrue(note.hidden)
Example #2
0
    def test_update_note(self):
        with self.assertRaises(NoteNotFound):
            note = NotesService.get_note(VALID_ID)

        NotesService.upsert_note(VALID_ID, "Hello, world!", utils.now())
        NotesService.upsert_note(VALID_ID, "goodbye", utils.now())

        note = NotesService.get_note(VALID_ID)
        self.assertEqual(note.contents, "goodbye")
Example #3
0
    def test_hide_note(self):
        params_list = [
            {
                "page": 1,
                "pageSize": 10
            },
            {
                "page": 1
            },
            {
                "page": "foobar"
            },
            {
                "page": "foobar",
                "pageSize": "foo"
            },
        ]
        NotesService.upsert_note(VALID_ID, "hello", utils.now())

        for params in params_list:
            with self.subTest(**params):
                rv = self.client.post("/notes/" + VALID_ID + "/hide",
                                      data=params)

                self.assertEqual(rv.status_code, 302)
                self.assertTrue(NotesService.get_note(VALID_ID).hidden)
Example #4
0
def get_note(note_id):
    note = NotesService.get_note(note_id)
    NotesService.mark_as_read(note)

    is_link = is_note_link(note)
    template = "view-link.html" if is_link else "view.html"

    return render_template(template, contents=note.contents)
Example #5
0
    def test_create_empty_note(self):
        rv = self.client.put(
            "/notes/" + VALID_ID + "?timestamp=1",
            data="",
            headers={"Content-type": "text/plain"},
        )
        self.assertEqual(rv.status_code, 200)

        note = NotesService.get_note(VALID_ID)
        self.assertEqual(note.contents, "")
Example #6
0
    def test_update_note(self):
        rv = self.client.put(
            "/notes/" + VALID_ID + "?timestamp=1000",
            data="foo",
            headers={"Content-type": "text/plain"},
        )
        self.assertEqual(rv.status_code, 200)

        rv = self.client.put(
            "/notes/" + VALID_ID + "?timestamp=2000",
            data="bar",
            headers={"Content-type": "text/plain"},
        )
        self.assertEqual(rv.status_code, 200)

        note = NotesService.get_note(VALID_ID)
        self.assertEqual(note.contents, "bar")
        self.assertEqual(utils.timestamp_seconds(note.modified), 2)
Example #7
0
    def test_try_update_note_invalid_timestamp(self):
        rv = self.client.put(
            "/notes/" + VALID_ID + "?timestamp=2000",
            data="foo",
            headers={"Content-type": "text/plain"},
        )
        self.assertEqual(rv.status_code, 200)

        # Try sending again with invalid timestamp
        rv = self.client.put(
            "/notes/" + VALID_ID + "?timestamp=foobar",
            data="bar",
            headers={"Content-type": "text/plain"},
        )
        self.assertEqual(rv.status_code, 200)

        note = NotesService.get_note(VALID_ID)
        self.assertEqual(note.contents, "foo")
        self.assertEqual(utils.timestamp_seconds(note.modified), 2)
Example #8
0
 def test_create_note(self):
     NotesService.upsert_note(VALID_ID, "Hello, world!", utils.now())
     note = NotesService.get_note(VALID_ID)
     self.assertEqual(note.id, VALID_ID)