Пример #1
0
 def setUp(self):
     """ Database Setup """
     product_file = "products"
     directory_name = "./csv_files"
     customer_file = "customers"
     rental_file = "rentals"
     db.import_data(directory_name, product_file, customer_file, rental_file)
def test_import_data():
    added, errors = l.import_data()
    for add in added:
        assert isinstance(add, int)
    for error in errors:
        assert isinstance(error, int)
    assert added == (10, 10, 9)
    assert errors == (0, 0, 0)
Пример #3
0
 def test_show_rentals(self):
     """This method tests that the correct customers are displayed for the product_id"""
     database.import_data('csvs', 'product_data.csv', 'customer_data.csv',
                          'rentals_data.csv')
     actual_customers1 = database.show_rentals('prd002')
     expected_customers1 = {
         'cst001': {
             'name': 'Charlie',
             'address': '123 Fleet Street',
             'phone_number': '1231234123'
         },
         'cst002': {
             'name': 'Andrey',
             'address': '123 Jordan Street',
             'phone_number': '4564564567'
         }
     }
     actual_customers2 = database.show_rentals('prd009')
     expected_customers2 = {}
     self.assertEqual(actual_customers1, expected_customers1)
     self.assertEqual(actual_customers2, expected_customers2)
Пример #4
0
def test_import_data():
    """ import """
    added, errors = l.import_data('data', 'product.csv', 'customers.csv',
                                  'rental.csv')

    for add in added:
        assert isinstance(add, int)

    for error in errors:
        assert isinstance(error, int)

    assert added == (10, 10, 9)
    assert errors == (0, 0, 0)
def test_import_data():
    """ import """
    data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
    added, errors = l.import_data(data_dir, "products.csv", "customers.csv",
                                  "rentals.csv")

    for add in added:
        assert isinstance(add, int)

    for error in errors:
        assert isinstance(error, int)

    assert added == (10, 10, 9)
    assert errors == (0, 0, 0)
Пример #6
0
    def test_show_available(self):
        """This method tests that all and only available products are displayed"""
        database.import_data('csvs', 'product_data.csv', 'customer_data.csv',
                             'rentals_data.csv')
        actual_available = database.show_available_products()
        expected_available = {
            'prd001': {
                'description': 'TV',
                'product_type': 'livingroom',
                'quantity_available': '3'
            },
            'prd002': {
                'description': 'Couch',
                'product_type': 'livingroom',
                'quantity_available': '1'
            }
        }
        self.assertEqual(actual_available, expected_available)
        database.delete_database()

        database.import_data('csvs', 'produc_data.csv', 'customer_data.csv',
                             'rentals_data.csv')
        database.delete_database()
Пример #7
0
    def test_import_data(self):
        """
        Tests the import_data function of Database.py
        :return: None
        """

        direct = "C:\\Python220A_2019\\students\\KyleCreek\\lesson05\\assignment\\data\\"
        cust = "customers.csv"
        prod = "product.csv"
        rent = "rental.csv"

        return_tuple = import_data(direct, prod, cust, rent)
        self.assertIsInstance(return_tuple, tuple)
        self.assertEqual(len(return_tuple), 4)
Пример #8
0
    def test_import(self):
        """This method will test import of .csv files to the database"""

        database.delete_database()

        #Fully successful import
        actual_tuples1 = database.import_data('csvs', 'product_data.csv',
                                              'customer_data.csv',
                                              'rentals_data.csv')
        expected_tuples1 = ((1, 1, 1), (0, 0, 0))
        self.assertEqual(actual_tuples1, expected_tuples1)
        database.delete_database()

        #Partially successful import with failed product_data
        actual_tuples2 = database.import_data('csvs', 'produc_data.csv',
                                              'customer_data.csv',
                                              'rentals_data.csv')
        expected_tuples2 = ((0, 1, 1), (1, 0, 0))
        self.assertEqual(actual_tuples2, expected_tuples2)
        database.delete_database()

        #Partially successful import with failed customer_data
        actual_tuples3 = database.import_data('csvs', 'product_data.csv',
                                              'custome_data.csv',
                                              'rentals_data.csv')
        expected_tuples3 = ((1, 0, 1), (0, 1, 0))
        self.assertEqual(actual_tuples3, expected_tuples3)
        database.delete_database()

        #Partially successful import with failed rentals_data
        actual_tuples4 = database.import_data('csvs', 'product_data.csv',
                                              'customer_data.csv',
                                              'rental_data.csv')
        expected_tuples4 = ((1, 1, 0), (0, 0, 1))
        self.assertEqual(actual_tuples4, expected_tuples4)
        database.delete_database()
def test_import_data():
    """ import """
    file_dir = pathlib.Path(os.path.abspath(__file__)).parents
    data_dir = file_dir[1] / "data"
    # data_dir = os.path.dirname(os.path.abspath(__file__))
    added, errors = l.import_data(data_dir, "product.csv", "customers.csv",
                                  "rental.csv")

    for add in added:
        assert isinstance(add, int)

    for error in errors:
        assert isinstance(error, int)

    assert added == (10, 10, 9)
    assert errors == (0, 0, 0)
Пример #10
0
    def test_import_data(self):
        """ Test the import_data method"""
        # Given
        product_file = "products"
        directory_name = "./csv_files"
        customer_file = "customers"
        rental_file = "rentals"

        # When
        [records, errors] = db.import_data(directory_name, product_file,
                                           customer_file, rental_file)

        # Then
        self.assertEqual(0, errors[0])
        self.assertEqual(0, errors[1])
        self.assertEqual(0, errors[2])

        self.assertEqual(4, records[0])
        self.assertEqual(4, records[1])
        self.assertEqual(5, records[2])
        db._drop_collections()