def setUp(self): self.database = SerloDatabase("sqlite:///:memory:") self.person1, self.person2, self.person3 = generate_persons()[0:3] self.persons = [self.person1, self.person2, self.person3] self.project1, self.project2, \ self.unit1, self.unit2 = generate_working_units()[0:4] self.units = [self.project1, self.project2, self.unit1, self.unit2]
def run_script(): """Executes this script.""" try: database_file = sys.argv[1] except IndexError: sys.exit("Error: No database file specified as first argument.") try: api_token = os.environ[TOKEN_VARIABLE] except KeyError: sys.exit(f"Error: Environment Variable {TOKEN_VARIABLE} not defined.") database = SerloDatabase(database_file) persons = dict( parse_people( api_call("people", api_token, params={"tag_id": MEMBER_ID}))) deals = api_call("deals", api_token) mentoring_spec = parse_mentoring(deals) for mentor_id, mentee_ids in mentoring_spec.items(): for mentee_id in mentee_ids: mentor = persons.get(mentor_id, None) mentee = persons.get(mentee_id, None) if mentor and mentee: mentee.mentor = mentor units = parse_working_units(deals, persons) database.add_all(persons.values()) database.add_all(units)
def run_script(args): """Main function of the script.""" try: database_file, template = args except ValueError: sys.exit(f"Error: Cannot parse arguments") database = SerloDatabase(database_file) env = jinja2.Environment(autoescape=True, loader=jinja2.FileSystemLoader(".")) template = env.get_template(template) print(template.render(serlo=database))
def run_script(args): """Main function of the script.""" try: database_file, template = args except ValueError: sys.exit(f"Error: Cannot parse arguments") database = SerloDatabase(database_file) env = jinja2.Environment(autoescape=True, loader=jinja2.FileSystemLoader(".")) template = env.get_template(template) timestamp = datetime.now().astimezone(pytz.timezone('Europe/Berlin')) print(template.render( serlo=database, timestamp=timestamp ))
def run_script(): """Executes this script.""" try: database_file = sys.argv[1] except IndexError: sys.exit("Error: No database file specified as first argument.") try: api_token = os.environ[TOKEN_VARIABLE] except KeyError: sys.exit(f"Error: Environment Variable {TOKEN_VARIABLE} not defined.") database = SerloDatabase(database_file) persons = dict( parse_people( api_call("people", api_token, params={"tag_id": MEMBER_ID}))) units = parse_working_units(api_call("deals", api_token), persons) database.add_all(persons.values()) database.add_all(units)
class TestSerloDatabase(TestCase): """Testcases for the class `SerloDatabase`.""" # pylint: disable=too-many-instance-attributes def setUp(self): self.database = SerloDatabase("sqlite:///:memory:") self.person1, self.person2, self.person3 = generate_persons()[0:3] self.persons = [self.person1, self.person2, self.person3] self.project1, self.project2, \ self.unit1, self.unit2 = generate_working_units()[0:4] self.units = [self.project1, self.project2, self.unit1, self.unit2] def test_storing_nothing(self): """Testcase when nothing is stored.""" self.assertListEqual(list(self.database.persons), []) self.assertListEqual(list(self.database.working_units), []) self.database.add_all([]) self.assertListEqual(list(self.database.persons), []) self.assertListEqual(list(self.database.working_units), []) def test_attribute_persons(self): """Testcase for storing persons to `SerloDatabase`.""" self.database.add_all(self.persons) self.assertSetEqual(set(self.database.persons), set(self.persons)) def test_atttribute_working_units(self): """Testcase for storing working units to `SerloDatabase`.""" self.database.add_all([self.project2, self.project1]) self.database.add_all([self.unit1, self.unit2]) self.assertSetEqual(set(self.database.working_units), set(self.units)) def test_attribute_projects(self): """Testcase for accessing all active projects.""" self.database.add_all( [self.project1, self.project2, self.unit1, self.unit2]) self.assertSetEqual(set(self.database.projects), set([self.project1, self.project2])) def test_attribute_support_units(self): """Testcase for accessing all active support_units.""" self.database.add_all( [self.project1, self.project2, self.unit1, self.unit2]) self.assertSetEqual(set(self.database.support_units), set([self.unit1, self.unit2])) def test_attribute_managing_units(self): """Test for attribute `Person.managing_unit`.""" self.database.add_all( [self.project1, self.project2, self.unit1, self.unit2]) person1 = self.project1.person_responsible person3 = self.unit2.person_responsible self.assertEqual(list(person1.managing_units), [self.project1, self.unit1]) self.assertEqual(list(person3.managing_units), [self.unit2]) def test_attribute_participating_units(self): # pylint: disable=invalid-name """Test for attribute `Person.participating_unit`.""" self.database.add_all( [self.project1, self.project2, self.unit1, self.unit2]) person1 = self.project1.person_responsible person2 = self.project2.person_responsible self.assertEqual(set(person1.participating_units), set([self.unit2])) self.assertEqual(set(person2.participating_units), set([self.unit1, self.unit2]))