class TestCase95DevManageBatchSaleByNoDev(unittest.TestCase):
    def setUp(self):
        self.driver = AutomateDriver()
        self.base_url = self.driver.base_url
        self.base_page = BasePage(self.driver, self.base_url)
        self.dev_manage_page = DevManagePages(self.driver, self.base_url)
        self.driver.set_window_max()
        self.log_in_base = LogInBase(self.driver, self.base_url)
        self.dev_manage_page_read_csv = DevManagePageReadCsv()
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.assert_text = AssertText()
        self.driver.wait(1)

    def tearDown(self):
        self.driver.quit_browser()

    def test_case_dev_manage_batch_sale_by_no_dev(self):
        # 打开途强在线首页-登录页
        self.base_page.open_page()
        self.log_in_base.log_in()
        # 点击进入设备管理
        self.dev_manage_page.enter_dev_manage()
        # 点击批量
        self.dev_manage_page.click_batch_sale_button()
        self.dev_manage_page.click_close_batch_sale_button()
        self.dev_manage_page.click_batch_sale_button()
        # 验证界面
        get_sale_title = self.dev_manage_page.get_sale_title_text_in_sale_dev()
        self.assertEqual(self.assert_text.batch_sale_text(), get_sale_title)

        # 搜索框输入多个设备IMEI,点击添加(设备之间用enter键、逗号隔开)
        self.dev_manage_page.add_imei_in_sale_dev_page(
            '121201234567889,867597011453591')
        get_dev_in_list_number = self.dev_manage_page.get_dev_in_list_number()
        self.assertEqual(2, get_dev_in_list_number)

        # 搜索框输入多个设备IMEI,点击添加(设备之间不用enter键、逗号隔开,而用空格隔开)
        self.dev_manage_page.add_imei_in_sale_dev_page(
            '121201234567889867597011453591')
        add_dev_state = self.dev_manage_page.add_dev_after_fail_state()
        self.assertEqual(self.assert_text.dev_page_fail_text(), add_dev_state)
        add_dev_reason = self.dev_manage_page.add_dev_after_fail_reason()
        self.assertEqual(self.assert_text.dev_page_inexistence_text(),
                         add_dev_reason)
        self.dev_manage_page.click_close_fails()

        # 不选择销售对象进行销售
        self.dev_manage_page.click_sale_button()
        # text = self.dev_manage_page.get_error_text_after_ensure()
        # self.assertEqual(self.assert_text.glob_search_please_add_account_text(), text)

        # 点击重置的按钮
        self.dev_manage_page.click_clear_button_in_dev_sale()
        get_dev_in_list_number = self.dev_manage_page.get_dev_in_list_number()
        self.assertEqual(0, get_dev_in_list_number)
