def test_001_add_drugstore(self):
     response = self.add_drugstore(self.drugstore_1)
     assert response.status_code == 200
     json_data = json.loads(response.data)
     assert jsoncompare.are_same(json_data["mobilerp"], self.drugstore_1,
                                 False, ['id'])
     response = self.add_drugstore(self.drugstore_2)
     assert response.status_code == 200
     json_data = json.loads(response.data)
     assert jsoncompare.are_same(json_data["mobilerp"], self.drugstore_2,
                                 False, ['id'])
Exemple #2
0
def json_should_be(context, field):
    actual_value = json.loads(context.response.text)
    expected_value = json.loads(context.text)
    same, error_message = jsoncompare.are_same(
        expected_value, actual_value, True, [field]
    )
    assert same, error_message
Exemple #3
0
def comparejson(a, b):
    result = jsoncompare.are_same(a, b)[0]
    if result:
        ## JSONs are the same ##
        print("0")
    else:
        ## JSONs are different ##
        print("1")
def comparejson(a, b):
    result = jsoncompare.are_same(a, b)[0]
    if result:
        ## JSONs are the same ##
        print("0");
    else:
        ## JSONs are different ##
        print("1");
Exemple #5
0
 def test_006_list_products_1_1(self):
     response = self.list_products_1_1(1)
     json_data = json.loads(response.data)
     assert len(json_data["mobilerp"]) == 4
     assert response.status_code == 200
     assert b'0001' in response.data
     assert b'0002' in response.data
     assert b'0003' in response.data
     assert b'1000' in response.data
     for item in json_data["mobilerp"]:
         if item['barcode'] == '0001':
             assert jsoncompare.are_same(item, self.json_prod_1, True)
         if item['barcode'] == '0002':
             assert jsoncompare.are_same(item, self.json_prod_2, True)
         if item['barcode'] == '0003':
             assert jsoncompare.are_same(item, self.json_prod_3, True)
         if item['barcode'] == '1000':
             assert jsoncompare.are_same(item, self.json_prod_6, True)
     response = self.list_products_1_1(2)
     json_data = json.loads(response.data)
     assert len(json_data["mobilerp"]) == 3
     assert response.status_code == 200
     assert b'0004' in response.data
     assert b'0005' in response.data
     assert b'1001' in response.data
     for item in json_data["mobilerp"]:
         if item['barcode'] == '0004':
             assert jsoncompare.are_same(item, self.json_prod_4, True)
         if item['barcode'] == '0005':
             assert jsoncompare.are_same(item, self.json_prod_5, True)
         if item['barcode'] == '0003':
             assert jsoncompare.are_same(item, self.json_prod_7, True)
 def test_005_update_service_1_1_change_price(self):
     service = dict(
         barcode='0001',
         price=10.5
     )
     response = self.find_service_1_1(service['barcode'])
     assert response.status_code == 200
     response = self.update_service_1_1(
         service['barcode'], json.dumps(service))
     assert response.status_code == 200
     json_data = json.loads(response.data)
     assert jsoncompare.are_same(json_data["mobilerp"], json.dumps(service))
Exemple #7
0
 def test_005_list_products_1_0(self):
     response = self.list_products_1_0()
     json_data = json.loads(response.data)
     assert len(json_data["mobilerp"]) == 4
     assert response.status_code == 200
     assert b'0001' in response.data
     assert b'0002' in response.data
     assert b'0003' in response.data
     assert b'1000' in response.data
     for item in json_data["mobilerp"]:
         if item['barcode'] == '0001':
             assert jsoncompare.are_same(item, self.json_prod_1, False,
                                         ['storeid'])
         if item['barcode'] == '0002':
             assert jsoncompare.are_same(item, self.json_prod_2, False,
                                         ['storeid'])
         if item['barcode'] == '0003':
             assert jsoncompare.are_same(item, self.json_prod_3, False,
                                         ['storeid'])
         if item['barcode'] == '1000':
             assert jsoncompare.are_same(item, self.json_prod_6, False,
                                         ['storeid'])
 def test_003_edit_drugstore(self):
     response = self.open_with_auth('/api/v1.1/list_drugstores/', 'GET')
     assert response.status_code == 200
     json_data = json.loads(response.data)
     i = 2
     for item in json_data["mobilerp"]:
         new_json = json.dumps({
             'name': 'Store X' + str(i),
             'id': item['id']
         })
         response = self.open_with_auth('/api/v1.1/edit_drugstore/', 'PUT',
                                        new_json)
         assert response.status_code == 200
         new_data = json.loads(response.data)
         assert jsoncompare.are_same(new_data, new_json)
         i = i + 1
