예제 #1
0
    def test_send_raw_to_validator(self, KAFKAjson, KAFKAjson2):

        allure.description('Testing send raw json to validator topic')
        allure.label('kafka operations')

        d1 = nistest.KafkaDriver(topic=config.get('kafka_topic_raw'),
                                 server=config.get('kafka_server'),
                                 schema_registry=config.get('kafka_schema'))

        offset1 = d1.get_last_offset()
        rawData = {
            "producer": "test",
            "sessionKey": "123e4567-e89b-12d3-a456-426655440002",
            "termId": 123,
            "protocolId": 1,
            "deviceTypeId": 100,
            "timePlatformFrom1970": 1527601137000,
            "timeDeviceFrom1970": 1527601137000,
            "activityInfo": 1
        }

        rawData = json.dumps(rawData, sort_keys=True).encode('utf-8')
        last_offset = d1.get_last_offset()
        d1.send(msg=rawData, lang='json', schema=None)

        res = d1.read_from_offset(offset1)
        result = d1.read_from_offset(offset=last_offset,
                                     lang='json',
                                     schema=None)

        log.debug('result: ' + str(result))
        assert rawData == result
        res_delete = d1.delete_topic()
        assert res_delete == 0
예제 #2
0
    def test_get_history(self, HDS, KAFKAavro):
        '''

        Create device test

        Send http request to read history

        '''
        allure.description('Testing hds get history')
        '''
        -----------------------------------------------------------------------------
        send message
        -----------------------------------------------------------------------------
        '''

        startTime = '2018-06-20T09:08:28+03:00'
        endTime = '2018-07-29T09:08:28+03:00'
        dateFrom = '2018-06-27T09:08:28+03:00'
        dateTo = '2018-06-27T09:08:28+03:00'

        log.debug('[test_get_history] dateFrom: ' + str(dateFrom))
        device_v_term_id = random.randint(1, 100000)

        filter = 'null'
        limit = 1
        sort = 'asc'
        device_activity_info = random.randint(1, 100000)

        expected = []

        for tim in range(2):

            device_time_device = 1530523171000 + 1000 * tim
            device_time_device_utc = datetime.fromtimestamp(
                int(device_time_device / 1000)).strftime('%Y-%m-%dT%H:%M:%SZ')

            expected_dict = {}
            expected_dict['activityInfo'] = device_activity_info
            expected_dict['termId'] = device_v_term_id
            expected_dict['timeDevice'] = device_time_device_utc
            expected.append(expected_dict)
            KAFKAavro.send_valid(termId=device_v_term_id,
                                 time_platform=device_time_device,
                                 time_device=device_time_device,
                                 activity_info=device_activity_info)
        '''
        -----------------------------------------------------------------------------
        get history
        -----------------------------------------------------------------------------
        '''

        response = HDS.get_history(expected=expected,
                                   termId=device_v_term_id,
                                   limit=None,
                                   sort='asc',
                                   filter=None,
                                   startTime=startTime,
                                   endTime=endTime,
                                   dateFrom=dateFrom,
                                   dateTo=dateTo)
    def test_validator_processing_message_new(self, ServiceObjKAFKAavro):
        allure.description('Testing validator processing message new')
        allure.label('validator operations')

        startTime = '2018-06-20T09:08:28+03:00'
        endTime = '2018-07-29T09:08:28+03:00'
        dateFrom = '2018-07-02T09:19:32+03:00'
        dateTo = '2018-07-02T09:19:32+03:00'

        log.debug('[test_get_history] dateFrom: ' + str(dateFrom))
        device_v_term_id = random.randint(1, 100000)
        filter = 'null'
        limit = 1
        sort = 'asc'

        expected = []

        for time in range(2):

            device_activity_info = random.randint(1, 100000)
            device_time_device = 1530523171000 + 1000 * time
            device_time_device_utc = datetime.fromtimestamp(
                int(device_time_device / 1000)).strftime('%Y-%m-%dT%H:%M:%SZ')

            ServiceObjKAFKAavro.send_valid(termId=device_v_term_id,
                                           time_platform=device_time_device,
                                           time_device=device_time_device,
                                           activity_info=device_activity_info)
