~aleteoryx/muditaos

c42f977fd8738e67c1a59e6e455999067e301e4a — Bartosz Cichocki 5 years ago fb22548
[EGD-4752] tests: fixed contact offset bug, sliced contact test into batches (#1154)

Fix contact offset bug
Slice contact test into batches

Co-authored-by: SP2FET <bartosz.cichocki@mudita.com>
D .idea/modules.xml => .idea/modules.xml +0 -8
@@ 1,8 0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/.idea/PurePhone.iml" filepath="$PROJECT_DIR$/.idea/PurePhone.iml" />
    </modules>
  </component>
</project>
\ No newline at end of file

M module-services/service-desktop/endpoints/contacts/ContactHelper.cpp => module-services/service-desktop/endpoints/contacts/ContactHelper.cpp +2 -1
@@ 77,7 77,8 @@ auto ContactHelper::requestDataFromDB(Context &context) -> sys::ReturnCodes
    }

    auto limit = context.getBody()[json::contacts::count].int_value();
    auto query = std::make_unique<db::query::ContactGet>(0, limit, "");
    auto offset = context.getBody()[json::contacts::offset].int_value();
    auto query  = std::make_unique<db::query::ContactGet>(offset, limit, "");

    auto listener = std::make_unique<db::EndpointListener>(
        [](db::QueryResult *result, Context context) {

M module-services/service-desktop/endpoints/contacts/ContactHelper.hpp => module-services/service-desktop/endpoints/contacts/ContactHelper.hpp +1 -0
@@ 43,6 43,7 @@ namespace parserFSM
    namespace json::contacts
    {
        inline constexpr auto count           = "count";
        inline constexpr auto offset          = "offset";
        inline constexpr auto primaryName     = "priName";
        inline constexpr auto alternativeName = "altName";
        inline constexpr auto address         = "address";

M test/harness/interface/CDCSerial.py => test/harness/interface/CDCSerial.py +6 -3
@@ 23,6 23,7 @@ class CDCSerial:
    def __init__(self, port_name, timeout=10):
        self.timeout = timeout
        self.body = ""
        self.header_length = 10
        while timeout != 0:
            try:
                self.serial = serial.Serial(port_name, baudrate=115200, timeout=10)


@@ 59,13 60,15 @@ class CDCSerial:
        json_dump = json.dumps(json_data)
        return "#%09d%s" % (len(json_dump), json_dump)

    def write(self, msg, timeout=10):
    def write(self, msg, timeout=30):
        message = self.__build_message(msg)
        log.info(message)
        self.serial.write(message.encode())

        header = self.serial.read(timeout).decode()
        self.serial.timeout = timeout
        header = self.serial.read(self.header_length).decode()
        payload_length = int(header[1:])
        result = self.serial.read(payload_length).decode()
        log.info(f"received length: {len(result)}, payload length:{payload_length}")
        return json.loads(result)

    def send_key(self, key_code, key_type=Keytype.short_press, wait=10):

M test/pytest/service-desktop/test_contacts.py => test/pytest/service-desktop/test_contacts.py +24 -5
@@ 16,26 16,45 @@ def test_contacts(harness):
        pytest.skip("No contacts entries, skipping")

    # getting all contacts
    body = {"count": count}
    batch_size = 30
    divider = int(count / batch_size)
    reminder = count % batch_size
    contacts = []
    for i in range(divider):
        body = {"count": batch_size, "offset": batch_size*i}
        ret = harness.endpoint_request("contacts", "get", body)
        assert ret["status"] == status["OK"]
        contacts = contacts + ret["body"]

    body = {"count": reminder, "offset": count-reminder}
    ret = harness.endpoint_request("contacts", "get", body)
    assert ret["status"] == status["OK"]
    contacts = contacts + ret["body"]

    contacts = ret["body"]
    contacts_length = len(contacts)
    assert contacts_length
    assert contacts_length == count

    # try to get more than available
    body = {"count": 10 + count}
    batch_size = 30
    divider = int((count+10) / batch_size)
    reminder = (count+10) % batch_size
    contacts = []
    for i in range(divider):
        body = {"count": batch_size, "offset": batch_size * i}
        ret = harness.endpoint_request("contacts", "get", body)
        assert ret["status"] == status["OK"]
        contacts = contacts + ret["body"]

    body = {"count": reminder, "offset": (count+10)-reminder}
    ret = harness.endpoint_request("contacts", "get", body)
    assert ret["status"] == status["OK"]
    contacts = contacts + ret["body"]

    contacts = ret["body"]
    contacts_length = len(contacts)
    assert contacts_length
    assert contacts_length == count


    # adding new contact
    body = {"address": "6 Czeczota St.\n02600 Warsaw",
            "altName": "Testowy",