コード例 #1
0
    def test_debug_logging(self, debug):
        monufacture.debug = True

        def check_log(factory, document=None, **overrides):
            debug.assert_called_once_with(
                "CREATED [%s]: %s, document=%s, overrides=%s", 
                ANY, factory, document, overrides)
            debug.reset_mock()

        create('company')
        check_log('company')
        create('company', 'pharma')
        check_log('company', 'pharma')
        create('company', thing='blah')
        check_log('company', thing='blah')
        create_list(1, 'company', 'pharma', thing='blah')
        check_log('company', 'pharma', thing='blah')
コード例 #2
0
ファイル: module_tests.py プロジェクト: dwoos/monufacture
    def test_create_list(self):
        object_ids = [ObjectId() for x in range(3)]
        docs = [{
            "_id": object_ids[0],
            "first": "John",
            "last": "Smith",
            "prefs": {
                "receives_sms": True,
                "receives_email": False
            },
            "company_id": self.company_id,
            "email": "[email protected]",
            "age": 21
        }, {
            "_id": object_ids[1],
            "first": "John",
            "last": "Smith",
            "prefs": {
                "receives_sms": True,
                "receives_email": False
            },
            "company_id": self.company_id,
            "email": "[email protected]",
            "age": 22
        }, {
            "_id": object_ids[2],
            "first": "John",
            "last": "Smith",
            "prefs": {
                "receives_sms": True,
                "receives_email": False
            },
            "company_id": self.company_id,
            "email": "[email protected]",
            "age": 23
        }]
        return_docs = copy(docs)

        def object_id_returns(*args):
            return object_ids.pop(0)

        def doc_returns(*args):
            return return_docs.pop(0)

        self.user_collection.insert = Mock(side_effect=object_id_returns)
        self.user_collection.find_one = Mock(side_effect=doc_returns)

        created_list = create_list("user", 3)

        self.assertEqual(created_list, docs)
コード例 #3
0
    def test_create_list_of_named_documents_with_overrides(self):
        expected_docs = [{
            "first": "Bill",
            "last": "Jones",
            "prefs": {
                "receives_sms": False,
                "receives_email": True,
                "v": 4
            },
            "company_id": self.company_id,
            "email": "[email protected]",
            "age": 21,
            "created": "then",
            "favorite_color": "green",
            "v": 4
        }, {
            "first": "Bill",
            "last": "Jones",
            "prefs": {
                "receives_sms": False,
                "receives_email": True,
                "v": 4
            },
            "company_id": self.company_id,
            "email": "[email protected]",
            "age": 22,
            "created": "then",
            "favorite_color": "green",
            "v": 4
        }, {
            "first": "Bill",
            "last": "Jones",
            "prefs": {
                "receives_sms": False,
                "receives_email": True,
                "v": 4
            },
            "company_id": self.company_id,
            "email": "[email protected]",
            "age": 23,
            "created": "then",
            "favorite_color": "green",
            "v": 4
        }]

        created_list = create_list(3, "user", "admin", created="then", favorite_color="green")

        for expected, actual in zip(expected_docs, created_list):
            self.assertDictContainsSubset(expected, actual)
コード例 #4
0
 def test_create_list(self):
     expected_docs = [{
         "first": "John",
         "last": "Smith",
         "prefs": {
             "receives_sms": True,
             "receives_email": False,
             "v": 4
         },
         "company_id": self.company_id,
         "email": "[email protected]",
         "age": 21,
         "created": "now"
     }, {
         "first": "John",
         "last": "Smith",
         "prefs": {
             "receives_sms": True,
             "receives_email": False,
             "v": 4
         },
         "company_id": self.company_id,
         "email": "[email protected]",
         "age": 22,
         "created": "now"
     }, {
         "first": "John",
         "last": "Smith",
         "prefs": {
             "receives_sms": True,
             "receives_email": False,
             "v": 4
         },
         "company_id": self.company_id,
         "email": "[email protected]",
         "age": 23,
         "created": "now"
     }]
     
     created_docs = create_list(3, "user")
     
     for created, expected in zip(created_docs, expected_docs):
         self.assertDictContainsSubset(expected, created)
コード例 #5
0
 def test_some_functionality(self):
     users = create_list(10, "user")
     self.assertEqual(user_collection.count(), 10)
     self.assertEqual("John", users[0]['first'])