'Simulate a new artifact being loaded into the store via the UI.'

def testNewArtifactLoaded(self):

    cmd_artifact = 'name:    "TestCmdArtifact"\ndoc:    "Test    command    artifact    for    dpkg."\nsources:\n-    type:    "COMMAND"\n        attributes:\n                cmd:    "/usr/bin/dpkg"\n                args:    ["--list"]\nlabels:    [    "Software"    ]\nsupported_os:    [    "Linux"    ]\n'
    no_datastore_artifact = 'name:    "NotInDatastore"\ndoc:    "Test    command    artifact    for    dpkg."\nsources:\n-    type:    "COMMAND"\n        attributes:\n                cmd:    "/usr/bin/dpkg"\n                args:    ["--list"]\nlabels:    [    "Software"    ]\nsupported_os:    [    "Linux"    ]\n'
    test_registry = artifact_registry.ArtifactRegistry()
    test_registry.ClearRegistry()
    test_registry._dirty = False
    with utils.Stubber(artifact_registry, 'REGISTRY', test_registry):
        collect_flow = collectors.ArtifactCollectorFlow(None, token=self.token)
        with self.assertRaises(artifact_registry.ArtifactNotRegisteredError):
            artifact_registry.REGISTRY.GetArtifact('TestCmdArtifact')
        with self.assertRaises(artifact_registry.ArtifactNotRegisteredError):
            artifact_registry.REGISTRY.GetArtifact('NotInDatastore')
        artifact_coll = artifact_registry.ArtifactCollection(rdfvalue.RDFURN('aff4:/artifact_store'), token=self.token)
        for artifact_val in artifact_registry.REGISTRY.ArtifactsFromYaml(cmd_artifact):
            artifact_coll.Add(artifact_val)
        for artifact_val in artifact_registry.REGISTRY.ArtifactsFromYaml(no_datastore_artifact):
            artifact_registry.REGISTRY.RegisterArtifact(artifact_val, source='datastore', overwrite_if_exists=False)
        self.assertTrue(collect_flow._GetArtifactFromName('TestCmdArtifact'))
        with self.assertRaises(artifact_registry.ArtifactNotRegisteredError):
            artifact_registry.REGISTRY.GetArtifact('NotInDatastore')
