Example #1
0
 def test_add_tag(self):
     file_ = self.root.append_file('That\'s How Strong My Love Is.mp3')
     tag = Tag(name='Redding')
     tag.save()
     file_.tags.add(tag)
     file_.save()
     find = query_tag_file('Redding')['results']
     assert_equal(len(find), 1)
Example #2
0
 def test_add_tag(self):
     file_ = self.root.append_file('That\'s How Strong My Love Is.mp3')
     tag = Tag(name='Redding')
     tag.save()
     file_.tags.add(tag)
     file_.save()
     find = query_tag_file('Redding')['results']
     assert_equal(len(find), 1)
Example #3
0
    def legacy_system_tags(self):
        tags = []
        for item in [item[0] for item in PROVIDER_SOURCE_TAGS]:
            tag = Tag(name=item, system=True)
            tag.save()

        for item in [item[0] for item in CAMPAIGN_SOURCE_TAGS]:
            tag = Tag(name=item, system=True)
            tag.save()
Example #4
0
    def test_file_add_tag_fail_doesnt_create_log(self, mock_log):
        file = self.node_settings.get_root().append_file('UltraLightBeam.mp3')
        tag = Tag(name='The Life of Pablo')
        tag.save()
        file.tags.add(tag)
        file.save()
        url = self.project.api_url_for('osfstorage_add_tag', fid=file._id)
        res = self.app.post_json(url, {'tag': 'The Life of Pablo'}, auth=self.user.auth, expect_errors=True)

        assert_equal(res.status_code, 400)
        mock_log.assert_not_called()
Example #5
0
 def test_tag_the_same_tag(self):
     file = self.node_settings.get_root().append_file('Lie,Cheat,Steal.mp3')
     tag = Tag(name='Run_the_Jewels')
     tag.save()
     file.tags.add(tag)
     file.save()
     assert_in('Run_the_Jewels', file.tags.values_list('name', flat=True))
     url = self.project.api_url_for('osfstorage_add_tag', fid=file._id)
     res = self.app.post_json(url, {'tag': 'Run_the_Jewels'}, auth=self.user.auth, expect_errors=True)
     assert_equal(res.status_code, 400)
     assert_equal(res.json['status'], 'failure')
Example #6
0
 def test_file_remove_tag(self):
     file = self.node_settings.get_root().append_file('Champion.mp3')
     tag = Tag(name='Graduation')
     tag.save()
     file.tags.add(tag)
     file.save()
     assert_in('Graduation', file.tags.values_list('name', flat=True))
     url = self.project.api_url_for('osfstorage_remove_tag', fid=file._id)
     self.app.delete_json(url, {'tag': 'Graduation'}, auth=self.user.auth)
     file.reload()
     assert_not_in('Graduation', file.tags.values_list('name', flat=True))
Example #7
0
 def test_tag_the_same_tag(self):
     file = self.node_settings.get_root().append_file('Lie,Cheat,Steal.mp3')
     tag = Tag(name='Run_the_Jewels')
     tag.save()
     file.tags.add(tag)
     file.save()
     assert_in('Run_the_Jewels', file.tags.values_list('name', flat=True))
     url = api_url_for('osfstorage_add_tag', guid=self.node._id, fid=file._id)
     res = self.app.post_json(url, {'tag': 'Run_the_Jewels'}, auth=self.user.auth, expect_errors=True)
     assert_equal(res.status_code, 400)
     assert_equal(res.json['status'], 'failure')
Example #8
0
 def test_file_remove_tag(self):
     file = self.node_settings.get_root().append_file('Champion.mp3')
     tag = Tag(name='Graduation')
     tag.save()
     file.tags.add(tag)
     file.save()
     assert_in('Graduation', file.tags.values_list('name', flat=True))
     url = self.project.api_url_for('osfstorage_remove_tag', fid=file._id)
     self.app.delete_json(url, {'tag': 'Graduation'}, auth=self.user.auth)
     file.reload()
     assert_not_in('Graduation', file.tags.values_list('name', flat=True))
Example #9
0
    def test_file_add_tag_fail_doesnt_create_log(self, mock_log):
        file = self.node_settings.get_root().append_file('UltraLightBeam.mp3')
        tag = Tag(name='The Life of Pablo')
        tag.save()
        file.tags.add(tag)
        file.save()
        url = api_url_for('osfstorage_add_tag', guid=self.node._id, fid=file._id)
        res = self.app.post_json(url, {'tag': 'The Life of Pablo'}, auth=self.user.auth, expect_errors=True)

        assert_equal(res.status_code, 400)
        mock_log.assert_not_called()
