示例#1
0
    def test_show_rentals(self):
        """ Test the show_rentals method """
        # Given
        product_id = "V0032-100"

        # When
        expected_result = {
            "C1955810": {
                "name": "Atreides, LetoII",
                "address": "Arrakis",
                "phone_number": "899-123-5432",
                "email_address": "*****@*****.**",
            },
            "C3281830": {
                "name": "Corino, Irulan",
                "address": "Kaitain",
                "phone_number": "001-000-0002",
                "email_address": "*****@*****.**",
            },
        }

        # Then
        customers = db.show_rentals(product_id)
        LOGGER.debug(customers)
        self.assertDictEqual(expected_result, customers)
        db._drop_collections()
示例#2
0
    def test_populate_database(self):
        """ Test the populate_database method"""
        # Given
        data = [
            {
                "customer_id": "ID001",
                "name": "Paul",
                "last_name": "Atreides",
                "address": "Arrakis",
                "phone_number": "888-778-6668",
                "email_address": "*****@*****.**",
                "status": "True",
                "credit_limit": "999999.99",
            }
        ]
        mongo = db.MongoDBConnection()
        with mongo:
            test_db = mongo.connection.test_db

            # When
            (r_cnt, e_cnt) = db.populate_database(test_db, "customers", data)

            customers = test_db.customers.find()
            # test_db.customers.customer_id.find()
            LOGGER.debug(customers)
            actual_id = customers[0]["customer_id"]
            LOGGER.debug(actual_id)

            # Then
            self.assertEqual(1, r_cnt)
            self.assertEqual(0, e_cnt)
            self.assertIn("ID001", actual_id)

            db._drop_collections(test_db)
    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()
示例#4
0
 def tearDown(self):
     """ Database teardown """
     db._drop_collections()