예제 #4
0
    def test_get_history_hide_interval(self, HDS, KAFKAavro, DBHistory):
        '''

        Create device test

        Send http request to read history

        '''
        allure.description('Test get history hide interval')
        '''
        -----------------------------------------------------------------------------
        send message
        -----------------------------------------------------------------------------
        '''

        device_v_term_id = random.randint(1, 100000)
        filter = 'null'
        limit = 1
        sort = 'asc'
        device_activity_info = random.randint(1, 100)

        for t in range(5):

            device_activity_info += 1
            device_time_device = datetime.strptime(
                '2018-07-02 09:19:3' + str(t),
                "%Y-%m-%d %H:%M:%S").strftime('%s000')
            KAFKAavro.send_valid(termId=device_v_term_id,
                                 time_platform=int(device_time_device),
                                 time_device=int(device_time_device),
                                 activity_info=device_activity_info)
        '''
        -----------------------------------------------------------------------------
        get history
        -----------------------------------------------------------------------------
        '''

        startTime = '2018-06-20T09:08:28+03:00'
        endTime = '2018-07-29T09:08:28+03:00'
        dateFrom = '2018-07-02T09:19:30+03:00'
        dateTo = '2018-07-02T09:19:33+03:00'
        device_time_device_utc = '2018-07-02T09:19:34Z'

        expected = [{
            "activityInfo": device_activity_info,
            "termId": device_v_term_id,
            "timeDevice": device_time_device_utc
        }]

        response = HDS.get_history(expected=expected,
                                   termId=device_v_term_id,
                                   limit=None,
                                   sort='asc',
                                   filter=None,
                                   startTime=startTime,
                                   endTime=endTime,
                                   dateFrom=dateFrom,
                                   dateTo=dateTo)
예제 #5
0
    def test_create_kafka(self):

        allure.description('Testing create topic')
        allure.label('kafka operations')
        log.debug('start test_kafka')

        d1 = nistest.KafkaDriver(topic=config.get('kafka_topic_raw'))
        res_create = d1.create_topic('testtopic2')
        assert res_create == None
예제 #6
0
    def test_invalid_auth(self, HDS):
        '''

        Create device test

        Send http request to read history

        '''
        allure.description('Testing hds http 400 invalid json')
        '''
        -----------------------------------------------------------------------------
        send message
        -----------------------------------------------------------------------------
        '''

        startTime = '2018-06-20T09:08:28+03:00'
        endTime = '2018-07-29T09:08:28+03:00'
        dateFrom = '2018-06-27T09:08:28+03:00'
        dateTo = '2018-06-27T09:08:28+03:00'

        termId = '1'
        filter = '1'
        limit = 1
        sort = 'asc'
        device_activity_info = random.randint(1, 100000)

        params = 'termId={0}&filter={1}&limit={2}&sort={3}'.format(
            str(termId), str(filter), str(limit), str(sort))

        payload = '''{
          "startTime": ''' + str(startTime) + ''',
          "endTime": ''' + str(endTime) + ''',
          "hideTimes": [
             { "from": ''' + str(dateFrom) + ''', "to": ''' + str(
            dateTo) + '''}
          ]
        '''

        HDS.service.authorise.set('pwd', '123')

        headers = {
            'Authorization': str(HDS.service.authorise.get_basic_auth()),
            'Content-Type': 'application/json'
        }

        response = HDS.service.request(
            method='get_history',
            path=HDS.service.paths.get('get_history') + str(params),
            payload=payload,
            headers=headers)
        assert response.status_code == 400
        assert response.text == 'absent header x-sender'
예제 #7
0
    def test_send_raw_to_validator_new(self, KAFKAjson, KAFKAjson2):
        allure.description('Testing send raw json to validator topic')
        allure.label('kafka operations')
        device_time_device = 1530523171000
        device_time_device_utc = datetime.fromtimestamp(
            int(device_time_device / 1000)).strftime('%Y-%m-%dT%H:%M:%SZ')

        KAFKAjson.send_raw(termId=100,
                           protocolId=200,
                           deviceTypeId=100,
                           timePlatformFrom1970=device_time_device,
                           timeDeviceFrom1970=device_time_device,
                           activityInfo=300)
