def test_create_test_builds_correctly():
    t = Tackle('some_filename.txt')
    assert len(t._tests) == 0
    assert len(t._results.keys()) == 0
    t.create_test(
        test_name='test the test',
        input_routing_key='test key 1',
        output_routing_key='test key 2',
        dataset=None, # not actually running the test so not a problem
    )
    assert len(t._tests) == 1
    assert len(t._results.keys()) == 1
    assert t._results.get('test the test') != None
Example #2
0
    def __init__(self, product_db):
        # tackle bugs in name
        self.tackle = Tackle()
        self.product_db = dict()
        for key in product_db.keys():
            if product_db[key]:
                self.product_db[key] = product_db[key].decode(encoding = 'UTF-8', errors = 'strict')
            else:
                self.product_db[key] = product_db[key]
        self._fetch_stock()

        self.format_dict = dict()
        self._normal_field()
        self._stock_field()
Example #3
0
class Product(object):
    def __init__(self, product_db):
        # tackle bugs in name
        self.tackle = Tackle()
        self.product_db = dict()
        for key in product_db.keys():
            if product_db[key]:
                self.product_db[key] = product_db[key].decode(encoding = 'UTF-8', errors = 'strict')
            else:
                self.product_db[key] = product_db[key]
        self._fetch_stock()

        self.format_dict = dict()
        self._normal_field()
        self._stock_field()
        # self.fingerprint_mapping()
        # self.suitable_mapping()
        # self.white_mapping()

    def _fetch_stock(self):
        pid = self.product_db['pid']
        conn = MySQL(DEJA_FASHION_MYSQL_CONFIG_PRODUCT)
        fetch_sql = '''
            select * from deja_product_stock where pid = '{pid}'
            order by time desc limit 1
        '''.format(pid=pid)
        results = conn.fetch_rows(fetch_sql)
        #get the most recently stock infomation, then generate stock.
        self.stock = Stock(results)
        pass

    def _normal_field(self):
        self.format_dict['pid'] = self.product_db['pid']
        #add by dongjie
        self.format_dict['product_code'] = self.product_db['product_code']

        self.format_dict['merchant'] = self.product_db['merchant']
        self.format_dict['group_id'] = self.product_db['group_id']
        self.format_dict['shop_url'] = self.product_db['url'].replace(u'\\', u'\\\\').replace(u'\'', u'\\\'')
        self.format_dict['detail_images'] = json.dumps(self.product_db['detail_images'].split('|'))
        self.format_dict['description'] = self._set_description()
        # self.format_dict['description_text'] = ""
        self.format_dict['update_v'] = unicode(int(round(time.time() * 1000)))
        # self.format_dict['update_time'] = unicode(time.strftime('%Y-%m-%d %H:%M:%S'))

        #add by jack
        self.format_dict['white_index'] = self.get_index_of_img_in_detail_images(self.product_db['detail_images'], self.product_db['white_suitable_images'])

        self.format_dict['suitable_index'] = self.get_index_of_img_in_detail_images(self.product_db['detail_images'],
                                                   self.product_db['suitable_images'])


    def get_index_of_img_in_detail_images(self, detail_images, suitable):
        detail_images_list = detail_images.split('|')
        suitable = suitable
        if suitable in detail_images_list:
            return json.dumps([detail_images_list.index(suitable)])
        else:
            return json.dumps([])

    def _set_description(self):
        tag_source = dict()
        tag_source['category'] = self.product_db['breadcrumb']
        tag_source['info'] = u"%s_%s_%s_%s_%s" % (
            self.product_db['size_guide'], self.product_db['delivery_returns'], self.product_db['color'],
            self.product_db['washing_care']
            , self.product_db['material']
        )
        tag_source['description'] = self.product_db['description']
        #add by jack, zhou nan need the color
        tag_source['color'] = self.product_db['color']
        tag_source['brand'] = self.product_db['brand']
        tag_source['name'] = self.tackle.tackle_merchant(int(self.product_db['merchant']), self.product_db['name'])
        return json.dumps(tag_source).replace(u'\\', u'\\\\').replace(u'\'', u'\\\'')

    def _stock_field(self):
        self.format_dict['natural_currency'] = self.stock.stock_info['natural_currency']
        self.format_dict['natural_original_price'] = self.stock.stock_info['natural_price']
        self.format_dict['natural_price'] = self.stock.stock_info['natural_discount_price']
        self.format_dict['stock_info'] = self.stock.stock_info['stock_info']
        self.format_dict['original_price'] = self.stock.stock_info['price']
        self.format_dict['price'] = self.stock.stock_info['discount_price']
        self.format_dict['currency'] = self.stock.stock_info['currency_unit']
        self.format_dict['status'] = self.stock.stock_info['status']
        pass

    def _fill_default(self):
        pass
Example #4
0
import asyncio
import json
import logging

from tackle import Tackle

logging.basicConfig(level="DEBUG")
log = logging.getLogger(__name__)

t = Tackle(output_path='any.txt')

input = json.loads(
    '{"type": "PUBLISH_NEW_CITATION", "user": "******", "timestamp": "definitely right now", "payload": {"text": "oh hi there, some very interesting! sample! text!", "GUID": "fake-citation-3599", "tags": [], "meta": {}}}'
)
output = json.loads(
    '{"type": "CITATION_PUBLISHED", "user": "******", "timestamp": "definitely right now", "priority": 1, "payload": {"text": "oh hi there, some very interesting! sample! text!", "GUID": "fake-citation-3599", "tags": [], "meta": {}}}'
)
data = [{'in': input, 'out': output}]

t.create_test(test_name='Test setup',
              input_routing_key='command.writemodel',
              output_routing_key='event.emitted',
              dataset=data)

t.run_tests()
results = t.results()
def test_file_loader():
    t = Tackle('some_filename.txt')
    data = t.load_data('tests/test_data.json')
    assert data['name'] == 'test'