Ejemplo n.º 1
0
    def test_delete_by_item_id(self):
        links = ItemLink.query.all()
        assert len(links) == 0

        link_type = 'test'
        item_1 = Item.create()
        item_2 = Item.create()
        linked_item = Item.create()

        link_1 = ItemLink(type=link_type, item_id=item_1.id, linked_id=linked_item.id)
        link_2 = ItemLink(type=link_type, item_id=item_2.id, linked_id=linked_item.id)
        db.session.add(link_1)
        db.session.add(link_2)
        db.session.flush()

        links = ItemLink.query.all()
        assert len(links) == 2
        assert link_1 in links and link_2 in links

        ItemLink.delete_by_item_id(item_1.id)

        links = ItemLink.query.all()
        assert len(links) == 1
        assert link_1 not in links and link_2 in links

        ItemLink.delete_by_item_id(item_2.id)

        links = ItemLink.query.all()
        assert len(links) == 0
Ejemplo n.º 2
0
    def test_delete_by_item_id(self):
        self.assertEqual(ItemLink.query.count(), 0)

        linked_item = Item.create()

        link_1 = ItemLink(type=self.link_type, item_id=self.item_1.id, linked_id=linked_item.id)
        link_2 = ItemLink(type=self.link_type, item_id=self.item_2.id, linked_id=linked_item.id)
        db.session.add(link_1)
        db.session.add(link_2)
        db.session.flush()

        links = ItemLink.query.all()
        self.assertEqual(len(links), 2)
        self.assertIn(link_1, links)
        self.assertIn(link_2, links)

        ItemLink.delete_by_item_id(self.item_1.id)

        links = ItemLink.query.all()
        self.assertEqual(len(links), 1)
        self.assertNotIn(link_1, links)
        self.assertIn(link_2, links)

        ItemLink.delete_by_item_id(self.item_2.id)

        self.assertEqual(ItemLink.query.count(), 0)
Ejemplo n.º 3
0
    def test_create(self):
        self.assertEqual(Item.query.count(), 0)

        item_1 = Item.create("Type A")

        items = Item.query.all()
        self.assertEqual(len(items), 1)
        self.assertEqual(items[0], item_1)

        item_2 = Item.create("Type B")

        items = Item.query.all()
        self.assertEqual(len(items), 2)
        self.assertIn(item_1, items)
        self.assertIn(item_2, items)
        self.assertNotEqual(item_1, item_2)
Ejemplo n.º 4
0
    def test_create(self):
        items = Item.query.all()
        assert len(items) == 0

        item_1 = Item.create('Type A')

        items = Item.query.all()
        assert len(items) == 1
        assert items[0] == item_1

        item_2 = Item.create('Type B')

        items = Item.query.all()
        assert len(items) == 2
        assert item_1 in items and item_2 in items
        assert item_1 != item_2
Ejemplo n.º 5
0
    def test_list_index(self):
        item = Item.create()
        index = 'test'
        item_data = ItemData.create(item_id=item.id, data_json='{}', data_id='%s/album/lalala' % index)

        response = self.client.get("/data/%s" % index)
        self.assert200(response)

        response = self.client.get("/data/missing")
        self.assert404(response)
Ejemplo n.º 6
0
    def test_list_index(self):
        item = Item.create()
        index = 'test'
        item_data = ItemData.create(item_id=item.id, data_json='{}', data_id='%s/album/lalala' % index)

        response = self.client.get("/api/1/data/%s" % index)
        self.assert200(response)
        self.assertEquals(response.json, dict(index=index, item_types=ItemData.get_item_types_by_index(index)))

        response = self.client.get("/api/1/data/missing")
        self.assert404(response)
Ejemplo n.º 7
0
    def test_delete(self):
        self.assertEqual(ItemRedirect.query.count(), 0)

        item = Item.create()
        redirect = ItemRedirect(old_id=42, new_id=item.id)
        db.session.add(redirect)
        db.session.flush()
        self.assertEqual(ItemRedirect.query.count(), 1)

        redirect.delete()
        self.assertEqual(ItemRedirect.query.count(), 0)
