Esempio n. 1
0
    def test_exist_domain(self):
        '''
        Kiểm tra response trả về khi không có trường domain

        Step by step:
        - Nhập các trường tương ứng
        - Gọi api
        - Kiểm tra response trả về

        Expect: code = shop_overlapped_name
        :return:
        '''
        payload1 = {
            'name': 'test54ẻtyu623',
            'domain': 'https://neqfsu.com',
            'activate': True,
            'activeInProductPrice': True
        }
        payload = {
            'name': 'test546232df13432',
            'domain': 'https://neqfsu.com',
            'activate': True,
            'activeInProductPrice': True
        }
        requests.post(url=url, json=payload1)
        response = requests.post(url=url, json=payload)
        result = response.json()
        # print(json.dumps(result))
        assert result['code'] == 'shop_overlapped_domain'
        record = DbConnectMysql().get_data_one(
            "select * from shops order by id desc;")
        DbConnectMysql().execute_query(
            f"DELETE FROM shops WHERE id = {record['id']};")
Esempio n. 2
0
 def test_exist_domain(self):
     '''
     <Update>Kiểm tra response trả về khi update không có trường domain
     Step by step:
     code = bad_request
     :return:
     '''
     payload = {
         'name': 'name',
         'domain': 'https://thuyhgy.com',
         'activeInProductPrice': True,
         'activate': random.choice([True, False]),
     }
     response = requests.post(url=url_list, json=payload)
     assert response.status_code == 200
     json = {
         'name': 'name1',
         'domain': 'https://thuyhgy.com',
         'activate': random.choice([True, False]),
         'activeInProductPrice': random.choice([True, False])
     }
     id = random.choice(get_id())
     response = requests.patch(url=url + str(id), json=json)
     result = response.json()
     assert response.status_code == 400
     assert result['code'] == 'shop_overlapped_domain'
     assert result[
         'message'] == "Shop domain https://thuyhgy.com has already been used"
     record = DbConnectMysql().get_data_one(
         "select * from shops order by id desc;")
     DbConnectMysql().execute_query(
         f"DELETE FROM shops WHERE id = {record['id']};")
Esempio n. 3
0
    def test_not_activeInProductPrice(self):
        '''
        Kiểm tra response trả về khi không có trường activeInProductPrice

        Step by step:
        - Nhập các trường tương ứng
        - Gọi api
        - Kiểm tra response trả về

        Expect: code = success
        :return:
        '''
        payload = {
            'name': 'test5ádfghj4623',
            'domain': 'https://nejjjqfsu.com',
            'activate': True
        }
        response = requests.post(url=url, json=payload)
        result = response.json()
        # print(json.dumps(result))
        assert result['code'] == 'success'
        record = DbConnectMysql().get_data_one(
            "select * from shops order by id desc;")
        DbConnectMysql().execute_query(
            f"DELETE FROM shops WHERE id = {record['id']};")
Esempio n. 4
0
    def test_validate(self, Title, Expected, name, domain, activate,
                      activateInProductPrice, code, message):
        f'''
        {Title}
        Step by step:
        Expect: {Expected}
        :return:
        '''
        # DbConnectMysql().execute_query("DELETE FROM shops;")
        payload = {
            'name': name,
            'domain': domain,
            'activate': activate,
            'activeInProductPrice': activateInProductPrice
        }
        # print(payload)
        response = requests.post(url=url, json=payload)
        result = response.json()
        print(json.dumps(result))
        assert result['code'] == code
        assert result['message'] == message

        if response.status_code == 200:
            record = DbConnectMysql().get_data_one(
                "select * from shops order by id desc;")
            DbConnectMysql().execute_query(
                f"DELETE FROM shops WHERE id = {record['id']};")
        else:
            assert response.status_code == 400
Esempio n. 5
0
 def teardown_class(self):
     print('teardown')
     DbConnectMysql().execute_query("delete from category_extractors ;")
     DbConnectMysql().execute_query("delete from product_extractors;")
     DbConnectMysql().execute_query(
         "delete from shops where name like 'thunt_qc%' or name like '%update extractor%';"
     )
