Beispiel #1
0
 def test_edit_personal_data_via_profile(self):
     db_conn = DbConnect()
     api_helper = ApiHelper()
     main_page = MainPage(self.driver)
     fake_data = self.helpers.generate_fake_data()
     fake_data2 = self.helpers.generate_fake_data()
     fake_email = fake_data["email"]
     new_email = fake_data2["email"]
     sql_query = """select "email" from "worker" where email='{}';""".format(
         new_email)
     body = {
         'email': fake_email,
         'firstname': fake_data["first_name"],
         'lastname': fake_data["last_name"]
     }
     api_helper.make_http_request(method_type="POST",
                                  url_part="workers_creation",
                                  body=body)
     self.login()
     main_page.specify_search(fake_email)
     main_page.press_search_button()
     main_page.click_on_worker_name_in_grid()
     main_page.click_on_edit_profile()
     main_page.fill_fields_on_edit_pers_data(new_email,
                                             fake_data2["first_name"],
                                             fake_data2["last_name"])
     main_page.click_done_button()
     main_page.click_done_button()
     query_response = db_conn.fetch_one(sql_query)
     self.assertIsNotNone(query_response)
Beispiel #2
0
 def test_upload_file_via_profile(self):
     main_page = MainPage(self.driver)
     api_helper = ApiHelper()
     db_conn = DbConnect()
     fake_data = self.helpers.generate_fake_data()
     fake_data2 = self.helpers.generate_fake_data()
     image_path = os.path.join(os.path.abspath('..'), 'tmp', 'test.png')
     email = fake_data["email"]
     cert_name = fake_data["cert_name"]
     body = {
         'email': email,
         'firstname': fake_data["first_name"],
         'lastname': fake_data["last_name"]
     }
     sql_query = '''select "courseName" from "certificate" 
             where "workerId"=(select "id" from worker where email='{}') 
             and "courseName"='{}';'''.format(email, cert_name)
     api_helper.make_http_request(method_type="POST",
                                  url_part="workers_creation",
                                  body=body)
     self.login()
     main_page.specify_search(email)
     main_page.press_search_button()
     main_page.click_on_worker_name_in_grid()
     main_page.click_add_new_record()
     main_page.send_file_to_upload_input(image_path)
     main_page.select_from_drop_down()
     main_page.type_certificate_name(cert_name)
     main_page.type_tr_provider_name(fake_data2["cert_name"])
     main_page.type_dates("2016-12-10", "2019-12-12")
     main_page.type_additional_info(fake_data2["cert_name"])
     main_page.press_submit_button()
     query_response = db_conn.fetch_one(sql_query)
     self.assertIsNotNone(query_response)
Beispiel #3
0
 def test_edit_certificates(self):
     main_page = MainPage(self.driver)
     api_helper = ApiHelper()
     db_conn = DbConnect()
     fake_data = self.helpers.generate_fake_data()
     fake_data2 = self.helpers.generate_fake_data()
     email = fake_data["email"]
     first_name = fake_data["first_name"]
     last_name = fake_data["last_name"]
     image_file = "efb9c5a7-862b-46ca-9ce3-7c8110d0cbff_share rules.png"
     query = """select "id" from worker where email='{}';""".format(email)
     worker_body = {
         'email': email,
         'firstname': first_name,
         'lastname': last_name
     }
     api_helper.make_http_request(method_type="POST",
                                  url_part="workers_creation",
                                  body=worker_body)
     worker_id = db_conn.fetch_one(query)[0]
     cert_body = {
         'courseName': fake_data["cert_name"],
         'description': fake_data["random_phrase"],
         'expiration': "2030-11-05T16:01:38.433Z",
         'file': image_file,
         'issued': "2016-11-05T16:01:38.433Z",
         'trainingProvider': fake_data2["cert_name"],
         'workerId': worker_id
     }
     certificate_query = """select "courseName" from "certificate" where "workerId"=(
     select "id" from worker where email='{}') 
     and "courseName"='{}' 
     and "description"='{}' 
     and "trainingProvider"='{}' 
     and "file"='{}';""".format(
         email, "Certificate name after EDITING",
         "Additional Certificate Details after EDITING",
         "Training Provider Name after EDITING", image_file)
     api_helper.make_http_request(method_type="POST",
                                  url_part="certificates_creation",
                                  body=cert_body)
     self.login()
     main_page.specify_search(email)
     main_page.press_search_button()
     main_page.click_on_worker_name_in_grid()
     main_page.click_edit_certificates_control()
     main_page.type_certificate_name("Certificate name after EDITING")
     main_page.type_tr_provider_name("Training Provider Name after EDITING")
     main_page.type_dates("2000-01-01", "2040-12-12")
     main_page.type_additional_info(
         "Additional Certificate Details after EDITING")
     main_page.press_submit_button()
     query_response = db_conn.fetch_one(certificate_query)
     self.assertIsNotNone(query_response)