Example #10
0
 def test_remove_tag(self):
     file_ = self.root.append_file('I\'ve Been Loving You Too Long.mp3')
     tag = Tag(name='Blue')
     tag.save()
     file_.tags.add(tag)
     file_.save()
     find = query_tag_file('Blue')['results']
     assert_equal(len(find), 1)
     file_.tags.remove(tag)
     file_.save()
     find = query_tag_file('Blue')['results']
     assert_equal(len(find), 0)
Example #11
0
    def test_file_remove_tag_creates_log(self):
        file = self.node_settings.get_root().append_file('Formation.flac')
        tag = Tag(name='You that when you cause all this conversation')
        tag.save()
        file.tags.add(tag)
        file.save()
        url = self.project.api_url_for('osfstorage_remove_tag', fid=file._id)
        res = self.app.delete_json(url, {'tag': 'You that when you cause all this conversation'}, auth=self.user.auth)

        assert_equal(res.status_code, 200)
        self.node.reload()
        assert_equal(self.node.logs.latest().action, 'file_tag_removed')
Example #12
0
 def test_remove_tag(self):
     file_ = self.root.append_file('I\'ve Been Loving You Too Long.mp3')
     tag = Tag(name='Blue')
     tag.save()
     file_.tags.add(tag)
     file_.save()
     find = query_tag_file('Blue')['results']
     assert_equal(len(find), 1)
     file_.tags.remove(tag)
     file_.save()
     find = query_tag_file('Blue')['results']
     assert_equal(len(find), 0)
Example #13
0
    def test_file_remove_tag_creates_log(self):
        file = self.node_settings.get_root().append_file('Formation.flac')
        tag = Tag(name='You that when you cause all this conversation')
        tag.save()
        file.tags.add(tag)
        file.save()
        url = api_url_for('osfstorage_remove_tag', guid=self.node._id, fid=file._id)
        res = self.app.delete_json(url, {'tag': 'You that when you cause all this conversation'}, auth=self.user.auth)

        assert_equal(res.status_code, 200)
        self.node.reload()
        assert_equal(self.node.logs.latest().action, 'file_tag_removed')
Example #14
0
    def test_qatest_quickfiles_files_not_appear_in_search(self):
        quickfiles = QuickFilesNode.objects.get(creator=self.node.creator)
        quickfiles_osf_storage = quickfiles.get_addon('osfstorage')
        quickfiles_root = quickfiles_osf_storage.get_root()

        file = quickfiles_root.append_file('GreenLight.mp3')
        tag = Tag(name='qatest')
        tag.save()
        file.tags.add(tag)
        file.save()

        find = query_file('GreenLight.mp3')['results']
        assert_equal(len(find), 0)
Example #15
0
    def test_qatest_quickfiles_files_not_appear_in_search(self):
        quickfiles = QuickFilesNode.objects.get(creator=self.node.creator)
        quickfiles_osf_storage = quickfiles.get_addon('osfstorage')
        quickfiles_root = quickfiles_osf_storage.get_root()

        file = quickfiles_root.append_file('GreenLight.mp3')
        tag = Tag(name='qatest')
        tag.save()
        file.tags.add(tag)
        file.save()

        find = query_file('GreenLight.mp3')['results']
        assert_equal(len(find), 0)
Example #16
0
    def add_tag(self, tag, auth, save=True, log=True):
        from osf.models import Tag, NodeLog  # Prevent import error

        if not self.tags.filter(system=False, name=tag).exists() and not self.node.is_registration:
            new_tag = Tag.load(tag)
            if not new_tag:
                new_tag = Tag(name=tag)
            new_tag.save()
            self.tags.add(new_tag)
            if log:
                self.add_tag_log(NodeLog.FILE_TAG_ADDED, tag, auth)
            if save:
                self.save()
            return True
        return False
Example #17
0
    def test_uniqueness_on_name_and_system(self):
        tag = Tag(name='FooBar', system=False)
        tag.save()

        tag2 = Tag(name='FooBar', system=False)
        with pytest.raises(ValidationError):
            tag2.save()

        tag3 = Tag(name='FooBar', system=True)
        try:
            tag3.save()
        except Exception:
            pytest.fail('Saving system tag with non-unique name should not error.')
Example #18
0
    def test_load_loads_by_name(self):
        tag_name = 'NeONDreams'
        tag = Tag(name=tag_name)
        tag.save()

        assert Tag.load(tag_name).pk == tag.pk
Example #19
0
 def test_has_an_integer_pk(self):
     tag = Tag(name='FooBar')
     tag.save()
     assert type(tag.pk) is int