예제 #8
0
 def test_login(self, listcases):
     '''
     登录成功的用例
     :param listcases:
     :return: None
     '''
     allure.dynamic.title(listcases['title'])
     allure.description(listcases['description'])  #添加描述
     testcases = listcases['cases']
     for cases in testcases:
         listcase = list(cases.values())
         with allure.step(listcase[0]):  #用例执行步骤
             func = getattr(self.web, listcase[1])
             values = listcase[2:]
             func(*values)
    def test_login_plus(self, list_cases):
        """
        数据驱动方式
        执行登录
        :return: None
        """

        allure.dynamic.title(list_cases['title'])
        allure.description(list_cases['description'])
        login_case = list_cases['cases']
        for cases in login_case:
            list_case = list(cases.values())
            with allure.step(list_case[0]):
                function = getattr(self.web, list_case[1])
                values = list_case[2:]
                function(*values)
예제 #10
0
    def test_create_device(self, DB):
        '''

        Create device test

        Send http request to create device

        '''

        allure.description('Testing info get device')
        expected_list = {'v_device_type': 'hub'}
        response = DB.create_device(p_device_type='hub',
                                    p_model='OVI-BOVI',
                                    p_hub_id=0,
                                    p_sensor_id=101)
        ids = response.get('v_term_id')
        log.debug('ids: ' + str(ids))
예제 #11
0
 def test_excel_case(self, mokuai, case_name, url, data_method, data,
                     result_method, result):
     # print(mokuai, case_name, url, data_method, data, result_method, result)
     # 应该再封装一个base, case层调用base的方法即可
     allure.description(mokuai + " " + case_name)
     if data_method == 'get':
         response = requests.get(url).json()
     elif data_method == 'post':
         # 格式化请求数据, 发送post请求
         params = data
         response = requests.post(url, data=params)
     else:
         raise TypeError("暂不支持此类型请求")
     if result_method == '包含':
         assert result in response
     elif result_method == '等于':
         assert result == response
예제 #12
0
    def test_get_history_empty_term_id(self, HDS, KAFKAavro):
        '''

        Create device test

        Send http request to read history

        '''
        allure.description('Testing hds get history')
        '''
        -----------------------------------------------------------------------------
        send message
        -----------------------------------------------------------------------------
        '''

        startTime = '2018-06-20T09:08:28+03:00'
        endTime = '2018-07-29T09:08:28+03:00'
        dateFrom = '2018-06-27T09:08:28+03:00'
        dateTo = '2018-06-27T09:08:28+03:00'
        '''
        -----------------------------------------------------------------------------
        get history
        -----------------------------------------------------------------------------
        '''

        response = HDS.get_history(expected=None,
                                   termId=None,
                                   limit=None,
                                   sort='asc',
                                   filter=None,
                                   startTime=startTime,
                                   endTime=endTime,
                                   dateFrom=dateFrom,
                                   dateTo=dateTo,
                                   no_check=True)
        assert response.status_code == 400
        expected = {
            "developerMessage": "Required query parameter in URI 'termId'",
            "errorCode": 1,
            "errorMessage": "Required query parameter in URI 'termId'"
        }
        assert nistest.basic.CompareDriver(data_result=response.json(),
                                           data_expected=expected,
                                           lang='json',
                                           dump=False)
예제 #13
0
    def test_create_device(self, DRS):
        '''

        Create device test

        Send http request to create device

        '''

        allure.description('Testing drs creating device')

        devicetype = 'ovibovi'
        model = 'OVI-BOVI'
        hubId = 0

        device2 = DRS.create_device(deviceType=devicetype,
                                    model=model,
                                    hubId=hubId,
                                    sensorId=random.randint(1, 100000))
예제 #14
0
    def test_create_device_raw(self, DRS):
        '''

        Create device test

        Send http request to create device

        '''

        allure.description('Testing drs creating device from raw')

        json_data = {
            "deviceType": 'ovibovi',
            "model": 'OVI-BOVI',
            "hubId": 0,
            "sensorId": random.randint(1, 100000)
        }

        DRS.create_device_raw(payload=json_data)
