Exemplo n.º 1
0
 def create_listing(self, data):
     session = oauth.get_oauth_session(self.credentials,
                                       signature_type='body')
     url = oauth.ETSY_API_URL + '/listings'
     response = oauth.post_protected_resource(session, url, data)
     assert response.status_code == 201, format_http_response(response)
     print('created listing %s' % data['title'])
Exemplo n.º 2
0
 def get_sections(self):
     session = oauth.get_oauth_session(self.credentials)
     shop_id = self.get_shop_id()
     url = oauth.ETSY_API_URL + '/shops/' + shop_id + '/sections'
     response = oauth.get_protected_resource(session, url)
     assert response.status_code == 200, format_http_response(response)
     j = response.json()
     return j['results']
Exemplo n.º 3
0
 def remove_listings(self, prefix):
     session = oauth.get_oauth_session(self.credentials)
     for listing in self.filter_listings(self.get_listings(), prefix):
         url = oauth.ETSY_API_URL + '/listings/' + str(
             listing['listing_id'])
         print('removing listing', listing['listing_id'])
         response = oauth.delete_protected_resource(session, url)
         assert response.status_code == 200, format_http_response(response)
Exemplo n.º 4
0
 def _get_listings_page(_offset=0):
     url = oauth.ETSY_API_URL + '/shops/' + shop_id + '/listings/' + status + '?fields=' + fields +\
           '&limit=%d' % self.LISTINGS_LIMIT
     if _offset:
         url += '&offset=%d' % _offset
     _response = oauth.get_protected_resource(session, url)
     assert _response.status_code == 200, format_http_response(
         _response)
     return _response
Exemplo n.º 5
0
 def get_shop_id(self):
     if not self.shop_id:
         session = oauth.get_oauth_session(self.credentials)
         url = oauth.ETSY_API_URL + '/users/__SELF__/shops'
         response = oauth.get_protected_resource(session, url)
         assert response.status_code == 200, format_http_response(response)
         j = response.json()
         assert len(j['results']) > 0
         self.shop_id = str(j['results'][0]['shop_id'])
     return self.shop_id
Exemplo n.º 6
0
 def get_listing_detail(
     self,
     listing_id,
     includes='?includes=User,Shop,Section,Images,MainImage,Translations,Manufacturers,Inventory,Attributes&language=en'
 ):
     session = oauth.get_oauth_session(self.credentials)
     url = oauth.ETSY_API_URL + '/listings/' + str(listing_id) + includes
     response = oauth.get_protected_resource(session, url)
     assert response.status_code == 200, format_http_response(response)
     j = response.json()
     return j['results'][0]
Exemplo n.º 7
0
 def remove_at_section(self, section_title):
     sections = self.get_sections()
     my_section = [sec for sec in sections if sec['title'] == section_title]
     if len(my_section) > 0:
         session = oauth.get_oauth_session(self.credentials)
         shop_id = self.get_shop_id()
         shop_section_id = my_section[0]['shop_section_id']
         url = oauth.ETSY_API_URL + '/shops/' + shop_id + '/sections/' + str(
             shop_section_id)
         print('removing section', section_title, shop_section_id)
         response = oauth.delete_protected_resource(session, url)
         assert response.status_code == 200, format_http_response(response)
Exemplo n.º 8
0
 def change_listing_title(self, listing_id, listing_state, new_title):
     session = oauth.get_oauth_session(self.credentials)
     url = oauth.ETSY_API_URL + '/listings/' + str(listing_id)
     data = {
         'listing_id': int(listing_id),
         'state': listing_state.lower(),
         'title': new_title
     }
     response = oauth.put_protected_resource(session, url, data)
     assert response.status_code == 200, format_http_response(response)
     j = response.json()
     return j['results'][0]
Exemplo n.º 9
0
def compare_images(image_urls, expected_images_info):
    assert len(image_urls) == 2, "2 uploaded images expected"
    photo_dir = mkdtemp(prefix='qa-', dir='/tmp')
    img_path = os.path.join(photo_dir, 'img.jpg')

    try:
        for i, img_url in enumerate(image_urls):
            response = requests.get(img_url)
            assert response.status_code == 200, format_http_response(response)

            with open(img_path, 'wb') as f:
                f.write(response.content)
                f.close()
            img_size = subprocess.getoutput('convert ' + img_path +
                                            ' -format "%w x %h" info:')
            assert img_size == expected_images_info[i]['size']
    finally:
        shutil.rmtree(photo_dir, ignore_errors=True)