示例#1
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)
示例#2
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)
示例#3
0
 def test_download_csv(self):
     main_page = MainPage(self.driver)
     db_conn = DbConnect()
     self.login()
     main_page.click_download_csv_button()
     sql_query = '''select count(email) 
     from worker where "employerId"='{}' and archived='False';'''.format(
         Config.db_login)
     query_response = db_conn.fetch_one(sql_query)
     self.assertEqual(self.helpers.get_count_of_emails_in_csv(),
                      query_response[0])
示例#4
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)
 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]
示例#6
0
 def test_add_new_worker(self):
     main_page = MainPage(self.driver)
     db_conn = DbConnect()
     fake_data = self.helpers.generate_fake_data()
     email = fake_data["email"]
     sql_query = """select "email" from "worker" where email='{}';""".format(
         email)
     self.login()
     main_page.press_add_new_worker()
     main_page.enter_email_address(email)
     main_page.press_search_emails()
     main_page.enter_first_name(fake_data["first_name"])
     main_page.enter_last_name(fake_data["last_name"])
     main_page.press_create_button()
     self.assertTrue(main_page.wait_for_confirm_message())
     query_response = db_conn.fetch_one(sql_query)
     self.assertIsNotNone(query_response)
示例#7
0
 def test_save_teams(self):
     db_conn = DbConnect()
     main_page = MainPage(self.driver)
     fake_data = self.helpers.generate_fake_data()
     team_name = fake_data["cert_name"]
     sql_query = '''select "name" from "team" where name='{}';'''.format(
         team_name)
     self.login()
     main_page.click_on_checkbox_next_to_worker(1)
     main_page.click_on_checkbox_next_to_worker(2)
     main_page.click_on_checkbox_next_to_worker(3)
     main_page.click_on_checkbox_next_to_worker(4)
     main_page.click_on_checkbox_next_to_worker(5)
     main_page.click_save_team_button()
     main_page.type_team_name_while_saving(team_name)
     main_page.click_save_button_while_saving_team()
     main_page.click_done_button()
     query_response = db_conn.fetch_one(sql_query)
     self.assertIsNotNone(query_response)
示例#8
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)
示例#9
0
 def __init__(self):
     self.api_helper = ApiHelper()
     self.db_conn = DbConnect()
     self.fake = Faker()
示例#10
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