def test_custom_license_text(self):
     repo = ContentRepository(
         license=CUSTOM_REPO_LICENSE_TYPE,
         custom_license_name='Foo',
         custom_license_text='Bar')
     repo.save()
     self.assertEqual(repo.get_license_text(), 'Bar')
     self.assertEqual(unicode(repo), 'Foo (Custom license)')
 def test_write_license_file(self):
     with self.settings(GIT_REPO_PATH=self.workspace.working_dir):
         repo = ContentRepository(license='CC-BY-4.0')
         repo.save()
         file_path = os.path.join(settings.GIT_REPO_PATH, 'LICENSE')
         with open(file_path, 'r') as fp:
             license_text = fp.read()
         self.assertEqual(license_text, repo.get_license_text())
    def test_setting_of_target_fields(self):
        cr = ContentRepository(license='CC-BY-4.0')
        cr.save()
        self.assertEqual(cr.url, '[email protected]/foo.git')
        self.assertEqual(cr.name, 'foo')
        self.assertFalse(cr.targets.exists())
        self.assertEqual(PublishingTarget.objects.count(), 0)

        model_admin = ContentRepositoryAdmin(ContentRepository, admin)
        obj = model_admin.get_object(None, cr.pk)
        self.assertEqual(obj.url, '[email protected]/foo.git')
        self.assertEqual(obj.name, 'foo')
        self.assertEqual(PublishingTarget.objects.count(), 1)
        [target] = obj.targets.all()
        self.assertEqual(target.name, 'The Target')