Testcases failed

In module 2 shared my review through qeats successfully but I am facing issue during assesment

I have tried solving the issue by redoing each task but could not find where i got wrong

THIS IS MY UNIT TESTING LOG

2020-01-25 16:20:09,813 unitTesting INFO Running pytest
2020-01-25 16:20:18,287 unitTesting INFO ============================= test session starts ==============================
platform linux – Python 3.6.9, pytest-5.3.1, py-1.8.0, pluggy-0.12.0
Django settings: qeats.settings (from ini file)
rootdir: /mynenisp1703-ME_QEATS_REVIEW_MP-8a2ec2e8-3f8e-11ea-b30c-ab5bc8175981/mynenisp1703-ME_QEATS_REVIEW_MP, inifile: pytest.ini
plugins: django-3.5.1, mock-1.10.4
collected 2 items

tests/test_views.py FF [100%]

=================================== FAILURES ===================================
______________ TestSocialSharing.test_post_to_facebook_share_cli _______________

self = <tests.test_views.TestSocialSharing object at 0x3ee59cf55eb8>

def test_post_to_facebook_share_cli(self):

    facebook = restaurants.facebook_post.Facebook()
    image_url = 'http://ksmartstatic.sify.com/cmf-1.0.0/appflow/bawarchi.com/Image/oeturjecjjdah_bigger.jpg'
    my_name = self.get_user_name()

    message = my_name + ' completed FACEBOOK CLI module! @ {}'.format(str(datetime.datetime.now()))
    print(message)
    facebook.publish_photo_msg(message, image_url)

    facebook_test_util = FacebookTestUtil()
  assert facebook_test_util.check_whether_message_is_published(message, image_url)

tests/test_views.py:119:


self = <tests.test_views.FacebookTestUtil object at 0x3ee5a1d4b5f8>
message = ‘Assessment completed FACEBOOK CLI module! @ 2020-01-25 16:20:11.514697’
image_path = ‘http://ksmartstatic.sify.com/cmf-1.0.0/appflow/bawarchi.com/Image/oeturjecjjdah_bigger.jpg

def check_whether_message_is_published(self, message, image_path):
    user_feeds = self.get_user_feed()

    if 'error' in user_feeds:
        print("\n\n",json.dumps(user_feed, indent=4))
        return False
    for feed in user_feeds['data']:
        if 'attachments' in feed:
          if feed['message'] == message:

E KeyError: ‘message’

tests/test_views.py:82: KeyError
----------------------------- Captured stdout call -----------------------------
Assessment completed FACEBOOK CLI module! @ 2020-01-25 16:20:11.514697
200
{‘id’: ‘108165340736456’, ‘post_id’: ‘106641657555491_108165340736456’}
Get user feed url = https://graph.facebook.com/106641657555491/feed?access_token=EAAJgjkAaFCQBAECTNkz84xAGqzKeZBhyHPZA111ZCGtNd64DRXZBtvglz8usX0ZCHiABis0d8LZCZCvkY4SeiEEyupb6PKR6VZABoYCO2xfwCyfZAKQz36GH3IeMOKJMY4wLAkhFe58m3SsODgaQsjN6Cd3odZBivpw4yUXLwnRdzFoAZDZD&fields=id,message,attachments
________________ TestSocialSharing.test_post_to_facebook_share _________________

self = <tests.test_views.TestSocialSharing object at 0x3ee59cf21518>

def test_post_to_facebook_share(self):
    client = Client()

    prefix = os.getenv('USER_SOLUTION')
    if prefix is None:
        prefix = '.'

    image_path = prefix + '/tests/sneakpeak.jpg'
    img_b64 = restaurants.image_uploader.file_path_to_img64(image_path)
    message = 'Great Work!!! Completed module 1 @ {}'.format(str(datetime.datetime.now()))
    request_body = {
                    'imgBase64' : img_b64.decode('utf-8'),
                    'text' : message,
                    'orderId' : '0x12312',
                    'tags' : ['Facebook', 'Module1'],
                    'share' : ['Facebook']
                    }

    resp = client.post(r'/qeats/v1/review/share', data=request_body, content_type='application/json')
    assert resp.status_code == 200
    facebook_test_util = FacebookTestUtil()
    message_expected = message + ' #Facebook #Module1'
  assert facebook_test_util.check_whether_message_is_published(message_expected, image_path)

tests/test_views.py:145:


self = <tests.test_views.FacebookTestUtil object at 0x3ee59cb11dd8>
message = ‘Great Work!!! Completed module 1 @ 2020-01-25 16:20:14.655534 #Facebook #Module1
image_path = ‘/mynenisp1703-ME_QEATS_REVIEW_MP-8a2ec2e8-3f8e-11ea-b30c-ab5bc8175981/mynenisp1703-ME_QEATS_REVIEW_MP/tests/sneakpeak.jpg’

def check_whether_message_is_published(self, message, image_path):
    user_feeds = self.get_user_feed()

    if 'error' in user_feeds:
        print("\n\n",json.dumps(user_feed, indent=4))
        return False
    for feed in user_feeds['data']:
        if 'attachments' in feed:
          if feed['message'] == message:

E KeyError: ‘message’

tests/test_views.py:82: KeyError
----------------------------- Captured stdout call -----------------------------
200
{‘id’: ‘108165417403115’, ‘post_id’: ‘106641657555491_108165417403115’}
Get user feed url = https://graph.facebook.com/106641657555491/feed?access_token=EAAJgjkAaFCQBAECTNkz84xAGqzKeZBhyHPZA111ZCGtNd64DRXZBtvglz8usX0ZCHiABis0d8LZCZCvkY4SeiEEyupb6PKR6VZABoYCO2xfwCyfZAKQz36GH3IeMOKJMY4wLAkhFe58m3SsODgaQsjN6Cd3odZBivpw4yUXLwnRdzFoAZDZD&fields=id,message,attachments
=============================== warnings summary ===============================
/usr/local/lib/python3.6/dist-packages/_pytest/junitxml.py:436
/usr/local/lib/python3.6/dist-packages/_pytest/junitxml.py:436: PytestDeprecationWarning: The ‘junit_family’ default value will change to ‘xunit2’ in pytest 6.0.
Add ‘junit_family=legacy’ to your pytest.ini file to silence this warning and make your suite compatible.
_issue_warning_captured(deprecated.JUNIT_XML_DEFAULT_FAMILY, config.hook, 2)

– Docs: https://docs.pytest.org/en/latest/warnings.html

  • generated xml file: /mynenisp1703-ME_QEATS_REVIEW_MP-8a2ec2e8-3f8e-11ea-b30c-ab5bc8175981/mynenisp1703-ME_QEATS_REVIEW_MP/tests.xml -
    ========================= 2 failed, 1 warning in 6.95s =========================

2020-01-25 16:20:18,325 unitTesting INFO Pytest run complete
2020-01-25 16:20:18,328 unitTesting INFO Report generated: {‘tests.test_views.TestSocialSharing.test_post_to_facebook_share_cli’: ‘TEST_STATUS_FAILURE’, ‘tests.test_views.TestSocialSharing.test_post_to_facebook_share’: ‘TEST_STATUS_FAILURE’}

Make sure you are using the correct URL.
Check the message at 5:07 PM on #announcement channel on slack.
Use the cURL provided at the end of the message.

1 Like

I am unable to see the message at 5:07 PM on #announcement channel on slack.Can you please post it here.