예제 #15
0
    def test_create_device_set_and_check_status(self, DB):
        '''

        Create device test

        Send http request to create device, set and check status

        '''

        allure.description('Testing info set status')
        expected_list = {'v_device_type': 'hub'}
        response = DB.create_device(p_device_type='hub',
                                    p_model='OVI-BOVI',
                                    p_hub_id=0,
                                    p_sensor_id=1010)
        ids = response.get('v_term_id')
        DB.set_status(p_term_id=ids, p_status_id=3)
        expected_list = {'v_status_id': '3'}
        response = DB.get_device(expected_list=expected_list, p_term_id=ids)
예제 #16
0
 def test_db_interface(self, name, describe, url, request_data, method,
                       except_desc, except_content):
     allure.description(name + " " + describe)
     if method == 'get':
         response = requests.get(url).text
         # print(response)
     elif method == 'post':
         # 格式化请求数据, 发送post请求
         params = request_data
         response = requests.post(url, data=params).text
     else:
         raise TypeError("暂不支持此类型请求")
     print(except_desc)
     if except_desc == 'contains':
         assert except_content in response
     elif except_desc == 'equal':
         assert except_content == response
     else:
         assert False is True
예제 #17
0
    def test_create_and_delete_device(self, DRS):
        '''

        Create and delete device test

        Send http request to create and then delete device

        '''

        allure.description('Testing drs creating and delete device')

        deviceType = 'ovibovi'
        model = 'OVI-BOVI'
        hubId = 0

        device = DRS.create_device(deviceType=deviceType,
                                   model=model,
                                   hubId=hubId,
                                   sensorId=random.randint(1, 100000))
        DRS.delete_device(device=device)
        device = DRS.get_device(termId=device.termId)
예제 #18
0
 def test_add_monitor(self, add_monitor):
     """
     测试添加监测设备(传感器)
     :param add_monitor:
     :return:
     """
     allure.dynamic.title(add_monitor["title"])  # 动态获取yaml中的title
     allure.description(add_monitor["description"])  # 用例描述
     test_cases = add_monitor["cases"]
     for cases in test_cases:
         list_case = list(cases.values())
         with allure.step(list_case[0]):  # 0在yaml文件中为name字段;1为方法名称;2为方法参数
             func = getattr(self.base_action, list_case[1])
             values = list_case[2:]
             try:
                 func(*values)
             except Exception as e:
                 png = self.base_action.driver.get_screenshot_as_png()
                 name = time.strftime('%Y-%m-%d %H:%M:%S')+list_case[0]
                 allure.attach(png, name, allure.attachment_type.PNG)
                 raise e
예제 #19
0
 def test_add_nvr(self, add_nvr):
     """
     测试添加NVR
     :param add_nvr:
     :return:
     """
     allure.dynamic.title(add_nvr["title"])
     allure.description(add_nvr["description"])
     test_cases = add_nvr["cases"]
     for cases in test_cases:
         list_case = list(cases.values())
         with allure.step(list_case[0]):
             func = getattr(self.base_action, list_case[1])
             values = list_case[2:]
             try:
                 func(*values)
             except Exception as e:
                 png = self.base_action.driver.get_screenshot_as_png()
                 name = time.strftime('%Y-%m-%d %H:%M:%S')+list_case[0]
                 allure.attach(png, name, allure.attachment_type.PNG)
                 raise e
예제 #20
0
    def test_send_to_validator(self, KAFKAavro, HDS):
        '''

        Create device test

        Send http request to read history

        '''
        allure.description('Testing hds send to validator')
        '''
        -----------------------------------------------------------------------------
        send message
        -----------------------------------------------------------------------------
        '''

        startTime = '2018-06-20T09:08:28+03:00'
        endTime = '2018-07-29T09:08:28+03:00'
        dateFrom = '2018-07-02T09:19:32+03:00'
        dateTo = '2018-07-02T09:19:32+03:00'

        log.debug('[test_get_history] dateFrom: ' + str(dateFrom))
        device_v_term_id = random.randint(1, 100000)
        filter = 'null'
        limit = 1
        sort = 'asc'

        expected = []

        for tim in range(2):

            device_activity_info = random.randint(1, 100000)
            device_time_device = 1530523171000 + 1000 * tim
            device_time_device_utc = datetime.fromtimestamp(
                int(device_time_device / 1000)).strftime('%Y-%m-%dT%H:%M:%SZ')

            KAFKAavro.send_valid(termId=device_v_term_id,
                                 time_platform=device_time_device,
                                 time_device=device_time_device,
                                 activity_info=device_activity_info)
