class ModelTestCase(TestCase): """This class defines the test suite for the bucketlist model.""" def setUp(self): """Define the test client and other test variables.""" self.project_title = "Write world class code" self.project_owner = "It's a me" self.project = Project(title=self.project_title, owner=self.project_owner) def test_model_can_create_a_project(self): """Test the Project model can create a project.""" old_count = Project.objects.count() self.project.save() new_count = Project.objects.count() self.assertNotEqual(old_count, new_count)
def insert_user_projects(proj_dir, user): for project_name in os.listdir(proj_dir): num_threads = get_num_threads(os.path.join(proj_dir, project_name)) exec_time = get_exec_time(os.path.join(proj_dir, project_name)) if not os.path.exists( os.path.join( os.path.join(proj_dir, project_name, 'workdir', 'results'), f'{project_name}.log')): project_task_status = 'FAILURE' mod_time = os.path.getmtime(os.path.join(proj_dir, project_name)) else: project_task_status = 'SUCCESS' mod_time = os.path.getmtime( os.path.join(proj_dir, project_name, 'config.ctl')) start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(mod_time)) e_time = mod_time + exec_time end_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(e_time)) project = Project(name=project_name, user=user, num_threads=num_threads, execution_time=exec_time, status=project_task_status, start_time=start_time, end_time=end_time) db.session.add(project) db.session.commit()
def test_project_seconds_to_time(self): user = add_user() new_project = Project(name='test', user=user, execution_time=60) db.session.add(new_project) db.session.commit() project = Project.query.filter_by(name='test').first() self.assertEqual(project.convert_seconds_to_time(), '0:01:00')
def test_user_projects(self): user = add_user() new_project1 = Project(name='test1', user=user, start_time=datetime(2019, 6, 25, 12, 32, 45), end_time=datetime(2019, 6, 25, 12, 32, 56)) db.session.add(new_project1) db.session.commit() new_project2 = Project(name='test2', user=user, start_time=datetime(2019, 6, 25, 12, 32, 45), end_time=datetime(2019, 6, 25, 12, 32, 56)) db.session.add(new_project2) db.session.commit() projects = Project.query.all() self.assertEqual(projects[0].user_id, 1) self.assertEqual(projects[1].user_id, 1) self.assertEqual(len(user.projects), 2) self.assertEqual(user.projects[0].name, 'test1') self.assertEqual(user.projects[0].start_time, datetime(2019, 6, 25, 12, 32, 45))
def test_project_to_json(self): user = add_user() new_project = Project(name='test', user=user, start_time=datetime(2019, 6, 25, 12, 32, 45), end_time=datetime(2019, 6, 25, 12, 32, 56)) db.session.add(new_project) db.session.commit() project = Project.query.filter_by(name='test').first() project_json = project.to_json() self.assertEqual(project_json['name'], 'test') self.assertEqual(project_json['status'], 'PENDING') self.assertEqual(project_json['num_threads'], 2) self.assertEqual(project_json['execution_time'], '0:00:00') self.assertEqual(project_json['start_time'], '2019-06-25 12:32:45') self.assertEqual(project_json['end_time'], '2019-06-25 12:32:56')
def create_projects(): with open("projects.json") as f: projects = json.load(f) for project_dict in projects: project = Project() project.name = project_dict["name"] project.release_date = datetime.datetime.strptime(project_dict["releaseDate"], "%Y-%m-%d").date() project.website_url = project_dict["websiteUrl"] project.logo_url = project_dict["logoUrl"] project.description = project_dict["description"] for platform_id in project_dict["platforms"]: platform = Platform.query.filter_by(platform_id=platform_id).first() project.platforms.append(platform) db.session.add(project) db.session.commit()
def add_test_data(): admin = User.query.get(1) tag1 = Tag(**{'title': 'Programming'}) tag2 = Tag(**{'title': 'Programming'}) tag3 = Tag(**{'title': 'Social studies'}) tag4 = Tag(**{'title': 'Creative'}) tag5 = Tag(**{'title': 'Engineering'}) admin.tags.append(tag5) group = Group( **{ 'name': 'Copenhagen Office', 'address': 'Købmagergade 67', 'zipcode': '1150', 'city': 'Copenhagen', 'country': 'Denmark' }) role = Role(**{'name': 'Application consultant'}) user1 = User( **{ 'email': '*****@*****.**', 'password': '******', 'name': 'Jonatan Tegen', 'admin': False, 'verified': False }) education1 = Education( **{ 'title': 'Engineering Physics', 'school': 'LTH', 'extent': 'Master\'s degree', 'description': 'Learned cool stuff!' }) admin.educations.append(education1) education2 = Education( **{ 'title': 'Psychology', 'school': 'Lund University', 'type': 'COURSE', 'extent': 'One semester', 'description': '' }) education3 = Education( **{ 'title': 'Math', 'school': 'LTH', 'type': 'COURSE', 'extent': '30HP', 'description': 'Math man..!' }) project = Project( **{ 'title': 'Some cool project', 'description': 'DO STUFF', 'startdate': '2018-01-01T00:00+01:00', 'enddate': '2018-08-01T00:00+01:00', 'hours': 100 }) location1 = Location( **{ 'description': 'HQ', 'latitude': 55.6831585, 'longitude': 13.1756237, 'street': 'Sankt Lars väg 46', 'zipcode': '222 70', 'city': 'Lund', 'country': 'Sweden' }) customer = Customer( **{ 'name': 'Lime Technologies AB', 'customer_number': '123456', 'registration_number': '', 'location_id': 1 }) contact_person = ContactPerson(**{ 'firstname': 'Jonatan', 'lastname': 'Tegen', 'title': 'Consultant manager' }) project_response = ProjectResponse(**{'type': 'INTERESTED'}) location1.customers.append(customer) location1.projects.append(project) customer.projects.append(project) customer.contactpersons.append(contact_person) education1.tags.append(tag1) education2.tags.append(tag3) user1.tags.append(tag2) user1.tags.append(tag4) user1.educations.append(education2) user1.educations.append(education3) user1.projectresponses.append(project_response) project.projectresponses.append(project_response) role.users.append(user1) group.users.append(user1) db.session.add(tag5) db.session.add(education1) db.session.add(user1) db.session.add(location1) db.session.commit()
def setUp(self): """Define the test client and other test variables.""" self.project_title = "Write world class code" self.project_owner = "It's a me" self.project = Project(title=self.project_title, owner=self.project_owner)