Beispiel #1
0
    def get_marketplace(self):
        marketplace_dict = {
            'id':
            str(uuid.uuid4()),
            'user_id':
            str(uuid.uuid4()),
            'name':
            'tienda_1',
            'address': {
                'street': 'General Gana',
                'number': '1063',
                'block': '219-A',
                'city': 'Santiago',
                'city_2': 'Santiago Centro',
                'country': 'CL',
                'phone': '+56953078374',
                'zip_code': '823000'
            },
            'publications': [{
                'id_sku': '3434',
                'price': 400.00,
                'quantity': 10
            }, {
                'id_sku': '9999',
                'price': 999.00,
                'quantity': 10
            }]
        }

        return MarketplaceFactory.from_dict(marketplace_dict)
Beispiel #2
0
    def test_on_missing_address_from_dict_raises_attribute_error(self):
        #Arrange
        marketplace_dict = {
            'id': str(uuid.uuid4()),
            'user_id': str(uuid.uuid4()),
            'name': 'tienda_1',
            'publications': []}

        #Act #Assert
        with self.assertRaises(AttributeError, msg='Missing attribute address.'):
            marketplace = MarketplaceFactory.from_dict(marketplace_dict)
Beispiel #3
0
    def test_from_dict(self):
        #Arrange
        marketplace_dict = {
            'id': str(uuid.uuid4()),
            'user_id': str(uuid.uuid4()), 
            'name': 'tienda_1',
            'address' : {
                'street': 'General Gana',
                'number': '1063',
                'block': '219-A',
                'city': 'Santiago',
                'city_2': 'Santiago Centro',
                'country': 'CL',
                'phone': '+56953078374',
                'zip_code': '823000'
            },
            'publications': [
                {
                    'id_sku': '3434',
                    'price': 400.00,
                    'quantity': 10},
                {
                    'id_sku': '9999',
                    'price': 999.00,
                    'quantity': 10}
            ]
        }

        #Act
        marketplace = MarketplaceFactory.from_dict(marketplace_dict)
        print()

        #Assert
        self.assertTrue(isinstance(marketplace.address, Address))
        self.assertTrue(isinstance(marketplace.publications, list))
        for publication in marketplace.publications:
            self.assertTrue(isinstance(publication, Publication))
        self.assertEqual(marketplace.address.street, 'General Gana')
        self.assertEqual(marketplace.address.number, '1063')
        self.assertEqual(marketplace.address.block, '219-A')
        self.assertEqual(marketplace.address.city, 'Santiago')
        self.assertEqual(marketplace.address.city_2, 'Santiago Centro')
        self.assertEqual(marketplace.address.country, 'CL')
        self.assertEqual(marketplace.address.phone, '+56953078374')
        self.assertEqual(marketplace.address.zip_code, '823000')
Beispiel #4
0
    def test_on_missing_publications_from_dict_raises_attribute_error(self):
        #Arrange
        marketplace_dict = {
            'id': str(uuid.uuid4()),
            'user_id': str(uuid.uuid4()),
            'name': 'tienda_1',
            'address' : {
                'street': 'General Gana',
                'number': '1063',
                'block': '219-A',
                'city': 'Santiago',
                'city_2': 'Santiago Centro',
                'country': 'CL',
                'phone': '+56953078374',
                'zip_code': '823000'
            }}

        #Act #Assert
        with self.assertRaises(AttributeError, msg='Missing attribute publications.'):
            marketplace = MarketplaceFactory.from_dict(marketplace_dict)
Beispiel #5
0
    def test_on_invalid_dictionary_from_dict_raises_type_error(self):
        #Arrange
        invalid_dict = 'invalid_dict'

        with self.assertRaises(TypeError):
            marketplace = MarketplaceFactory.from_dict(invalid_dict)