예제 #21
0
    def test_create_device_if_exist(self, DB):
        '''

        Create device test

        Send http request to create device

        '''

        allure.description('Testing info get device')
        expected_list = {'v_device_type': 'hub'}
        response = DB.create_device(p_device_type='hub',
                                    p_model='OVI-BOVI',
                                    p_hub_id=0,
                                    p_sensor_id=102)
        ids = response.get('v_term_id')
        log.debug('ids: ' + str(ids))
        with pytest.raises(sqlalchemy.exc.InternalError) as excinfo:
            response = DB.create_device(p_device_type='hub',
                                        p_model='OVI-BOVI',
                                        p_hub_id=0,
                                        p_sensor_id=102)
            log.debug('response: ' + str(response))
            log.debug('excinfo: ' + str(excinfo))
예제 #22
0
    def test_create_device_if_exist(self, DRS):
        '''

        Create device test

        Send http request to create device if exist

        '''

        allure.description('Testing drs creating device if exist')

        deviceType = 'ovibovi'
        model = 'OVI-BOVI'
        hubId = 0
        sensorId = random.randint(1, 100000000)

        device = DRS.create_device(deviceType=deviceType,
                                   model=model,
                                   hubId=hubId,
                                   sensorId=sensorId)

        device2 = DRS.create_device(deviceType=deviceType,
                                    model=model,
                                    hubId=hubId,
                                    sensorId=sensorId,
                                    no_check=True)
        assert device2.response.status_code == 400, 'response: ' + str(
            device2.response.text)

        expected_response = {
            "developerMessage": "Can't registrate terminal",
            "errorCode": 1,
            "errorMessage": "Can't registrate terminal"
        }
        assert device2.response.json(
        ) == expected_response, 'response: ' + str(device2.resp.text)
# -*- coding: utf-8 -*-
import pytest
from requests import Response
from rest_framework.status import HTTP_200_OK

import allure
from directory_tests_shared import URLs
from tests.smoke.cms_api_helpers import get_and_assert, status_error

pytestmark = [
    allure.suite("HttpOnly Cookie flag"),
    allure.feature("HttpOnly Cookie flag"),
    allure.description(
        "The HttpOnly flag should be set by including this attribute within "
        "the relevant Set-cookie directive. Alternatively, URL rewriting could be used,"
        " as is detailed in the following example"
    ),
]

USER_AGENT = {"user-agent": "automated smoke tests"}


