Beispiel #1
0
    def test_duplicates(self):
        user = model_factories.UserFactory()
        sticker = model_factories.StickerFactory()
        label = model_factories.LabelFactory()
        association = model_factories.AssociationFactory(user=user,
                                                         sticker=sticker,
                                                         label=label)

        with pytest.raises(models.ObjectAlreadyExistsError):
            user_duplicate = model_factories.UserFactory(user_id=user.id)

        with pytest.raises(models.ObjectAlreadyExistsError):
            sticker_duplicate = model_factories.StickerFactory(
                sticker_id=sticker.id)

        with pytest.raises(models.ObjectAlreadyExistsError):
            label_duplicate = model_factories.LabelFactory(text=label.text)

        with pytest.raises(models.ObjectAlreadyExistsError):
            association_duplicate = model_factories.AssociationFactory(
                user=user, sticker=sticker, label=label)

        assert models.User.count() == 1
        assert models.Sticker.count() == 1
        assert models.Label.count() == 1
        assert models.Association.count() == 1
Beispiel #2
0
    def test_increment_usage(self):
        label = model_factories.LabelFactory()
        association = model_factories.AssociationFactory(label=label)
        assert association.uses == 0

        models.Association.increment_usage(association.user_id,
                                           association.sticker_id,
                                           [label.text])
        assert association.uses == 1
Beispiel #3
0
    def populate_associations(self, raw_associations):
        associations = [
            model_factories.AssociationFactory(
                user=models.database.session.merge(self.users[u], load=False),
                sticker=models.database.session.merge(self.stickers[s],
                                                      load=False),
                label=models.database.session.merge(self.labels[l],
                                                    load=False))
            for u, s, l in raw_associations
        ]

        return associations
Beispiel #4
0
    def test_get_usage_count(self):
        user = model_factories.UserFactory()
        sticker = model_factories.StickerFactory()
        label = model_factories.LabelFactory()
        association = model_factories.AssociationFactory(user=user,
                                                         sticker=sticker,
                                                         label=label)

        usage = models.Association.get_usage_count(sticker.id, label.text,
                                                   user.id)
        assert usage == 0

        new_usage = 5
        association.uses = new_usage
        usage = models.Association.get_usage_count(sticker.id, label.text,
                                                   user.id)
        assert usage == new_usage
Beispiel #5
0
    def test_insertion_basic(self):
        user = model_factories.UserFactory()
        sticker = model_factories.StickerFactory()
        label = model_factories.LabelFactory()
        association = model_factories.AssociationFactory(user=user,
                                                         sticker=sticker,
                                                         label=label)

        assert models.User.id_exists(user.id)
        assert models.User.count() == 1

        assert models.Sticker.id_exists(sticker.id)
        assert models.Sticker.count() == 1

        assert models.Label.id_exists(label.id)
        assert models.Label.count() == 1

        assert models.Association.id_exists(association.id)
        assert models.Association.count() == 1
Beispiel #6
0
    def test_increment_same_users_same_stickers_different_labels(self):
        users = model_factories.UserFactory.build_batch(2)
        stickers = model_factories.StickerFactory.build_batch(2)
        labels = model_factories.LabelFactory.build_batch(2)

        # user, sticker, label
        association_groups = [(0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1)]

        associations = [
            model_factories.AssociationFactory(user=users[u],
                                               sticker=stickers[s],
                                               label=labels[l])
            for u, s, l in association_groups
        ]

        relevant_indices = [0, 3]
        relevant_association_groups = [
            association_groups[i] for i in relevant_indices
        ]

        current_uses = [
            models.Association.get_usage_count(stickers[s].id, labels[l].text,
                                               users[u].id)
            for u, s, l in relevant_association_groups
        ]

        relevant_labels = [label.text for label in labels[:2]]
        models.Association.increment_usage(users[0].id, stickers[0].id,
                                           relevant_labels)

        new_uses = [
            models.Association.get_usage_count(stickers[s].id, labels[l].text,
                                               users[u].id)
            for u, s, l in relevant_association_groups
        ]

        incremented_uses = [use + 1 for use in current_uses]

        assert new_uses == incremented_uses