예제 #1
0
 def test_id_of_with_function_overrides(self, create):
     create.return_value = {"_id": 1234}
     func = id_of("bob", "dave", sandwich=lambda n: n['flavor'])
     obj1 = {"flavor": "ham"}
     obj2 = {"flavor": "cheese"}
     self.assertEqual(1234, func(obj1))
     self.assertEqual(1234, func(obj2))
     self.assertEqual(
         [call("bob", "dave", sandwich="ham"), call("bob", "dave", sandwich="cheese")],
         create.mock_calls)
예제 #2
0
 def test_id_of_with_function_overrides(self, create):
     create.return_value = {"_id": 1234}
     func = id_of("bob", "dave", sandwich=lambda n: n['flavor'])
     obj1 = {"flavor": "ham"}
     obj2 = {"flavor": "cheese"}
     self.assertEqual(1234, func(obj1))
     self.assertEqual(1234, func(obj2))
     self.assertEqual([
         call("bob", "dave", sandwich="ham"),
         call("bob", "dave", sandwich="cheese")
     ], create.mock_calls)
예제 #3
0
    def setUp(self):
        with factory("user", user_collection):
            default({
                "first": "John",
                "last": "Smith",
                "prefs": {
                    "receives_sms": True,
                    "receives_email": False
                },
                "company_id": id_of("company"),
                "email": dependent(lambda doc: "*****@*****.**" % (doc['first'], doc['last'])),
                "age": sequence(lambda n: n + 20)
            })

        with factory("company", company_collection):
            default({
                "name": "GloboCorp"
            })
예제 #4
0
    def setUp(self):
        with factory("user", user_collection):
            default({
                "first":
                "John",
                "last":
                "Smith",
                "prefs": {
                    "receives_sms": True,
                    "receives_email": False
                },
                "company_id":
                id_of("company"),
                "email":
                dependent(lambda doc: "*****@*****.**" %
                          (doc['first'], doc['last'])),
                "age":
                sequence(lambda n: n + 20)
            })

        with factory("company", company_collection):
            default({"name": "GloboCorp"})
예제 #5
0
 def test_id_of_with_overrides(self, create):
     create.return_value = {"_id": 1234}
     func = id_of("bob", "dave", sandwich="blt")
     self.assertEqual(1234, func())
     create.assert_called_with("bob", "dave", sandwich="blt")
예제 #6
0
 def test_id_of_with_doc_name(self, create):
     create.return_value = {"_id": 1234}
     func = id_of("bob", "dave")
     self.assertEqual(1234, func())
     create.assert_called_with("bob", "dave")
예제 #7
0
 def test_id_of(self, create):
     create.return_value = {"_id": 1234}
     func = id_of("bob")
     self.assertEqual(1234, func())
     create.assert_called_with("bob", None)
예제 #8
0
    def setUp(self):
        self.company_id = ObjectId()
        self.user_collection = conn.user
        self.company_collection = Mock()
        self.company_collection.insert = Mock(return_value=self.company_id)
        self.company_collection.find_one = Mock(return_value={'_id': self.company_id})

        trait("versioned", {
            "v": 4
        })

        with factory("user", self.user_collection):
            fragment("prefs_email", {
                "receives_sms": True,
                "receives_email": False
            }, traits=['versioned'])

            fragment("prefs_sms", {
                "receives_sms": False,
                "receives_email": True                
            }, traits=['versioned'])

            fragment("empty_prefs", traits=['versioned'])

            default({
                "first": "John",
                "last": "Smith",
                "prefs": embed("prefs_email")
            }, traits=["common"])

            document("admin", {
                "first": "Bill",
                "last": "Jones",
                "prefs": embed("prefs_sms"),
            }, parent="default", traits=["versioned"])

            document("nameless", parent="default", traits=["versioned"])

            trait("timestamped", {
                "created": "now"
            })

            trait("common", {
                "company_id": id_of("company"),
                "email": dependent(lambda doc: "*****@*****.**" % (doc['first'], doc['last'])),
                "age": sequence(lambda n: n + 20)
            }, parent="timestamped")

        
        with factory("company", self.company_collection):
            default({
                "name": "GloboCorp"
            })

            document('pharma', {
                "name": "Pfizer"
            })

        with factory("fake"):
            default({
                "fake": True
            })
예제 #9
0
 def test_id_of_with_overrides(self, create):
     create.return_value = {"_id": 1234}
     func = id_of("bob", "dave", sandwich="blt")
     self.assertEqual(1234, func())
     create.assert_called_with("bob", "dave", sandwich="blt")
예제 #10
0
 def test_id_of_with_doc_name(self, create):
     create.return_value = {"_id": 1234}
     func = id_of("bob", "dave")
     self.assertEqual(1234, func())
     create.assert_called_with("bob", "dave")
예제 #11
0
 def test_id_of(self, create):
     create.return_value = {"_id": 1234}
     func = id_of("bob")
     self.assertEqual(1234, func())
     create.assert_called_with("bob", None)
예제 #12
0
    def setUp(self):
        self.company_id = ObjectId()
        self.user_collection = conn.user
        self.company_collection = Mock()
        self.company_collection.insert = Mock(return_value=self.company_id)
        self.company_collection.find_one = Mock(
            return_value={'_id': self.company_id})

        trait("versioned", {"v": 4})

        with factory("user", self.user_collection):
            fragment("prefs_email", {
                "receives_sms": True,
                "receives_email": False
            },
                     traits=['versioned'])

            fragment("prefs_sms", {
                "receives_sms": False,
                "receives_email": True
            },
                     traits=['versioned'])

            fragment("empty_prefs", traits=['versioned'])

            default(
                {
                    "first": "John",
                    "last": "Smith",
                    "prefs": embed("prefs_email")
                },
                traits=["common"])

            document("admin", {
                "first": "Bill",
                "last": "Jones",
                "prefs": embed("prefs_sms"),
            },
                     parent="default",
                     traits=["versioned"])

            document("nameless", parent="default", traits=["versioned"])

            trait("timestamped", {"created": "now"})

            trait("common", {
                "company_id":
                id_of("company"),
                "email":
                dependent(lambda doc: "*****@*****.**" %
                          (doc['first'], doc['last'])),
                "age":
                sequence(lambda n: n + 20)
            },
                  parent="timestamped")

        with factory("company", self.company_collection):
            default({"name": "GloboCorp"})

            document('pharma', {"name": "Pfizer"})

        with factory("fake"):
            default({"fake": True})