示例#1
0
文件: base.py 项目: Jenniferstrej/lax
    def add_or_update_article(self, **adata):
        "creates article+article-version stubs for testing"
        replacements = [
            ('pub-date', 'published'),
            ('update', 'versionDate'),
        ]
        renkeys(adata, replacements)

        struct = {
            'id':
            utils.doi2msid(adata['doi'])
            if 'doi' in adata else adata['manuscript_id'],
            'volume':
            1,
            'type':
            'research-article',
            'title':
            '[default]',
            'version':
            1,
            'status':
            models.VOR,
            'published':
            '2012-01-01T00:00:00Z'
        }
        struct.update(adata)
        delall(struct, ['journal'])  # can't be serialized, not utilised anyway

        with self.settings(VALIDATE_FAILS_FORCE=False):
            # bad ajson won't fail ingest
            av = ajson_ingestor.ingest_publish({'article': struct}, force=True)
            av.datetime_published = utils.todt(struct['published'])
            av.save()
            return av
示例#2
0
    def setUp(self):
        ingest_these = [
            "elife-01968-v1.xml.json",  # => 01749
            "elife-16695-v1.xml.json",  # => []
            #"elife-16695-v2.xml.json",
            "elife-20125-v1.xml.json",  # poa
            #"elife-16695-v3.xml.json"
        ]
        ajson_dir = join(self.fixture_dir, 'ajson')
        for ingestable in ingest_these:
            path = join(ajson_dir, ingestable)
            data = json.load(open(path, 'r'))
            # remove these values here so they don't interfere in creation
            utils.delall(
                data,
                ['-related-articles-internal', '-related-articles-external'])
            ajson_ingestor.ingest_publish(data)

        self.msid1 = 1968
        self.msid2 = 16695
        self.msid3 = 20125

        self.av = models.ArticleVersion.objects.get(
            article__manuscript_id=self.msid1, version=1)
        self.a = models.Article.objects.get(
            manuscript_id=self.msid2)  # note: no version information
示例#3
0
文件: base.py 项目: Jenniferstrej/lax
 def load_ajson(self, path, strip_relations=True):
     "loads an article-json fixture. conveniently strips relations by default"
     data = json.load(open(path, 'r'))
     if strip_relations:
         # remove these values here so they don't interfere in creation
         utils.delall(
             data['article'],
             ['-related-articles-internal', '-related-articles-external'])
     return data
示例#4
0
 def test_delall(self):
     x = {'a': 1, 'b': 2, 'c': 3}
     expected_list = [
         (['a', 'b', 'c'], {}),
         (['a', 'b'], {'c': 3}),
         (['a'], {'b': 2, 'c': 3}),
         ([], x),
     ]
     for keys, expected in expected_list:
         y = copy.deepcopy(x)
         utils.delall(y, keys)
         self.assertEqual(y, expected)
示例#5
0
    def setUp(self):
        ingest_these = [
            #"elife-01968-v1.xml.json",
            "elife-20125-v1.xml.json",  # poa
            "elife-20125-v2.xml.json",  # poa
            "elife-20125-v3.xml.json",  # vor, related to 21162

            #"elife-21162-v1.xml.json", # vor, related to 20125

            #"elife-16695-v1.xml.json",
            #"elife-16695-v2.xml.json",
            #"elife-16695-v3.xml.json", # vor
            "elife-20105-v1.xml.json",  # poa
            "elife-20105-v2.xml.json",  # poa
            "elife-20105-v3.xml.json"  # poa, UNPUBLISHED
        ]
        ajson_dir = join(self.fixture_dir, 'ajson')
        for ingestable in ingest_these:
            data = self.load_ajson(join(ajson_dir, ingestable))
            # remove these values here so they don't interfere in creation
            utils.delall(
                data,
                ['-related-articles-internal', '-related-articles-external'])
            ajson_ingestor.ingest_publish(data)

        self.msid1 = 20125
        self.msid2 = 20105

        # 2 article, 6 versions, 5 published, 1 unpublished
        self.unpublish(self.msid2, version=3)

        # an unauthenticated client
        self.c = Client()
        # an authenticated client
        self.ac = Client(**{
            mware.CGROUPS: 'admin',
        })
示例#6
0
文件: base.py 项目: Jenniferstrej/lax
    def load_ajson2(self, path_or_data):
        "loads an article-json fixture. conveniently strips relations and other troublesome things"
        if isinstance(path_or_data, str):
            # assume string is a path to a file
            path = path_or_data
            data = json.load(open(path, 'r'))
        else:
            # assume data is article-json
            data = path_or_data

        # remove the 'journal' and 'snippet' sections if present
        if 'article' in data:
            data = data['article']

        # remove these values here so they don't interfere in creation
        utils.delall(data, [
            '-related-articles-internal', '-related-articles-external',
            '-history'
        ])

        # remove these values here so they don't interfere with comparison
        utils.delall(data, ['-meta', 'statusDate', 'versionDate'])

        return data
示例#7
0
 def test_delall_bad_idx(self):
     x = {'a': 1, 'b': 2, 'c': 3}
     y = copy.deepcopy(x)
     utils.delall(x, ['foo', 'bar', 'baz'])
     self.assertEqual(x, y)