Browse Source

Add tests for link editing

Trevor Elliott 4 years ago
parent
commit
9c56b4ff80
1 changed files with 26 additions and 0 deletions
  1. 26 0
      tests/model.py

+ 26 - 0
tests/model.py

@@ -133,3 +133,29 @@ class Testdb:
 
         with pytest.raises(e.NoSuchInvite):
             m.User.from_invite(r.User(name="u4", password="u4"), "a-non-existent-token")
+
+    def test_edit_link(self):
+        u = self.mk_user()
+
+        req = r.Link("http://foo.com", "foo", "", False, ["foo", "bar"])
+        l = m.Link.from_request(u, req)
+        assert l.name == req.name
+
+        assert l.tags == ["foo", "bar"]
+
+        # check the in-place update
+        req.name = "bar"
+        req.tags = ["bar", "baz"]
+        req.private = True
+        l.update_from_request(u, req)
+        assert l.name == req.name
+        assert l.tags == req.tags
+        assert l.private
+        assert l.created != req.created
+
+        # check that the link was persisted
+        l = m.Link.by_id(l.id)
+        assert l.name == req.name
+        assert l.tags == req.tags
+        assert l.private
+        assert l.created != req.created