def centre_societies_roles_data_dev(production=False): """Generate center societies and role data.""" # test centers nairobi = Center(name='nairobi') kampala = Center(name='kampala') lagos = Center(name='lagos') # societies phoenix = Society(name="phoenix") istelle = Society(name="istelle") sparks = Society(name="sparks") invictus = Society(name="invictus") # roles available roles = (Role(uuid="-KXGy1EB1oimjQgFim6F", name="success"), Role(uuid="-KXGy1EB1oimjQgFim6L", name="finance"), Role(uuid="-KXGy1EB1oimjQgFim6C", name="fellow"), Role(uuid="-KkLwgbeJUO0dQKsEk1i", name="success ops"), Role(uuid="-KiihfZoseQeqC6bWTau", name="andelan"), Role(name="society president"), Role(name="society vice president"), Role(name="society secretary")) return (roles, nairobi, kampala, lagos, phoenix, istelle, sparks, invictus) if not production else (roles, phoenix, istelle, sparks, invictus)
def setUp(self): BaseTestCase.setUp(self) self.society = Society(name="Phoenix", color_scheme="#333333", logo="https://logo.png", photo="http://photo.url2") self.society2 = dict(name="Invictus", colorScheme="#333334", logo="https://logo2.png", photo="http://photo.url") self.society.save()
def setUp(self): """Setup function to configure test enviroment.""" self.app = create_app("Testing") self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() # test client self.client = self.app.test_client() self.header = {"Authorization": self.generate_token(self.test_payload)} # mock user self.member = User(email="someonecool.andela.com", name="thecoolest", uuid="-Ksomeid", role="member", country="ke/ug/niger/ny/sa/tz/rw") self.admin = User(email="coolAdmin.andela.com", name="thecoolestAdmin", uuid="-KsomeidAdmin", role="admin", country="ke/ug/niger/ny/sa/tz/rw") # mock societies self.istelle = Society(name="istelle", photo="url/imgae", logo="url/image", color_scheme="#00ff4567") self.sparks = Society(name="sparks", photo="url/imgae", logo="url/image", color_scheme="#00ff4567") self.phenix = Society(name="phenix", photo="url/imgae", logo="url/image", color_scheme="#00ff4567") self.phenix.save() # mock points self.point = Point(value=2500, name="interview-2017-sep-23rd") # mock interview self.activity = Activity( name="Interview", value=50, description="members earn 50 points per activity", photo="cool/icon/url")
class SocietyBaseTestCase(BaseTestCase): def setUp(self): BaseTestCase.setUp(self) self.society = Society(name="Phoenix", color_scheme="#333333", logo="https://logo.png", photo="http://photo.url2") self.society2 = dict(name="Invictus", colorScheme="#333334", logo="https://logo2.png", photo="http://photo.url") self.society.save() def test_society_saved_successfully(self): old_societies = Society.query.all() post_response = self.client.post('/api/v1/societies/', data=json.dumps(self.society2), content_type='application/json') new_societies = Society.query.all() self.assertEqual(len(new_societies), len(old_societies) + 1)
class BaseTestCase(TestCase): """Contain utility required for testing.""" exp_date = datetime.datetime.utcnow() test_payload = { "UserInfo": { "email": "*****@*****.**", "first_name": "test", "id": "-Ktest_id", "last_name": "test", "name": "test test", "picture": "https://www.link.com", "roles": { "Andelan": "-Ktest_andelan_id", "Fellow": "-Ktest_fellow_id" } }, "exp": exp_date + datetime.timedelta(days=1) } def setUp(self): """Setup function to configure test enviroment.""" self.app = create_app("Testing") self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() # test client self.client = self.app.test_client() self.header = {"Authorization": self.generate_token(self.test_payload)} # mock user self.member = User(email="someonecool.andela.com", name="thecoolest", uuid="-Ksomeid", role="member", country="ke/ug/niger/ny/sa/tz/rw") self.admin = User(email="coolAdmin.andela.com", name="thecoolestAdmin", uuid="-KsomeidAdmin", role="admin", country="ke/ug/niger/ny/sa/tz/rw") # mock societies self.istelle = Society(name="istelle", photo="url/imgae", logo="url/image", color_scheme="#00ff4567") self.sparks = Society(name="sparks", photo="url/imgae", logo="url/image", color_scheme="#00ff4567") self.phenix = Society(name="phenix", photo="url/imgae", logo="url/image", color_scheme="#00ff4567") self.phenix.save() # mock points self.point = Point(value=2500, name="interview-2017-sep-23rd") # mock interview self.activity = Activity( name="Interview", value=50, description="members earn 50 points per activity", photo="cool/icon/url") @staticmethod def generate_token(payload): """Generate token.""" token = jwt.encode(payload, "secret", algorithm="HS256") return token def tearDown(self): """Clean up after every test.""" db.session.remove() db.drop_all() self.app_context.pop()
def setUp(self): """Configure test enviroment.""" os.environ['APP_SETTINGS'] = 'Testing' self.patcher = mock.patch( 'api.services.auth.helpers.add_extra_user_info', return_value=(None, None, None)) self.patcher.start() self.app = create_app("Testing") self.app_context = self.app.app_context() self.app_context.push() db.drop_all() db.create_all() # test client self.client = self.app.test_client() token_payloads_list = [ self.incomplete_payload, self.expired_payload, self.test_cio_role_payload, self.test_society_president_role_payload, self.test_auth_role_payload, self.test_finance_payload, self.test_successops_payload ] for token_payload in token_payloads_list: token_payload.update({ 'iss': self.app.config['API_ISSUER'], 'aud': self.app.config['API_AUDIENCE'] }) self.header = { "Authorization": self.generate_token(self.test_user_payload), "Content-Type": "application/json" } self.success_ops = { "Authorization": self.generate_token(self.test_successops_payload), "Content-Type": "application/json" } self.society_president = { "Authorization": self.generate_token(self.test_society_president_role_payload), "Content-Type": "application/json" } self.sparks_society_president = { "Authorization": self.generate_token(self.test_sparks_society_president_payload), "Content-Type": "application/json" } self.society_secretary = { "Authorization": self.generate_token(self.test_society_secretary_payload), "Content-Type": "application/json" } self.cio = { "Authorization": self.generate_token(self.test_cio_role_payload), "Content-Type": "application/json" } self.finance = { "Authorization": self.generate_token(self.test_finance_payload), "Content-Type": "application/json" } self.bad_token_header = { "Authorization": self.generate_token({"I don't know": "what to put here"}), "Content-Type": "application/json" } # test centers self.nairobi = Center(name='Nairobi') self.kampala = Center(name='Kampala') self.lagos = Center(name='Lagos') # test societies self.phoenix = Society(name="Phoenix", color_scheme="#00001", logo="https://bit.ly/2FTjkbV", photo="https://bit.ly/2k2l0qx") self.istelle = Society(name="iStelle", color_scheme="#00002", logo="https://bit.ly/2FTjkbV", photo="https://bit.ly/2k2l0qx") self.sparks = Society(name="Sparks", color_scheme="#00003", logo="https://bit.ly/2FTjkbV", photo="https://bit.ly/2k2l0qx") self.invictus = Society(name="Invictus", color_scheme="#00004", logo="https://bit.ly/2FTjkbV", photo="https://bit.ly/2k2l0qx") # test roles self.successops_role = Role(uuid="-KkLwgbeJUO0dQKsEk1i", name="success ops") self.fellow_role = Role(uuid="-KXGy1EB1oimjQgFim6C", name="Fellow") self.success_role = Role(uuid="-KXGy1EB1oimjQgFim6F", name="success ops") self.finance_role = Role(uuid="-KXGy1EB1oimjQgFim6L", name="finance") self.lf_role = Role(uuid="d47ec8a7-3f09-44a5-8188-ff1d40ef35b6", name="Learning Facilitator") self.president_role = Role(uuid="-KXGyd2udi2", name="society president") self.v_president_role = Role(uuid="-KXGy32odnd", name="vice president") self.secretary_role = Role(uuid="-KXGy12odfn2idn", name="society secretary") self.cio_role = Role(uuid="-KXGionceu24i2y", name="cio") # test cohorts self.cohort_12_Ke = Cohort(name="cohort-12", center=self.nairobi) self.cohort_14_Ke = Cohort(name="cohort-14", center=self.nairobi) self.cohort_12_Ug = Cohort(name="cohort-12", center=self.kampala) self.cohort_1_Nig = Cohort(name="cohort-1", center=self.lagos) # test users self.test_user = User(uuid="-KdQsMt2U0ixIy_-yWTSZ", name="Test User", photo="https://www.link.com", email="*****@*****.**", center=self.lagos, cohort=self.cohort_1_Nig, society=self.phoenix) self.test_user_2 = User(uuid="-KdQsawesome_usedk2cckjfbi", name="Test User2", photo="https://www.link.com", email="*****@*****.**", center=self.kampala, cohort=self.cohort_12_Ug, society=self.sparks) self.test_user_3 = User(uuid="-KdQsawesomb2dunkdnw", name="Test User3", photo="https://www.link.com", email="*****@*****.**", center=self.nairobi, cohort=self.cohort_12_Ke, society=self.invictus) self.test_cio = User( uuid="-KdQdsdadqwdqomb2dunkdnw", name="Test CIO", photo="https://www.link.com", email="*****@*****.**", center=self.nairobi, ) self.test_cio.roles.append(self.cio_role) self.president = User( uuid="-KdQsMtixG4U0y_-yJEH", name="Test President", photo="https://lh6.googleusercontent.com/-1DhBLOJentg/AAAAAAAAA" "AI/AAAAAAnAABc/ImeP_cAI/photo.jpg?sz=50", email="*****@*****.**", center=self.lagos, cohort=self.cohort_1_Nig, society=self.phoenix) self.president.roles.append(self.president_role) self.vice_president = User( uuid="-KdQsMtixGc2nuekwnd", name="Test Vice-President", photo="https://lh6.googleusercontent.com/-1DhBLOJentg/AAAAAAAAA" "AI/AAAAAAnAABc/ImeP_cAI/photo.jpg?sz=50", email="*****@*****.**", center=self.nairobi, cohort=self.cohort_12_Ke, society=self.sparks) self.vice_president.roles.append(self.v_president_role) self.secretary = User( uuid="-Kuty7hryt8cbkc", name="Test Secretary", photo="https://lh6.googleusercontent.com/-1DhBLOJentg/AAAAAAAAA" "AI/AAAAAAnAABc/ImeP_cAI/photo.jpg?sz=50", email="*****@*****.**", center=self.nairobi, cohort=self.cohort_14_Ke, society=self.invictus) self.secretary.roles.append(self.secretary_role) # test ActivityType self.hackathon = ActivityType(name="Hackathon", description="A Hackathon", value=100) self.tech_event = ActivityType(name="Tech Event", description="Organize a tech event", value=2500) self.interview = ActivityType( name="Bootcamp Interviews", description="Interviewing candidate for a fellow" " recruiting event", value=20, supports_multiple_participants=True) # test Activity self.alibaba_ai_challenge = Activity( name='Fashion challenge', activity_type=self.hackathon, activity_date=datetime.date.today() + datetime.timedelta(days=21), added_by=self.president) self.js_meet_up = Activity(name='Nairobi Js meetup', activity_type=self.tech_event, activity_date=datetime.date.today() + datetime.timedelta(days=14), added_by=self.president) self.bootcamp_xiv = Activity(name='Bootcamp XIV Interviews - Nairobi', activity_type=self.interview, activity_date=datetime.date.today() + datetime.timedelta(days=14), added_by=self.president) # test LoggedActivity self.log_alibaba_challenge = LoggedActivity( name="my logged activity", description="Participated in this event", value=2500, user=self.test_user, activity=self.alibaba_ai_challenge, society=self.invictus, activity_type=self.hackathon) self.log_alibaba_challenge2 = LoggedActivity( name="my second logged activity", description="Participated in this event", value=2500, user=self.test_user, activity=self.alibaba_ai_challenge, society=self.sparks, activity_type=self.hackathon) self.redemp_req = RedemptionRequest(name="T-shirt Funds Request", value=2500, user=self.test_user, center=self.test_user.center, society=self.test_user.society) # save common items to db self.tech_event.save() self.interview.save() self.hackathon.save() self.test_user.save()