def test_import_projects(celery_session_worker, contact_types, partners): VIP = factories.VIPGroup() factories.UserFactory.create(first_name='Julia', last_name='Crayon', groups=[VIP]) factories.UserFactory.create(first_name='Rebecca', last_name='Kafe', groups=[VIP]) factories.UserFactory.create(first_name='Embury', last_name='Bask') factories.UserFactory.create(first_name='Colman', last_name='Level', groups=[VIP]) factories.UserFactory.create(first_name='Nic', last_name='Purple', groups=[VIP]) factories.UserFactory.create(first_name='James', last_name='BK') projects_json = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../data/projects.json") importer = ProjectsImporter() importer.import_json_file(projects_json, True) projects = Project.objects.all() assert 2 == projects.count() project1 = Project.objects.filter( acronym='In vitro disease modeling').first() assert ["Joanne Swift", "Rebecca Kafe"] == [ custodian.full_name for custodian in project1.local_custodians.all() ] assert 1 == project1.company_personnel.count() assert False == project1.has_cner assert True == project1.has_erp assert ["Embury Bask"] == [ employee.full_name for employee in project1.company_personnel.all() ] assert "test notes 123" == project1.erp_notes assert 2 == project1.publications.count() project2 = Project.objects.filter(acronym='CCCC deficiency').first() assert ["Colman Level"] == [ custodian.full_name for custodian in project2.local_custodians.all() ] assert 3 == project2.company_personnel.count() assert 1 == project2.publications.count() #2016-11-01 assert 2016 == project2.start_date.year assert 11 == project2.start_date.month assert 1 == project2.start_date.day assert 1 == project2.publications.count()
def handle(self, *args, **options): try: path_to_json_file = options.get('f') with open(path_to_json_file) as json_file: json_file_contents = json_file.read() importer = ProjectsImporter() importer.import_json(json_file_contents) self.stdout.write(self.style.SUCCESS("Import was successful!")) except Exception as e: self.stderr.write( self.style.ERROR( "Something went wrong during the import! Is the path valid? Is the file valid?" )) self.stderr.write(self.style.ERROR(str(e)))
def handle(self, *args, **options): try: projects_json_file = os.path.join(DEMO_DATA_DIR, 'projects.json') with open(projects_json_file, encoding='utf-8') as json_file: json_file_contents = json_file.read() importer = ProjectsImporter() importer.import_json(json_file_contents) self.stdout.write(self.style.SUCCESS("Project import successful!")) dataset_json_file = os.path.join(DEMO_DATA_DIR, 'datasets.json') with open(dataset_json_file, encoding='utf-8') as json_file: json_file_contents = json_file.read() importer = DatasetsImporter() importer.import_json(json_file_contents) self.stdout.write(self.style.SUCCESS("Dataset import successful!")) datadecs_json = os.path.join(DEMO_DATA_DIR, 'datadecs.json') with open(datadecs_json, encoding='utf-8') as json_file: json_file_contents = json_file.read() importer = DatadecsImporter() importer.import_json(json_file_contents) self.stdout.write(self.style.SUCCESS("Data declaration import successful!")) admin_usr = User.objects.create_user(username='******', password='', email='*****@*****.**') admin_usr.is_superuser =True admin_usr.save() users = User.objects.all() for user in users: if not user.username == 'AnonymousUser': user.is_active = True user.is_staff = True user.set_password('demo') user.save() except Exception as e: self.stderr.write( self.style.ERROR("Something went wrong during the import! Is the path valid? Is the file valid?")) self.stderr.write(self.style.ERROR(str(e)))
def get_importer(self): return ProjectsImporter()
def _load_demo_projects(self): projects_json_file = os.path.join(DEMO_DATA_DIR, 'projects.json') importer = ProjectsImporter() importer.import_json_file(projects_json_file, False, True) self.stdout.write(self.style.SUCCESS("Project import successful!"))