Exemple #1
0
 def tearDown(self):
     IndexSet({
         "title": {
             "$in": ["Name Change Test", "Name Changed"]
         }
     }).delete()
     NoteSet({"ref": {"$regex": "^Name Change Test"}}).delete()
     NoteSet({"ref": {"$regex": "^Name Changed"}}).delete()
     HistorySet({
         "rev_type": "add index",
         "title": "Name Change Test"
     }).delete()
     HistorySet({
         "version": "The Name Change Test Edition",
         "rev_type": "add text"
     }).delete()
     HistorySet({
         "new.refs": {
             "$regex": "Name Change Test"
         },
         "rev_type": "add link"
     }).delete()
     HistorySet({
         "new.ref": {
             "$regex": "Name Change Test"
         },
         "rev_type": "add note"
     }).delete()
     HistorySet({"rev_type": "add index", "title": "Name Changed"}).delete()
     HistorySet({
         "ref": {
             "$regex": "Name Changed"
         },
         "rev_type": "add text"
     }).delete()
     HistorySet({
         "new.ref": {
             "$regex": "Name Changed"
         },
         "rev_type": "add note"
     }).delete()
     HistorySet({
         "new.refs": {
             "$regex": "Name Changed"
         },
         "rev_type": "add link"
     }).delete()
     HistorySet({
         "old.ref": {
             "$regex": "Name Changed"
         },
         "rev_type": "delete note"
     }).delete()
     HistorySet({
         "old.refs": {
             "$regex": "Name Changed"
         },
         "rev_type": "delete link"
     }).delete()
