def test_json_not_archetype_on_save():
    # JSON files that are not resourcetype "archetype" should be ignored, as
    # they are probably config files or something, not content
    archivist = S3archivist(bucket=testbucket,
                            siteconfig={},
                            jinja=mock.Mock())
    json_asset = archivist.new_resource('test.json', data={"json": "test"},
                                        contenttype='application/json')
    these = scribe.on_save(archivist, json_asset)
    assert len(these) == 0
def test_json_on_save():
    archivist = S3archivist(bucket=testbucket,
                            siteconfig=siteconfig,
                            s3=mock.Mock())
    archivist.s3.get_object.side_effect = ClientError({"Error": {}},
                                                      "NoSuchKey")
    archivist.publish = mock.Mock()
    the_thingy = archivist.new_resource('test.json',
                                        data=archetype,
                                        contenttype='application/json',
                                        resourcetype='archetype')
    these = scribe.on_save(archivist, the_thingy)
    assert len(these) == 1
    resource = these[0]
    assert resource.contenttype == 'text/html; charset=utf-8'
    assert resource.resourcetype == 'artifact'
    assert resource.archetype_guid == archetype['Item']['guid']
    assert "<p>test</p>" in resource.text
    assert archivist.publish.called_with(resource)