# Path: src/publisher/tests/base.py
# class BaseCase(SimpleBaseCase, DjangoTestCase):
#     pass


from functools import partial
from os.path import join
from datetime import date, datetime, timedelta
from .base import BaseCase
from publisher import ajson_ingestor, models, utils, codes, fragment_logic
from publisher.ajson_ingestor import StateError
from publisher.utils import lmap
from unittest import skip
from unittest.mock import patch
from publisher import logic
from django.test import Client, override_settings
from django.urls import reverse
import json, copy
        self.assertEqual(models.Article.objects.count(), 1)
        self.assertEqual(models.ArticleVersion.objects.count(), 1)
        av = self.freshen(av)
        self.assertEqual(av.version, 1)  # assert the version hasn't changed

    def test_publish_fails_if_no_article(self):
        self.assertEqual(models.ArticleVersion.objects.count(), 0)
        self.assertRaises(StateError, ajson_ingestor.publish, self.msid, self.version)

    def test_publish_dry_run(self):
        "specifying a dry run does not commit changes to database"
        saved_av = ajson_ingestor.ingest(self.ajson)  # do an actual ingest first
        unsaved_av = ajson_ingestor.publish(self.msid, self.version, dry_run=True)
        self.assertEqual(models.ArticleVersion.objects.count(), 1)
        # ensure the article version stored has no published date
        models.ArticleVersion.objects.get(pk=saved_av.pk, datetime_published=None)
        # and that the object returned *does* have a datetime published
        self.assertTrue(unsaved_av.published())

    def test_publish_fails_if_invalid(self):
        "an article cannot be published if it's article-json is invalid."
        self.ajson["article"]["title"] = ""
        # ValidationError is raised during ingest
        try:
            ajson_ingestor.ingest_publish(self.ajson)
        except StateError as err:
            self.assertEqual(err.code, codes.INVALID)
            self.assertTrue("'' is too short" in err.trace)



# Path: src/publisher/tests/base.py
# class BaseCase(SimpleBaseCase, DjangoTestCase):
#     pass


# Path: src/publisher/tests/test_ajson_ingest.py
from functools import partial
from os.path import join
from datetime import date, datetime, timedelta
from .base import BaseCase
from publisher import ajson_ingestor, models, utils, codes, fragment_logic
from publisher.ajson_ingestor import StateError
from publisher.utils import lmap
from unittest import skip
from unittest.mock import patch
from publisher import logic
from django.test import Client, override_settings
from django.urls import reverse
import json, copy

        self.assertEqual(models.Article.objects.count(), 1)
        self.assertEqual(models.ArticleVersion.objects.count(), 1)
        av = self.freshen(av)
        self.assertEqual(av.version, 1)  # assert the version hasn't changed

    def test_publish_fails_if_no_article(self):
        self.assertEqual(models.ArticleVersion.objects.count(), 0)
        self.assertRaises(StateError, ajson_ingestor.publish, self.msid, self.version)

    def test_publish_dry_run(self):
        "specifying a dry run does not commit changes to database"
        saved_av = ajson_ingestor.ingest(self.ajson)  # do an actual ingest first
        unsaved_av = ajson_ingestor.publish(self.msid, self.version, dry_run=True)
        self.assertEqual(models.ArticleVersion.objects.count(), 1)
        # ensure the article version stored has no published date
        models.ArticleVersion.objects.get(pk=saved_av.pk, datetime_published=None)
        # and that the object returned *does* have a datetime published
        self.assertTrue(unsaved_av.published())

    def test_publish_fails_if_invalid(self):
        "an article cannot be published if it's article-json is invalid."
        self.ajson["article"]["title"] = ""
        # ValidationError is raised during ingest
        try:
            ajson_ingestor.ingest_publish(self.ajson)
        except StateError as err:
            self.assertEqual(err.code, codes.INVALID)
            self.assertTrue("'' is too short" in err.trace)



class IngestPublish(BaseCase):