Esempio n. 6
0
 def setup_class(self):
     print('setup')
     time = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
     for i in range(20):
         DbConnectMysql().execute_query(
             f"insert into shops (created_at, updated_at, name, domain, activate, active_in_product_price ) values ('{time}', '{time}', 'thunt_qc{i}', 'https://thunt-qc{i}.vn', {random.choice([0, 1])}, {random.choice([0, 1])});"
         )
Esempio n. 7
0
    def test_get_detail_success(self):
        '''
        <Detail>Kiểm tra xem detail của shop thành công
        Step by step:
        Expect: Status = 200
        :return:
        '''
        data = DbConnectMysql().get_data_one('select * from shops')
        print(data)
        id = data['id']
        response = requests.get(url=url + str(id))
        result = response.json()
        data = db.get_data_one(f"select * from shops where id = '{id}';")
        assert response.status_code == 200
        assert result['code'] == 'success'
        assert result['result']['id'] == id
        assert result['result']['name'] == data['name']
        assert result['result']['domain'] == data['domain']
        assert datetime.strptime(result['result']['createdAt'],
                                 '%Y-%m-%dT%H:%M:%S%z') == pytz.utc.localize(
                                     data['created_at'])
        assert datetime.strptime(result['result']['updatedAt'],
                                 '%Y-%m-%dT%H:%M:%S%z') == pytz.utc.localize(
                                     data['updated_at'])

        if data['activate'] == 0:
            assert result['result']['activate'] == False
        else:
            assert result['result']['activate'] == True
        if data['active_in_product_price'] == 0:
            assert result['result']['activeInProductPrice'] == False
        else:
            assert result['result']['activeInProductPrice'] == True
Esempio n. 8
0
    def test_update(self, Title, Expected, name, status_code, domain, code,
                    message):
        f'''
        {Title}
        Step by step:
        Expect: {Expected}
        :return:
        '''
        json = {
            'name': name,
            'domain': domain,
            'activate': random.choice([True, False]),
            'activeInProductPrice': random.choice([True, False])
        }

        id = random.choice(get_id())
        response = requests.patch(url=url + str(id), json=json)
        result = response.json()
        # data = db.get_data_one(f"select * from shops where id = '{id}';")
        assert response.status_code == status_code
        assert result['code'] == code
        assert result['message'] == message
        if response.status_code == 200:
            # record = DbConnectMysql().get_data_one("select * from shops order by id desc;")
            DbConnectMysql().execute_query(
                f"DELETE FROM shops WHERE id = {id};")
        else:
            assert response.status_code == 400
Esempio n. 9
0
 def test_valid(self):
     '''
     <Get_List>Kiểm tra response khi các trường hợp lệ
     Expect: status = 200
     :return:
     '''
     response = self.call_api_get_list(pageSize=10, page=1, q=None, orderBy=None, activate='all',
                                       activeInProductPrice='all')
     result = response.json()
     data = DbConnectMysql().get_data_all('select * FROM shops;')
     assert response.status_code == 200
     assert len(data) == result['result']['totalItems']
Esempio n. 10
0
 def test_not_exsit_shop_id(self):
     '''
     <Detail>Kiểm tra response khi shop_id không có trong db
     Step by step:
     Expect: Status = 404
     :return:
     '''
     data = DbConnectMysql().get_data_one('select * from shops')
     id = data['id'] + 1
     response = requests.get(url=url + str(id))
     result = response.json()
     assert response.status_code == 404
     assert result['code'] == 'shop_not_found'
Esempio n. 11
0
 def test_pageSize_1(self):
     '''
     <Get_List>Kiểm tra response khi pageSize = 1
     Expect: status = 200
     :return:
     '''
     response = self.call_api_get_list(pageSize=1, page=1, q=None, orderBy=None, activate='all',
                                       activeInProductPrice='all')
     result = response.json()
     data = DbConnectMysql().get_data_one('select * FROM shops order by id desc ;')
     assert response.status_code == 200
     assert len(result['result']['results']) == 1
     assert result['result']['results'][0]['id'] == data['id']
     assert result['result']['results'][0]['name'] == data['name']
     assert result['result']['results'][0]['domain'] == data['domain']