class TestCase94DevManageBatchSaleByMoreDev(unittest.TestCase):
    def setUp(self):
        self.driver = AutomateDriver()
        self.base_url = self.driver.base_url
        self.base_page = BasePage(self.driver, self.base_url)
        self.dev_manage_page = DevManagePages(self.driver, self.base_url)
        self.driver.set_window_max()
        self.log_in_base = LogInBase(self.driver, self.base_url)
        self.dev_manage_page_read_csv = DevManagePageReadCsv()
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.assert_text = AssertText()
        self.driver.wait(1)

    def tearDown(self):
        self.driver.quit_browser()

    def test_case_dev_manage_batch_sale_by_more_dev(self):
        # 打开途强在线首页-登录页
        self.base_page.open_page()
        self.log_in_base.log_in()
        # 点击进入设备管理
        self.dev_manage_page.enter_dev_manage()
        # 选择多个设备点击批量销售
        self.dev_manage_page.choose_one_dev_to_search()
        self.dev_manage_page.choose_more_dev_to_search()
        # 点击批量
        self.dev_manage_page.click_batch_sale_button()
        self.dev_manage_page.click_close_batch_sale_button()
        self.dev_manage_page.click_batch_sale_button()
        # 验证界面
        get_sale_title = self.dev_manage_page.get_sale_title_text_in_sale_dev()
        self.assertEqual(self.assert_text.batch_sale_text(), get_sale_title)

        # 获取统计的数量和列表中的总数
        get_dev_number = self.dev_manage_page.get_dev_number_in_sale_dev()
        get_dev_in_list_number = self.dev_manage_page.get_dev_in_list_number()
        self.assertEqual(get_dev_number, str(get_dev_in_list_number))

        # 删除一个设备列表已添加的设备
        self.dev_manage_page.delete_one_dev_in_dev_list()
        get_dev_number = self.dev_manage_page.get_dev_number_in_sale_dev()
        get_dev_in_list_number = self.dev_manage_page.get_dev_in_list_number()
        self.assertEqual(get_dev_number, str(get_dev_in_list_number))

        # 输入所选账号下存在的未添加到已选设备列表的设备和已添加到已选设备列表的设备以及不存在的设备,121201234567889
        self.dev_manage_page.add_imei_in_sale_dev_page('121201234567889')
        sleep(2)
        get_dev_number = self.dev_manage_page.get_dev_number_in_sale_dev()
        get_dev_in_list_number = self.dev_manage_page.get_dev_in_list_number()
        self.assertEqual(get_dev_number, str(get_dev_in_list_number))

        # 删除一个设备列表已添加的设备后再添加该设备
        self.dev_manage_page.delete_one_devs_in_dev_list()
        get_dev_number = self.dev_manage_page.get_dev_number_in_sale_dev()
        get_dev_in_list_number = self.dev_manage_page.get_dev_in_list_number()
        self.assertEqual(get_dev_number, str(get_dev_in_list_number))

        self.dev_manage_page.add_imei_in_sale_dev_page('121201234567889')
        sleep(2)
        get_dev_number = self.dev_manage_page.get_dev_number_in_sale_dev()
        get_dev_in_list_number = self.dev_manage_page.get_dev_in_list_number()
        self.assertEqual(get_dev_number, str(get_dev_in_list_number))