Exemple #2
0
    def test_change_index_name(self):
        #Set up an index and text to test
        index = {
            "title": "Name Change Test",
            "titleVariants": ["The Book of Name Change Test"],
            "sectionNames": ["Chapter", "Paragraph"],
            "categories": ["Musar"],
        }
        response = c.post("/api/index/Name_Change_Test",
                          {'json': json.dumps(index)})
        self.assertEqual(200, response.status_code)
        self.assertEqual(
            1,
            HistorySet({
                "rev_type": "add index",
                "title": "Name Change Test"
            }).count())
        self.in_cache("Name Change Test")

        # Post some text, including one citation
        text = {
            "text": "Blah blah blah Genesis 5:12 blah",
            "versionTitle": "The Name Change Test Edition",
            "versionSource": "www.sefaria.org",
            "language": "en",
        }
        response = c.post("/api/texts/Name_Change_Test.1.1",
                          {'json': json.dumps(text)})
        self.assertEqual(200, response.status_code)
        self.assertEqual(
            1,
            LinkSet({
                "refs": {
                    "$regex": "^Name Change Test"
                }
            }).count())
        self.assertEqual(
            1,
            HistorySet({
                "version": "The Name Change Test Edition",
                "rev_type": "add text"
            }).count())
        self.assertEqual(
            1,
            HistorySet({
                "new.refs": {
                    "$regex": "Name Change Test"
                },
                "rev_type": "add link"
            }).count())

        # Test posting notes and links
        note1 = {
            'title': u'test title 1',
            'text': u'test body 1',
            'type': u'note',
            'ref': u'Name Change Test 1.1',
            'public': False
        }
        note2 = {
            'title': u'test title 2',
            'text': u'test body 2',
            'type': u'note',
            'ref': u'Name Change Test 1.1',
            'public': True
        }
        link1 = {
            'refs': ['Name Change Test 1.1', 'Genesis 1:5'],
            'type': 'reference'
        }
        link2 = {
            'refs': ['Name Change Test 1.1', 'Rashi on Genesis 1:5'],
            'type': 'reference'
        }

        # Post notes and refs and record ids of records
        for o in [note1, note2, link1, link2]:
            url = "/api/notes/" if o['type'] == 'note' else "/api/links/"
            response = c.post(url, {'json': json.dumps(o)})
            self.assertEqual(200, response.status_code)
            data = json.loads(response.content)
            self.assertIn("_id", data)
            o["id"] = data["_id"]

        # test history
        self.assertEqual(1,
                         HistorySet({
                             "new.ref": {
                                 "$regex": "Name Change Test"
                             },
                             "rev_type": "add note"
                         }).count())  # only one is public
        self.assertEqual(
            3,
            HistorySet({
                "new.refs": {
                    "$regex": "Name Change Test"
                },
                "rev_type": "add link"
            }).count())

        # Change name of index record
        orig = json.loads(c.get("/api/index/Name_Change_Test").content)
        new = deepcopy(orig)
        new["oldTitle"] = orig["title"]
        new["title"] = "Name Changed"
        new["titleVariants"].remove("Name Change Test")
        response = c.post("/api/index/Name_Changed", {'json': json.dumps(new)})
        self.assertEqual(200, response.status_code)

        # Check for change on index record
        response = c.get("/api/index/Name_Changed")
        self.assertEqual(200, response.status_code)
        data = json.loads(response.content)
        self.assertTrue(u"Name Changed" == data["title"])
        self.assertIn(u"Name Changed", data["titleVariants"])
        self.assertTrue(u"Name Change Test" not in data["titleVariants"])

        # In History
        self.assertEqual(
            0,
            HistorySet({
                "rev_type": "add index",
                "title": "Name Change Test"
            }).count())
        self.assertEqual(
            0,
            HistorySet({
                "ref": {
                    "$regex": "Name Change Test"
                },
                "rev_type": "add text"
            }).count())
        self.assertEqual(
            0,
            HistorySet({
                "new.ref": {
                    "$regex": "Name Change Test"
                },
                "rev_type": "add note"
            }).count())
        self.assertEqual(
            0,
            HistorySet({
                "new.refs": {
                    "$regex": "Name Change Test"
                },
                "rev_type": "add link"
            }).count())

        self.assertEqual(
            1,
            HistorySet({
                "rev_type": "add index",
                "title": "Name Changed"
            }).count())
        self.assertEqual(
            1,
            HistorySet({
                "ref": {
                    "$regex": "Name Changed"
                },
                "rev_type": "add text"
            }).count())
        self.assertEqual(
            1,
            HistorySet({
                "new.ref": {
                    "$regex": "Name Changed"
                },
                "rev_type": "add note"
            }).count())
        self.assertEqual(
            3,
            HistorySet({
                "new.refs": {
                    "$regex": "Name Changed"
                },
                "rev_type": "add link"
            }).count())

        # In cache
        self.not_in_cache("Name Change Test")
        self.in_cache("Name Changed")

        # And in the titles api
        response = c.get("/api/index/titles")
        data = json.loads(response.content)
        self.assertTrue(u"Name Changed" in data["books"])
        self.assertTrue(u"Name Change Test" not in data["books"])

        #toc changed
        toc = json.loads(c.get("/api/index").content)
        tutils.verify_title_existence_in_toc(new["title"], orig['categories'])

        self.assertEqual(2,
                         NoteSet({
                             "ref": {
                                 "$regex": "^Name Changed"
                             }
                         }).count())
        self.assertEqual(
            3,
            LinkSet({
                "refs": {
                    "$regex": "^Name Changed"
                }
            }).count())

        # Now delete a link and a note
        response = c.delete("/api/links/" + link1["id"])
        self.assertEqual(200, response.status_code)
        response = c.delete("/api/notes/" + note2["id"])
        self.assertEqual(200, response.status_code)

        # Make sure two are now deleted
        self.assertEqual(1,
                         NoteSet({
                             "ref": {
                                 "$regex": "^Name Changed"
                             }
                         }).count())
        self.assertEqual(
            2,
            LinkSet({
                "refs": {
                    "$regex": "^Name Changed"
                }
            }).count())

        # and that deletes show up in history
        self.assertEqual(
            1,
            HistorySet({
                "old.ref": {
                    "$regex": "Name Changed"
                },
                "rev_type": "delete note"
            }).count())
        self.assertEqual(
            1,
            HistorySet({
                "old.refs": {
                    "$regex": "Name Changed"
                },
                "rev_type": "delete link"
            }).count())

        # Delete Test Index
        IndexSet({"title": u'Name Changed'}).delete()

        # Make sure that index was deleted, and that delete cascaded to: versions, counts, links, cache
        self.not_in_cache("Name Changed")
        self.assertEqual(0, IndexSet({"title": u'Name Changed'}).count())
        self.assertEqual(0, VersionSet({"title": u'Name Changed'}).count())
        self.assertEqual(0,
                         VersionStateSet({
                             "title": u'Name Changed'
                         }).count())
        self.assertEqual(
            0,
            LinkSet({
                "refs": {
                    "$regex": "^Name Changed"
                }
            }).count())
        self.assertEqual(1,
                         NoteSet({
                             "ref": {
                                 "$regex": "^Name Changed"
                             }
                         }).count())  # Notes are note removed