@allure.step("Assert that HttpOnly Cookie flag is set")
def assert_httponly_cookie_flag_is_set(response: Response):
    without_httponly = {
        c.name: c.__dict__
        for c in response.cookies
        if not c.has_nonstandard_attr("HttpOnly")
    }
    error = (
        f"Following cookies on {response.url} are set without 'HttpOnly' flag: "
예제 #24
0
    def test_create_device_by_db_read_history(self, KAFKAavro, KAFKAchanged, KAFKAjson, DRS, HDS, INFO, DB, DBHistory):

        '''

        Create device test

        Send http request to create device

        '''

        allure.description('Testing e2e creating device and read history')


        '''
        -----------------------------------------------------------------------------
        prepare kafka
        -----------------------------------------------------------------------------        
        '''

        KAFKAjson.service.delete_topic()

        '''
        -----------------------------------------------------------------------------
        create device
        -----------------------------------------------------------------------------
        
        '''
        device_v_device_type = 'hub'
        device_v_model = 'OVI-BOVI'
        hubId = 0
        device_sensorId = random.randint(1, 100000)

        response = DB.create_device(p_device_type=device_v_device_type, p_model=device_v_model, p_hub_id=hubId,
                                         p_sensor_id=device_sensorId)

        device_v_term_id = response.get('v_term_id')
        device_v_protocol_family_id = response.get('v_protocol_family_id')
        device_v_status_id = response.get('v_status_id')
        device_activity_info = 1

        '''
        -----------------------------------------------------------------------------
        check device in db
        -----------------------------------------------------------------------------
        '''
        expected = {'v_status_id': '2'}
        response = DB.get_device(expected=expected, p_term_id=device_v_term_id)


        '''
        -----------------------------------------------------------------------------
        change status
        -----------------------------------------------------------------------------
        '''

        response = DB.set_status(p_term_id=device_v_term_id, p_status_id = 3)

        '''
        -----------------------------------------------------------------------------
        send raw
        -----------------------------------------------------------------------------
        '''
        device_time_device = 1530523171000
        device_time_device_utc = datetime.fromtimestamp(int(device_time_device/1000)).strftime('%Y-%m-%dT%H:%M:%SZ')

        KAFKAjson.send_raw(termId=device_v_term_id, protocolId=device_v_protocol_family_id, deviceTypeId=100,
                                 timePlatformFrom1970=device_time_device, timeDeviceFrom1970=device_time_device, activityInfo=device_activity_info)


        '''
        -----------------------------------------------------------------------------
        check raw
        -----------------------------------------------------------------------------
        '''

        KAFKAjson.read_raw(termId=device_v_term_id, protocolId=device_v_protocol_family_id, deviceTypeId=100,
                                 timePlatformFrom1970=device_time_device, timeDeviceFrom1970=device_time_device, activityInfo=device_activity_info)

        '''
        -----------------------------------------------------------------------------
        check valid
        -----------------------------------------------------------------------------
        '''

        log.debug('sleep')
        time.sleep(20)
        log.debug('sleep')
        KAFKAavro.read_valid(term_id=device_v_term_id, time_platform=device_time_device, time_device=device_time_device, activity_info=device_activity_info )


        '''
        -----------------------------------------------------------------------------
        check history db
        -----------------------------------------------------------------------------
        '''

        startTime = '2018-06-20T09:08:28+03:00'
        endTime = '2018-07-29T09:08:28+03:00'
        dateFrom = '2018-06-27T09:08:28+03:00'
        dateTo = '2018-06-27T09:08:28+03:00'

        response = DBHistory.get_history(in_term_id=device_v_term_id, in_time_start=startTime, in_time_end=endTime)

        '''
        -----------------------------------------------------------------------------
        get history
        -----------------------------------------------------------------------------
        '''

        response = HDS.get_history(termId=device_v_term_id, limit=None, sort='asc', filter=None,
                                          startTime=startTime, endTime=endTime, dateFrom=dateFrom, dateTo=dateTo, activityInfo=device_activity_info, timeDevice=device_time_device_utc)
예제 #25
0
class Test_baba:
    allure.description("Adding Student Details")

    def test_addStudent_Details(self):
        apiURL = "http://thetestingworldapi.com/api/studentsDetails"
        file = open("D:\\Pycharm\\API\\PostRequest.json", "r")

        #Global variables

        global myid
        myid = ''
        global json_payload

        #Loading file into the JSON
        json_payload = json.loads(file.read())

        #Making request
        response = requests.post(apiURL, json_payload)

        #Extracting data from respose
        extract_id = jsonpath.jsonpath(response.json(), 'id')
        myid = extract_id[0]
        print("Global id is ", myid)

    allure.description("Getting student details")

    def test_getStudentdata(self):
        apiURL = "http://thetestingworldapi.com/api/studentsDetails/" + str(
            myid)

        # Making request
        reponse = requests.get(apiURL)

        #Extracting response

        firstname = jsonpath.jsonpath(reponse.json(), 'data.first_name')
        print(firstname[0])

        assert json_payload['first_name'] == firstname[0]

        # print(reponse.text)

    allure.description("Adding tech details")

    def test_addTechincaldetails(self):
        appurl = "http://thetestingworldapi.com/api/technicalskills"
        fileaddtech = open("D:\\Pycharm\\API\\addtech.json", "r")
        json_payload = json.loads(fileaddtech.read())
        json_payload['id'] = myid
        json_payload['st_id'] = int(myid)
        reponse = requests.post(appurl, json_payload)
        # print(json_payload)

    allure.step("Veifing details")

    def test_getTechincaldetails(self):
        appurl = "http://thetestingworldapi.com/api/technicalskills/"
        reponse = requests.get(appurl)
        std_id = jsonpath.jsonpath(reponse.json(), 'data[*].st_id')
        print(std_id)

        assert str(myid) in std_id
        print("Global id is ", myid)
# -*- coding: utf-8 -*-
import pytest
from requests import Response
from rest_framework.status import HTTP_200_OK

import allure
from directory_tests_shared import URLs
from tests.smoke.cms_api_helpers import get_and_assert, status_error

pytestmark = [
    allure.suite("Secure Cookie flag"),
    allure.feature("Secure Cookie flag"),
    allure.description(
        "The Secure flag should be set on all cookies that are used for transmitting "
        "sensitive data when accessing content over HTTPS. If cookies are used to "
        "transmit session"),
]


@allure.step("Assert that Secure Cookie flag is set")
def assert_secure_cookie_flag_is_set(response: Response):
    cookie_dict = {c.name: c.__dict__ for c in response.cookies}
    insecure_cookies = [c.name for c in response.cookies if not c.secure]
    error = (f"Not all cookies on {response.url} are set with 'Secure' flag: "
             f"{insecure_cookies} → {cookie_dict}")
    assert all(c.secure for c in response.cookies), error


@allure.issue("TT-1614", "Cookies Not Set With Secure Flag")
@pytest.mark.parametrize(
    "url",
예제 #27
0
# -*- coding: utf-8 -*-
import pytest
from bs4 import BeautifulSoup
from rest_framework.status import HTTP_200_OK

import allure
from directory_tests_shared import URLs
from directory_tests_shared.settings import BASICAUTH_PASS, BASICAUTH_USER
from tests.smoke.cms_api_helpers import get_and_assert

pytestmark = [
    allure.suite("sitemap.xml"),
    allure.feature("sitemap.xml"),
    allure.description(
        "A service which handles our Top Level Domain should expose a valid sitemap.xml"
        " which enables various Search Engines/Web Crawlers (like Google) to discover "
        "what pages are present and which change frequently. This allows them to crawl "
        "our site accordingly"
    ),
]


@allure.step("Check if sitemap.xml is present")
def get_urls_from_sitemap(sitemap_url: str, *, ignore_404: bool = False) -> list:
    result = []
    try:
        response = get_and_assert(
            url=sitemap_url,
            status_code=HTTP_200_OK,
            auth=(BASICAUTH_USER, BASICAUTH_PASS),
        )
        xml_soup = BeautifulSoup(response.content, "xml")
예제 #28
0
    def test_get_history_hide(self, HDS, KAFKAavro, DBHistory):
        '''

        Create device test

        Send http request to read history

        '''
        allure.description('Testing hds get history hide equal time')
        '''
        -----------------------------------------------------------------------------
        prepare infra
        -----------------------------------------------------------------------------
        '''

        KAFKAavro.service.delete_topic()
        '''
        -----------------------------------------------------------------------------
        send message
        -----------------------------------------------------------------------------
        '''

        startTime = '2018-06-20T09:08:28+03:00'
        endTime = '2018-07-29T09:08:28+03:00'
        dateFrom = '2018-07-02T09:19:32+03:00'
        dateTo = '2018-07-02T09:19:32+03:00'

        log.debug('[test_get_history] dateFrom: ' + str(dateFrom))
        device_v_term_id = random.randint(1, 100000)
        filter = 'null'
        limit = 1
        sort = 'asc'

        expected = []
        device_activity_info = random.randint(1, 100000)

        for tim in range(2):

            device_activity = device_activity_info + tim
            device_time_device = 1530523171000 + 1000 * tim
            device_time_device_utc = datetime.fromtimestamp(
                int(device_time_device / 1000)).strftime('%Y-%m-%dT%H:%M:%SZ')

            KAFKAavro.send_valid(termId=device_v_term_id,
                                 time_platform=device_time_device,
                                 time_device=device_time_device,
                                 activity_info=device_activity)
        '''
        -----------------------------------------------------------------------------
        get history
        -----------------------------------------------------------------------------
        '''
        device_time_device_utc = datetime.fromtimestamp(
            int(1530523171000 / 1000)).strftime('%Y-%m-%dT%H:%M:%SZ')
        expected = [{
            "activityInfo": device_activity_info,
            "termId": device_v_term_id,
            "timeDevice": device_time_device_utc
        }]

        response = HDS.get_history(expected=expected,
                                   termId=device_v_term_id,
                                   limit=None,
                                   sort='asc',
                                   filter=None,
                                   startTime=startTime,
                                   endTime=endTime,
                                   dateFrom=dateFrom,
                                   dateTo=dateTo)
예제 #29
0
    def test_kafka_send_avro(self, KAFKAjson, KAFKAjson2):

        allure.description('Testing send raw json to validator topic')
        allure.label('kafka operations')

        d2 = nistest.KafkaDriver(topic=config.get('kafka_topic_valid'),
                                 server=config.get('kafka_server'),
                                 schema_registry=config.get('kafka_schema'))
        res_delete = d2.delete_topic()
        offset2 = d2.get_last_offset()
        schemaSF = '''{
              "type":"record",
              "name":"Farming",
              "namespace":"nis.dev.validator.avro",
              "fields":[
                {
                  "name": "term_id",
                  "type": "long"
                },
                {
                  "name": "time_platform",
                  "type": {
                    "type": "long",
                    "logicalType": "timestamp-millis"
                  }
                },
                {
                  "name": "time_device",
                  "type": {
                    "type": "long",
                    "logicalType": "timestamp-millis"
                  }
                },
                {
                  "name": "activity_info",
                  "type": "int"
                }
              ]
            }'''
        rawData2 = {
            "term_id": 100,
            "time_platform": 1527685363266,
            "time_device": 1527685363266,
            "activity_info": 300
        }
        expected = json.dumps(rawData2, indent=4, sort_keys=True, default=str)

        last_offset = d2.get_last_offset()
        d2.send(msg=rawData2, lang='avro', schema=schemaSF)

        res = d2.read_from_offset(offset2, 'avro', schemaSF)
        result = d2.read_from_offset(offset=offset2,
                                     lang='avro',
                                     schema=schemaSF)

        log.debug('result: ' + str(result))

        assert expected == result

        res_delete = d2.delete_topic()
        assert res_delete == 0
예제 #30
0
    def test_get_history_hide_interval_empty_response(self, HDS, KAFKAavro,
                                                      DBHistory):
        '''

        Create device test

        Send http request to read history

        '''
        allure.description(
            'Test get history hide interval equals and response empty')
        '''
        -----------------------------------------------------------------------------
        send message
        -----------------------------------------------------------------------------
        '''

        device_v_term_id = random.randint(1, 100000)
        filter = 'null'
        limit = 1
        sort = 'asc'
        device_activity_info = random.randint(1, 100)
        expected = []

        for t in range(2):

            device_time_device = datetime.strptime(
                '2018-07-02 09:19:3' + str(t),
                "%Y-%m-%d %H:%M:%S").strftime('%s000')
            KAFKAavro.send_valid(termId=device_v_term_id,
                                 time_platform=int(device_time_device),
                                 time_device=int(device_time_device),
                                 activity_info=device_activity_info)
        '''
        -----------------------------------------------------------------------------
        get history
        -----------------------------------------------------------------------------
        '''

        startTime = '2018-06-20T09:08:28+03:00'
        endTime = '2018-07-29T09:08:28+03:00'
        dateFrom = '2018-07-02T09:19:30+03:00'
        dateTo = '2018-07-02T09:19:33+03:00'
        device_time_device_utc = '2018-07-02T09:19:30Z'

        expected = [{
            "activityInfo": device_activity_info,
            "termId": device_v_term_id,
            "timeDevice": device_time_device_utc
        }]

        response = HDS.get_history(expected=expected,
                                   termId=device_v_term_id,
                                   limit=None,
                                   sort='asc',
                                   filter=None,
                                   startTime=startTime,
                                   endTime=endTime,
                                   dateFrom=dateFrom,
                                   dateTo=dateTo,
                                   no_check=True)

        assert response.status_code == 200
        expected = ["Data not found"]
        assert nistest.basic.CompareDriver(data_result=response.json(),
                                           data_expected=expected,
                                           lang='json',
                                           dump=False)