class TestCase82DevManageBatchSale(unittest.TestCase):
    def setUp(self):
        self.driver = AutomateDriver()
        self.base_url = self.driver.base_url
        self.base_page = BasePage(self.driver, self.base_url)
        self.dev_manage_page = DevManagePages(self.driver, self.base_url)
        self.driver.set_window_max()
        self.log_in_base = LogInBase(self.driver, self.base_url)
        self.dev_manage_page_read_csv = DevManagePageReadCsv()
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.assert_text = AssertText()
        self.driver.wait(1)

    def tearDown(self):
        self.driver.quit_browser()

    def test_case_dev_manage_batch_sale(self):
        # 打开途强在线首页-登录页
        self.base_page.open_page()
        self.log_in_base.log_in()
        # 点击进入设备管理
        self.dev_manage_page.enter_dev_manage()
        # 选择一个设备点击批量销售
        self.dev_manage_page.choose_one_dev_to_search()
        get_first_imei = self.dev_manage_page.get_first_imei_in_list()
        get_dev_type = self.dev_manage_page.get_dev_type_in_list()
        # 点击批量
        self.dev_manage_page.click_batch_sale_button()
        self.dev_manage_page.click_close_batch_sale_button()
        self.dev_manage_page.click_batch_sale_button()

        '''# 搜索右侧客户树
        # 循环点击5次
        for n in range(5):
            self.driver.click_element('x,//*[@id="treeDemo_device_sale_id_%s_span"]' % str(n + 1))
            sleep(2)
            # 判断数量
            get_account_dev_number = self.driver.get_text('x,//*[@id="treeDemo_device_sale_id_%s_span"]' % str(n + 1))

            name = self.dev_manage_page.get_select_account_name()
            self.assertEqual(get_account_dev_number, name)

        # 搜索无数据
        self.dev_manage_page.search_customer_after_click_batch_sale_dev('无数据')
        get_text = self.dev_manage_page.get_search_customer_no_data_text_after_batch_sale_dev()
        self.assertIn(self.assert_text.account_center_page_no_data_text(), get_text)

        # 获取选中设备的数量
        dev_number = self.dev_manage_page.get_select_dev_number()

        # 获取抬头设备统计的数量
        dev_numbers_count = self.dev_manage_page.get_dev_numbers()
        self.assertEqual(str(dev_number), dev_numbers_count)'''

        # 验证界面
        get_sale_title = self.dev_manage_page.get_sale_title_text_in_sale_dev()
        self.assertEqual(self.assert_text.batch_sale_text(), get_sale_title)

        get_imei_in_sale = self.dev_manage_page.get_batch_sale_imei_in_sale_dev()
        self.assertEqual(get_first_imei, get_imei_in_sale)

        get_dev_type_in_sale = self.dev_manage_page.get_dev_type_in_sale()
        self.assertEqual(get_dev_type, get_dev_type_in_sale)

        get_dev_number = self.dev_manage_page.get_dev_number_in_sale_dev()
        self.assertEqual('1', get_dev_number)

        get_dev_account = self.dev_manage_page.get_dev_account_name()
        connect_sql = ConnectSql()
        connect = connect_sql.connect_tuqiang_sql()
        cursor = connect.cursor()
        sql = "select m.account from equipment_mostly m where m.imei = '%s';" % get_first_imei
        cursor.execute(sql)
        data = cursor.fetchall()
        cursor.close()
        connect.close()

        sql_account = data[0][0]
        self.assertEqual(get_dev_account, sql_account)

        # 输入不存在的IMEI号进行添加
        self.dev_manage_page.add_imei_in_sale_dev_page('bucunzai')

        add_dev_state = self.dev_manage_page.add_dev_after_fail_state()
        self.assertEqual(self.assert_text.dev_page_fail_text(), add_dev_state)
        add_dev_reason = self.dev_manage_page.add_dev_after_fail_reason()
        self.assertEqual(self.assert_text.dev_page_inexistence_text(), add_dev_reason)
        self.dev_manage_page.click_close_fails()
        # 添加不属于当前登陆账号设备总进货数中的设备
        self.dev_manage_page.add_imei_in_sale_dev_page('863666010079196')

        add_dev_state = self.dev_manage_page.add_dev_after_fail_state()
        self.assertEqual(self.assert_text.dev_page_fail_text(), add_dev_state)
        add_dev_reason = self.dev_manage_page.add_dev_after_fail_reason()
        self.assertEqual(self.assert_text.dev_page_inexistence_text(), add_dev_reason)
        self.dev_manage_page.click_close_fails()
        # 添加与设备列表中重复的设备
        self.dev_manage_page.add_imei_in_sale_dev_page(get_first_imei)

        add_dev_state = self.dev_manage_page.add_dev_after_fail_state()
        self.assertEqual(self.assert_text.dev_page_fail_text(), add_dev_state)
        add_dev_reason = self.dev_manage_page.add_dev_after_fail_reason()
        self.assertEqual(self.assert_text.dev_page_repetition_text(), add_dev_reason)
        self.dev_manage_page.click_close_fails()

        # 搜索右侧客户树
        # 循环点击5次
        for n in range(5):
            self.driver.click_element('x,//*[@id="treeDemo_device_sale_id_%s_span"]' % str(n + 1))
            sleep(2)
            # 判断数量
            get_account_dev_number = self.driver.get_text('x,//*[@id="treeDemo_device_sale_id_%s_span"]' % str(n + 1))

            name = self.dev_manage_page.get_select_account_name()
            self.assertEqual(get_account_dev_number, name)

        # 搜索无数据
        self.dev_manage_page.search_customer_after_click_batch_sale_dev('无数据')
        get_text = self.dev_manage_page.get_search_customer_no_data_text_after_batch_sale_dev()
        self.assertIn(self.assert_text.account_center_page_no_data_text(), get_text)

        # 获取选中设备的数量
        dev_number = self.dev_manage_page.get_select_dev_number()

        # 获取抬头设备统计的数量
        dev_numbers_count = self.dev_manage_page.get_dev_numbers()
        self.assertEqual(str(dev_number), dev_numbers_count)