Beispiel #4
0
 def test_verify_project_team_filter(self):
     main_page = MainPage(self.driver)
     api_helper = ApiHelper()
     fake_data = self.helpers.generate_fake_data()
     team_name = fake_data["cert_name"]
     worker_id = self.helpers.create_worker()
     body = {'name': team_name, 'workerIds': [worker_id]}
     api_helper.make_http_request(method_type="POST",
                                  url_part="teams_creation",
                                  body=body)
     self.login()
     main_page.open_project_teams_filter()
     main_page.mark_checkbox_in_modals()
     main_page.click_apply_button_in_modals()
     self.assertTrue(main_page.verify_chips_is_present())
     main_page.select_all_workers_in_the_grid()
     self.assertTrue(main_page.verify_text_of_counting_worker())
class CertificatesGenerator:
    def __init__(self):
        self.image_file = "efb9c5a7-862b-46ca-9ce3-7c8110d0cbff_share rules.png"
        self.issued_date = "2016-11-05T16:01:38.433Z"
        self.url = os.path.join(Config.api_host, Config.create_certs_path)
        self.fake = Faker('en_CA')
        self.api_helper = ApiHelper()
        self.token = self.api_helper.auth_token
        self.header = {
            'Authorization':
            'bln type=session,version=1,token="{}"'.format(self.token)
        }

    def get_workers_id(self):
        if Config.env == "prod":
            workers_list = self.api_helper.make_http_request(
                method_type="GET", url_part="workers_creation").json()
            return [d.get('id') for d in workers_list]
        else:
            db_conn = DbConnect()
            query = '''select "id" from "worker" where "employerId"={} and "archived"=false;'''.format(
                Config.db_login)
            worker_id = db_conn.fetch_all(query)
            return [x[0] for x in worker_id]

    def generate_payload(self, worker_id: int, course_names: str) -> dict:
        body = {
            'courseName': course_names,
            'description': self.fake.catch_phrase(),
            'expiration': gen_date(),
            'file': self.image_file,
            'issued': self.issued_date,
            'trainingProvider': self.fake.company(),
            'workerId': worker_id
        }
        return body

    def add_certificates(self, course_names: list):
        certificates_id = []
        for worker_id in self.get_workers_id():
            response = requests.post(self.url,
                                     headers=self.header,
                                     json=self.generate_payload(
                                         worker_id,
                                         random.choice(course_names)))
            certificates_id.append(response.json().get('id'))
            if response.status_code == 201:
                pass
            else:
                print("Certificate is not created", response.status_code)
                break
        return certificates_id
Beispiel #6
0
 def test_validate_main_search(self):
     main_page = MainPage(self.driver)
     api_helper = ApiHelper()
     fake_data = self.helpers.generate_fake_data()
     email = fake_data["email"]
     f_name = "{} {}".format(fake_data["name_prefix"],
                             fake_data["first_name"])
     l_name = fake_data["last_name"]
     first_and_last_name = "{} {}".format(f_name, l_name)
     employee_id = fake_data["random_number"]
     body = {
         'email': email,
         'firstname': f_name,
         'lastname': l_name,
         'employeeId': employee_id
     }
     api_helper.make_http_request(method_type="POST",
                                  url_part="workers_creation",
                                  body=body)
     self.login()
     # search by first and last name
     main_page.specify_search(first_and_last_name)
     main_page.press_search_button()
     self.assertTrue(
         main_page.check_name_exist_in_grid(first_and_last_name))
     # search by email
     main_page.clear_search_filed()
     main_page.specify_search(email)
     main_page.press_search_button()
     self.assertTrue(
         main_page.check_name_exist_in_grid(first_and_last_name))
     # search by worker's employee id
     main_page.clear_search_filed()
     main_page.specify_search(employee_id)
     main_page.press_search_button()
     self.assertTrue(
         main_page.check_name_exist_in_grid(first_and_last_name))