Esempio n. 12
0
 def test_activeInProductPrice_null(self):
     '''
     <Get_List>Kiểm tra response khi activeInProductPrice = null
     Expect: status = 200
     :return:
     '''
     response = self.call_api_get_list(pageSize=10, page=1, q=None, orderBy=None, activate=None,
                                       activeInProductPrice=None)
     result = response.json()
     data = DbConnectMysql().get_data_all('select * FROM shops order by id desc ;')
     assert response.status_code == 200
     # assert len(result['result']['results']) == 10
     for i in range(len(result['result']['results'])):
         assert result['result']['results'][i]['id'] == data[i]['id']
         assert result['result']['results'][i]['name'] == data[i]['name']
         assert result['result']['results'][i]['domain'] == data[i]['domain']
Esempio n. 13
0
    def test_not_domain(self):
        '''
        <Update>Kiểm tra response trả về khi update không có trường domain
        Step by step:
        code = bad_request
        :return:
        '''

        json = {
            'name': 'name',
            # 'domain': 'http://domain.vn',
            'activate': random.choice([True, False]),
            'activeInProductPrice': random.choice([True, False])
        }
        id = random.choice(get_id())
        response = requests.patch(url=url + str(id), json=json)
        result = response.json()
        assert response.status_code == 200
        assert result['code'] == 'success'
        assert result['message'] == "Updated shop successful"
        DbConnectMysql().execute_query(f"DELETE FROM shops WHERE id = {id};")
Esempio n. 14
0
 def test_not_orderBy(self):
     '''
     <Get_List>Kiểm tra response khi không nhập orderBy
     Expect: status = 200
     :return:
     '''
     params1 = {
         'pageSize': 10,
         'page': 1,
         'q': None,
         # 'orderBy': None,
         'activate': 'all',
         'activeInProductPrice': 'all'
     }
     response = requests.get(url=url_list, params=params1)
     result = response.json()
     data = DbConnectMysql().get_data_all('select * FROM shops order by id desc ;')
     assert response.status_code == 200
     # assert len(result['result']['results']) == 10
     for i in range(len(result['result']['results'])):
         assert result['result']['results'][i]['id'] == data[i]['id']
         assert result['result']['results'][i]['name'] == data[i]['name']
         assert result['result']['results'][i]['domain'] == data[i]['domain']
Esempio n. 15
0
 def teardown_class(self):
     print('teardown')
     DbConnectMysql().execute_query("delete from shops where name like 'thunt_qc%';")
Esempio n. 16
0
 def setup_class(self):
     DbConnectMysql().execute_query("DELETE FROM shops;")
Esempio n. 17
0
from datetime import datetime
import random
from settings import PCR_URL_SHOP
import requests
from support.db.db_connection import DbConnectMysql
db = DbConnectMysql()

url_list = PCR_URL_SHOP + 'shops'
url = PCR_URL_SHOP + 'shops/'

def get_id():
    shop_id = []
    shop_list = db.get_data_all('select * from shops;')
    for i in range(len(shop_list)):
        shop_id.append(shop_list[i]['id'])
    return shop_id


class TestPCR29List:
    ISSUE_KEY = 'PCR-8'
    FOLDER = '/QC/API/Danh sách cửa hàng'

    def setup_class(self):
        print('setup')
        time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        for i in range(20):
            DbConnectMysql().execute_query(
                f"insert into shops (created_at, updated_at, name, domain, activate, active_in_product_price ) values ('{time}', '{time}', 'thunt_qc{i}', 'https://thunt_qc{i}.vn', {random.choice([0, 1])}, {random.choice([0, 1])});")

    def teardown_class(self):
        print('teardown')
Esempio n. 18
0
 def teardown_class(self):
     print('teardown')
     data = DbConnectMysql().get_data_one('select * from shops;')
     DbConnectMysql().execute_query(
         f"delete from shops where id = {data['id']};")