Exemple #9
0
def verifyResponse(expected_response, actual_response):
    try:
        jsoncompare.are_same(json.loads(expected_response), actual_response)
        print jsoncompare.are_same(json.loads(expected_response),
                                   actual_response)[0]
        print("Compare Results:")
        print("###############################################")
        print jsoncompare.are_same(json.loads(expected_response),
                                   actual_response)
        print("###############################################")
        print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
        return jsoncompare.are_same(json.loads(expected_response),
                                    actual_response)[0]
    except ValueError:
        print("data was not valid JSON")
        return False
Exemple #10
0
def compare(a, b):
    miss, hit, actual = jsoncompare.are_same(a, b)[1:4]
    expected = []
    expected.extend(repeat(1, len(actual)))
    hit_val = hit[1]
    miss_val = miss[1]
    accuracy = hit_val / (hit_val + miss_val) * 100

    score = f1_score(expected, actual)
    print("**********")
    print("hits =", hit_val)
    print("miss =", miss_val)
    print("accuracy =", accuracy, "%")
    print("f1 score =", score)

    # writing results of each file in a csv file
    res = [[hit_val, miss_val, accuracy, score]]
    with open("result.csv", "a") as result:
        writer = csv.writer(result)
        writer.writerows(res)
 def test_003_list_services_1_1(self):
     response = self.list_service_1_1()
     assert response.status_code == 200
     json_data = json.loads(response.data)
     assert len(json_data["mobilerp"]) == 6
     for item in json_data["mobilerp"]:
         if item['barcode'] == '0001':
             assert jsoncompare.are_same(item, self.json_serv_1, True)
         elif item['barcode'] == '0002':
             assert jsoncompare.are_same(item, self.json_serv_2, True)
         elif item['barcode'] == '0003':
             assert jsoncompare.are_same(item, self.json_serv_3, True)
         elif item['barcode'] == '0004':
             assert jsoncompare.are_same(item, self.json_serv_4, True)
         elif item['barcode'] == '0005':
             assert jsoncompare.are_same(item, self.json_serv_5, True)
         elif item['barcode'] == '0006':
             assert jsoncompare.are_same(item, self.json_serv_6, True)
 def test_002_find_service_1_1(self):
     response = self.find_service_1_1('1000')
     assert response.status_code == 200
     json_data = json.loads(response.data)
     assert jsoncompare.are_same(
         json_data["mobilerp"], self.json_serv_6, True)
Exemple #13
0
 def test_002_add_product_1_1(self):
     response = self.add_product_1_1(self.json_prod_7)
     json_data = json.loads(response.data)
     assert response.status_code == 200
     assert jsoncompare.are_same(json_data["mobilerp"], self.json_prod_7,
                                 True)
Exemple #14
0
 def test_003_find_product_1_0(self):
     response = self.find_product_1_0('1000')
     json_data = json.loads(response.data)
     assert jsoncompare.are_same(json_data["mobilerp"], self.json_prod_6,
                                 False, ['storeid'])
     assert response.status_code == 200
Exemple #15
0
 def test_004_find_product_1_1(self):
     response = self.find_product_1_1('2', '1001')
     json_data = json.loads(response.data)
     assert jsoncompare.are_same(json_data["mobilerp"], self.json_prod_7,
                                 True)
     assert response.status_code == 200
Exemple #16
0
 def __eq__(self, other):
     return jsoncompare.are_same(self.json, other.json)[0]
Exemple #17
0
 def __eq__(self, other):
     return jsoncompare.are_same(self.json, other.json)[0]