def test_dlrn_server(staged_env):
    """
    General server testing, with a single promotion
    :param staged_env: The staged env fixture
    :return: None
    """
    stage_info, promoter = staged_env
    commit = stage_info['dlrn']['promotions']['promotion_candidate']
    candidate_label = commit['name']
    promote_name = stage_info['dlrn']['promotion_target']
    repo_url = stage_info['dlrn']['server']['repo_url']

    client = promoter.dlrn_client
    dlrn_hash = DlrnHash(source=commit)
    dlrn_hash.label = candidate_label

    # TODO: Check db injection (needs sqlite3 import)
    #  Check we can access dlrnapi
    try:
        client.promote(dlrn_hash,
                       promote_name,
                       candidate_label=candidate_label,
                       create_previous=False)
        assert True, "Dlrn api responding"
    except ApiException as e:
        msg = "Exception when calling DefaultApi->api_promote_post: %s\n" % e
        assert False, msg

    # Check if we can access repo_url and get the versions file
    versions_url = os.path.join(repo_url, promote_name, 'versions.csv')
    try:
        url.urlopen(versions_url)
        assert True, "Versions file found"
    except IOError:
        assert False, "No versions file generated"
 def test_commit_dir(self):
     for hash_type, source_types in hashes_test_cases.items():
         dh = DlrnHash(source=source_types['object']['valid'])
         if hash_type == "commitdistro":
             self.assertEqual(dh.commit_dir, "ab/cd/abcd_defg")
         elif hash_type == "aggregate":
             dh.label = "label"
             self.assertEqual(dh.commit_dir, "label/ab/cd/abcd")