Ejemplo n.º 8
0
    def test_list_items(self):
        item = Item.create()
        index = 'test'
        item_type = 'album'
        item_data = ItemData.create(item_id=item.id, data_json='{}', data_id='%s/%s/lalala' % (index, item_type))

        response = self.client.get("/data/%s/%s" % (index, item_type))
        self.assert200(response)

        response = self.client.get("/data/%s/missing" % index)
        self.assert404(response)
Ejemplo n.º 9
0
    def test_find_or_insert(self):
        links = ItemLink.query.all()
        assert len(links) == 0

        link_type = 'test'
        test_item_1 = Item.create()
        test_item_2 = Item.create()

        link_1 = ItemLink.find_or_insert(test_item_1.id, test_item_2.id, link_type)

        links = ItemLink.query.all()
        assert len(links) == 1
        assert links[0] == link_1

        link_2 = ItemLink.find_or_insert(test_item_1.id, test_item_2.id, link_type)

        links = ItemLink.query.all()
        assert len(links) == 1
        assert links[0] == link_2
        assert link_1 == link_2
Ejemplo n.º 10
0
    def test_item_links(self):
        item = Item.create()

        response = self.client.get("/api/1/item/%s/links" % item.id)
        self.assert200(response)
        response = self.client.get("/api/1/item/0%s/links" % item.id)
        self.assert200(response)

        response = self.client.get("/api/1/item/%s0/links" % item.id)
        self.assert404(response)
        response = self.client.get("/api/1/item/missing/links")
        self.assert404(response)
Ejemplo n.º 11
0
    def test_data_item(self):
        item = Item.create()
        index = 'test'
        item_type = 'album'
        data_id = 'lalala'
        item_data = ItemData.create(item_id=item.id, data_json='{}', data_id='%s/%s/%s' % (index, item_type, data_id))

        response = self.client.get("/data/%s/%s/%s" % (index, item_type, data_id))
        self.assertEqual(response.status_code, 307)

        response = self.client.get("/data/%s/%s/missing" % (index, item_type))
        self.assert404(response)
Ejemplo n.º 12
0
    def test_item(self):
        item = Item.create()

        response = self.client.get("/item/%s" % item.id)
        self.assert200(response)
        response = self.client.get("/item/0%s" % item.id)
        self.assert200(response)

        response = self.client.get("/item/%s0" % item.id)
        self.assert404(response)
        response = self.client.get("/item/missing")
        self.assert404(response)
Ejemplo n.º 13
0
    def test_item(self):
        item = Item.create()

        response = self.client.get("/api/1/item/%s" % item.id)
        self.assert200(response)
        response = self.client.get("/api/1/item/0%s" % item.id)
        self.assert200(response)
        self.assertEquals(response.json, item.to_dict())

        response = self.client.get("/api/1/item/%s0" % item.id)
        self.assert404(response)
        response = self.client.get("/api/1/item/missing")
        self.assert404(response)
Ejemplo n.º 14
0
    def test_data_item(self):
        item = Item.create()
        index = 'test'
        item_type = 'album'
        data_id = 'lalala'
        item_data = ItemData.create(item_id=item.id, data_json='{}', data_id='%s/%s/%s' % (index, item_type, data_id))

        response = self.client.get("/api/1/data/%s/%s/%s" % (index, item_type, data_id))
        self.assert200(response)
        self.assertEquals(response.json, dict(
            index=index, item_type=item_type,
            data_id=data_id, item_id=ItemData.data_to_item('/'.join([index, item_type, data_id]))))

        response = self.client.get("/api/1/data/%s/%s/missing" % (index, item_type))
        self.assert404(response)
Ejemplo n.º 15
0
    def test_delete(self):
        redirects = ItemRedirect.query.all()
        assert len(redirects) == 0

        item = Item.create()
        redirect = ItemRedirect(old_id=42, new_id=item.id)
        db.session.add(redirect)
        db.session.flush()

        redirects = ItemRedirect.query.all()
        assert len(redirects) == 1
        assert redirects[0] == redirect

        redirect.delete()

        redirects = ItemRedirect.query.all()
        assert len(redirects) == 0
Ejemplo n.º 16
0
    def setUp(self):
        super(ItemLinkTestCase, self).setUp()

        self.link_type = 'test'
        self.item_1 = Item.create()
        self.item_2 = Item.create()