Beispiel #7
0
 def test_archived_worker(self):
     main_page = MainPage(self.driver)
     api_helper = ApiHelper()
     db_conn = DbConnect()
     fake_data = self.helpers.generate_fake_data()
     email = fake_data["email"]
     sql_query = """select "email" from worker where email='{}' and archived='true';""".format(
         email)
     body = {
         'email': email,
         'firstname': fake_data["first_name"],
         'lastname': fake_data["last_name"]
     }
     api_helper.make_http_request(method_type="POST",
                                  url_part="workers_creation",
                                  body=body)
     self.login()
     main_page.specify_search(email)
     main_page.press_search_button()
     main_page.click_on_checkbox_next_to_worker()
     main_page.click_on_archive_button()
     main_page.click_on_archive_button_in_dialog()
     query_response = db_conn.fetch_one(sql_query)
     self.assertIsNotNone(query_response)
Beispiel #8
0
class Helpers:
    def __init__(self):
        self.api_helper = ApiHelper()
        self.db_conn = DbConnect()
        self.fake = Faker()

    @staticmethod
    def get_count_of_emails_in_csv():
        def count_unique_emails():
            list_of_files = glob.glob('{}\\report*.csv'.format(
                Config.download_path))
            with open(list_of_files[0], 'r') as csv_report:
                csv_file = csv.DictReader(csv_report)
                emails_list = [
                    dict(row).get('Email address') for row in csv_file
                ]
                return len(set(emails_list))

        try:
            emails_number = count_unique_emails()
        except:
            time.sleep(1)
            emails_number = count_unique_emails()
        return emails_number

    def create_worker(self):
        fake_data = self.generate_fake_data()
        fake_email = fake_data["email"]
        body = {
            'email': fake_email,
            'firstname': fake_data["first_name"],
            'lastname': fake_data["last_name"]
        }
        response = self.api_helper.make_http_request(
            method_type="POST", url_part="workers_creation", body=body)
        return response.json().get('id')

    def create_multiple_workers(self, number):
        fake = Faker()
        names_list = []
        for i in range(number):
            body = {
                'email': fake.email(),
                'firstname': fake.first_name(),
                'lastname': fake.last_name()
            }
            self.api_helper.make_http_request(method_type="POST",
                                              url_part="workers_creation",
                                              body=body)
            names_list.append(body.get('firstname'))
            names_list.append(body.get('lastname'))
        return names_list

    @staticmethod
    def clear_download_folder():
        download_path = os.path.join(os.path.abspath('..'), 'tmp')
        list_csv_for_remove = glob.glob('{}\\*.csv'.format(download_path))
        [os.remove(csv_file) for csv_file in list_csv_for_remove]

    def set_no_primary_report(self):
        set_no_report_query = '''update "report" set "primary" = 'false' where "primary" = 'true';'''
        check_report_query = '''select "primary" from "report" where "primary" = 'true';'''
        query_response = self.db_conn.fetch_all(check_report_query)
        if query_response:
            self.db_conn.write_to_db(set_no_report_query)

    @staticmethod
    def gen_date():
        expiration_date = "{}-{}-{}T15:15:10.440Z".format(
            random.randint(2017, 2023),
            random.choice(["%.2d" % i for i in range(1, 12)]),
            random.choice(["%.2d" % i for i in range(1, 25)]))
        return expiration_date

    def generate_fake_data(self):
        fake_data = {
            "email": self.fake.email(),
            "email2": self.fake.email(),
            "first_and_last_name": self.fake.name(),
            "first_name": self.fake.first_name(),
            "last_name": self.fake.last_name(),
            "name_prefix": self.fake.prefix(),
            "cert_name": self.fake.company(),
            "cert_name2": self.fake.company(),
            "city": self.fake.city(),
            "country": self.fake.country(),
            "street_name": self.fake.street_name(),
            "random_phrase": self.fake.catch_phrase(),
            "random_phrase2": self.fake.catch_phrase(),
            "random_number": self.fake.ean(length=13)
        }
        return fake_data