Esempio n. 1
0
 def setUp(self):
     self.nk_repo = NetkanRepo(Repo.init(self.test_data))
     self.ckm_repo = CkanMetaRepo(Repo.init(self.ckm_root))
     self.scheduler = NetkanScheduler(self.nk_repo, self.ckm_repo,
                                      'TestyMcTestFace', 'token')
     self.messages = (nk.sqs_message(
         self.ckm_repo.highest_version(nk.identifier))
                      for nk in self.scheduler.nk_repo.netkans())
Esempio n. 2
0
class TestCkanMetaRepo(TestRepo):
    test_data = Path(PurePath(__file__).parent, 'testdata/CKAN-meta')

    def setUp(self):
        self.ckm_repo = CkanMetaRepo(self.repo)

    def test_mod_path(self):
        self.assertTrue(self.ckm_repo.mod_path('AwesomeMod').exists())
Esempio n. 3
0
 def find_diff(self, meta_repo: CkanMetaRepo) -> Optional[str]:
     ckans = [
         ck for ck in meta_repo.ckans(self.identifier)
         if ck.version == self.version
     ]
     return None if len(ckans) != 1 else ''.join(
         unified_diff(ckans[0].contents.splitlines(True),
                      self.contents.splitlines(True),
                      fromfile=f'Previous {self.name} {self.version}',
                      tofile=f'New {self.name} {self.version}'))
Esempio n. 4
0
class TestScheduler(unittest.TestCase):
    test_data = PurePath(__file__).parent.joinpath('testdata', 'NetKAN')
    ckm_root = PurePath(__file__).parent.joinpath('testdata', 'CKAN-meta')

    def setUp(self):
        self.nk_repo = NetkanRepo(Repo.init(self.test_data))
        self.ckm_repo = CkanMetaRepo(Repo.init(self.ckm_root))
        self.scheduler = NetkanScheduler(self.nk_repo, self.ckm_repo,
                                         'TestyMcTestFace', 'token')
        self.messages = (nk.sqs_message(
            self.ckm_repo.highest_version(nk.identifier))
                         for nk in self.scheduler.nk_repo.netkans())

    def test_netkans(self):
        self.assertEqual(len(list(self.scheduler.nk_repo.netkans())), 13)

    def test_sqs_batching(self):
        batches = []
        for batch in sqs_batch_entries(self.messages):
            batches.append(batch)
        self.assertEqual(len(batches[0]), 10)
        self.assertEqual(len(batches[1]), 3)

    def test_sqs_batch_attrs(self):
        batch = list(sqs_batch_entries(self.messages))[0]
        attrs = self.scheduler.sqs_batch_attrs(batch)
        self.assertEqual(attrs['QueueUrl'], 'test_url')
        self.assertEqual(len(attrs['Entries']), 10)

    def test_sqs_batching_ten(self):
        test_data = Path(PurePath(__file__).parent, 'testdata/NetTEN')
        scheduler = NetkanScheduler(NetkanRepo(Repo.init(test_data)),
                                    self.ckm_repo, 'TestyMcTestFace', 'token')
        messages = (nk.sqs_message(self.ckm_repo.highest_version(
            nk.identifier)) for nk in scheduler.nk_repo.netkans())

        batches = []
        for batch in sqs_batch_entries(messages):
            batches.append(batch)
        self.assertEqual(len(batches[0]), 10)
        self.assertEqual(len(batches), 1)
    def test_metadata(self,
                      source: str = 'netkans',
                      pr_body: str = '',
                      github_token: Optional[str] = None,
                      diff_meta_root: Optional[str] = None) -> bool:

        logging.debug('Starting metadata test')
        logging.debug('Builds: %s',
                      [str(v) for v in CkanInstall.KNOWN_VERSIONS])

        # Escape hatch in case author replaces a download after a previous success
        # (which will save it to the persistent cache)
        overwrite_cache = ('#overwrite_cache' in pr_body)
        logging.debug('overwrite_cache: %s', overwrite_cache)

        if not self.CACHE_PATH.exists():
            self.CACHE_PATH.mkdir()

        # Action inputs are apparently '' rather than None if not set in the yml
        meta_repo = CkanMetaRepo(Repo(
            Path(diff_meta_root))) if diff_meta_root else None

        for file in self.files_to_test(source):
            if not self.test_file(file, overwrite_cache, github_token,
                                  meta_repo):
                logging.error('Test of %s failed!', file)
                self.failed = True
        if self.failed:
            return False

        if len(self.source_to_ckans) == 0:
            logging.info('No .ckans found, done.')
            return True

        # Make secondary repo file with our generated .ckans
        run(['tar', 'czf', self.TINY_REPO, '-C', self.INFLATED_PATH, '.'])

        for orig_file, files in self.source_to_ckans.items():
            logging.debug('Installing files for %s: %s', orig_file, files)
            for file in files:
                if not self.install_ckan(file, orig_file, pr_body, meta_repo):
                    logging.error('Install of %s failed!', file)
                    self.failed = True

        for identifiers in self.pr_body_tests(pr_body):
            logging.debug('Installing identifiers: %s', ' '.join(identifiers))
            if not self.install_identifiers(identifiers, pr_body):
                logging.error('Install of %s failed!', ' '.join(identifiers))
                self.failed = True

        return not self.failed
Esempio n. 6
0
 def setUpClass(cls):
     super(TestCkan, cls).setUpClass()
     cls.msg = mock.Mock()
     cls.msg.body = Path(
         PurePath(__file__).parent,
         'testdata/DogeCoinFlag-v1.02.ckan').read_text()
     cls.msg.message_attributes = {
         'CheckTime': {
             'StringValue': '2019-06-24T19:06:14',
             'DataType': 'String'
         },
         'ModIdentifier': {
             'StringValue': 'DogeCoinFlag',
             'DataType': 'String'
         },
         'Staged': {
             'StringValue': 'False',
             'DataType': 'String'
         },
         'Success': {
             'StringValue': 'True',
             'DataType': 'String'
         },
         'FileName': {
             'StringValue': './DogeCoinFlag-v1.02.ckan',
             'DataType': 'String'
         }
     }
     cls.msg.message_id = 'MessageMcMessageFace'
     cls.msg.receipt_handle = 'HandleMcHandleFace'
     cls.msg.md5_of_body = '709d9d3484f8c1c719b15a8c3425276a'
     cls.tmpdir = tempfile.TemporaryDirectory()
     working = Path(cls.tmpdir.name, 'working')
     upstream = Path(cls.tmpdir.name, 'upstream')
     upstream.mkdir()
     Repo.init(upstream, bare=True)
     shutil.copytree(cls.test_data, working)
     cls.ckan_meta = Repo.init(working)
     cls.ckan_meta.index.add(cls.ckan_meta.untracked_files)
     cls.ckan_meta.index.commit('Test Data')
     cls.ckan_meta.create_remote('origin', upstream.as_posix())
     cls.ckan_meta.remotes.origin.push('master:master')
     cls.ckm_repo = CkanMetaRepo(cls.ckan_meta)
     cls.message = CkanMessage(cls.msg, cls.ckm_repo)
Esempio n. 7
0
 def setUp(self):
     self.ckm_repo = CkanMetaRepo(self.repo)