Beispiel #1
0
    def test_allows_subset(self):

        configured_option = deepcopy(BASE_PRODUCT)
        configured_option[u"options"][u"color"] = u"red"

        configured_version = WinnowVersion.add_doc(self.db, configured_option,
                                                   {})
        self.assertTrue(winnow.allows(self.base_version, configured_version))

        configured_option = deepcopy(BASE_PRODUCT)
        configured_option[u"options"][u"color"] = [u"red", u"green"]

        # the values for given keys are a subset
        configured_version = WinnowVersion.add_doc(self.db, configured_option,
                                                   {})
        self.assertTrue(winnow.allows(self.base_version, configured_version))
        self.assertFalse(winnow.allows(configured_version, self.base_version))

        self.assertFalse(
            winnow.is_allowed_by(self.base_version, configured_version))
        self.assertTrue(
            winnow.is_allowed_by(configured_version, self.base_version))

        configured_option = deepcopy(BASE_PRODUCT)
        configured_option[u"options"][u"color"] = [u"red", u"green"]
        configured_option[u"options"][u"tool"] = [u"cnc"]

        configured_version = WinnowVersion.add_doc(self.db, configured_option,
                                                   {})
        self.assertTrue(winnow.allows(self.base_version, configured_version))
Beispiel #2
0
    def test_default(self):

        other_dict = {
            u"name": u"something",
            u"description": u"these are other options",
            u"options": {
                u"color": [u"red", u"blue"],
                u"size": [u"medium"],
                u"tool": [u"cnc", u"laser", u"plaster"],
                u"days": [u"tuesday", u"thursday"],
                u"drinks": [u"beer", u"coffee"],
                u"snacks": [u"crisps", u"cheese", u"apple"]
            }
        }

        expected = {
            u"name": u"table",
            u"description": u"This is a very nice table",
            u"options": {
                u"color": [u"blue", u"red"],
                u"size": [u"big", u"small"],
                u"tool": [u"cnc", u"laser"],
                u"material": [u"metal", u"plastic", u"wood"],
                u"days": [u"thursday", u"tuesday"],
                u"drinks": [u"beer", u"coffee"],
                u"snacks": [u"apple", u"cheese", u"crisps"]
            }
        }

        other_version = WinnowVersion.add_doc(self.db, other_dict, {})
        merged_version = WinnowVersion.merged(self.db, BASE_PRODUCT, {},
                                              self.base_version, other_version)

        default = winnow.default_choices(merged_version, [])
Beispiel #3
0
    def test_does_a_merge(self):

        other_dict =  {u"name": u"something",
                        u"description": u"these are other options",
                        u"options":{
                            u"color": [u"red", u"blue"],
                            u"size": [u"big", u"medium", u"small"],
                            u"tool": [u"cnc", u"laser", u"plaster"],
                            u"days": [u"tuesday", u"thursday"],
                            u"drinks": [u"beer", u"coffee"],
                            u"snacks": [u"crisps", u"cheese", u"apple"]
                        }
                    }

        expected =  {u"name": u"table",
                    u"description": u"This is a very nice table",
                    u"options":{
                        u"color": [u"blue", u"red"],
                        u"size": [u"big", u"small"],
                        u"tool": [u"cnc", u"laser"],
                        u"material": [u"metal", u"plastic", u"wood"],
                        u"days": [u"thursday", u"tuesday"],
                        u"drinks": [u"beer", u"coffee"],
                        u"snacks": [u"apple", u"cheese", u"crisps"]
                    }
                }

        other_version =  WinnowVersion.add_doc(self.db, other_dict, {})
        merged = WinnowVersion.merged(self.db, BASE_PRODUCT, {}, self.base_version, other_version)

        self.maxDiff = None
        self.assertEqual(merged.kwargs[u"doc"], expected)
Beispiel #4
0
    def test_does_a_merge(self):

        other_dict = {
            u"name": u"something",
            u"description": u"these are other options",
            u"options": {
                u"color": [u"red", u"blue"],
                u"size": [u"big", u"medium", u"small"],
                u"tool": [u"cnc", u"laser", u"plaster"],
                u"days": [u"tuesday", u"thursday"],
                u"drinks": [u"beer", u"coffee"],
                u"snacks": [u"crisps", u"cheese", u"apple"]
            }
        }

        expected = {
            u"name": u"table",
            u"description": u"This is a very nice table",
            u"options": {
                u"color": [u"blue", u"red"],
                u"size": [u"big", u"small"],
                u"tool": [u"cnc", u"laser"],
                u"material": [u"metal", u"plastic", u"wood"],
                u"days": [u"thursday", u"tuesday"],
                u"drinks": [u"beer", u"coffee"],
                u"snacks": [u"apple", u"cheese", u"crisps"]
            }
        }

        other_version = WinnowVersion.add_doc(self.db, other_dict, {})
        merged = WinnowVersion.merged(self.db, BASE_PRODUCT, {},
                                      self.base_version, other_version)

        self.maxDiff = None
        self.assertEqual(merged.kwargs[u"doc"], expected)
Beispiel #5
0
    def setUp(self):
        self.db = MockKVStore()

        snot = {
            u"type": u"stuff",
            u"path": u"/stuff/bodilyfluids/snot",
            u"options":{
                u"colours": [u"green", u"yellow"],
            }
        }

        bodilyfluids = {
            u"type": u"stuff",
            u"path": u"/stuff/bodilyfluids",
            u"options":{}
        }

        drink = {
            u"type": u"drink",
            u"path": u"/drinks/cocktail",
            u"options":{
                u"stuff": u"$ref:/stuff/bodilyfluids"
            }
        }


        WinnowVersion.add_doc(self.db, snot, {})
        WinnowVersion.add_doc(self.db, bodilyfluids, {})
        self.drink = WinnowVersion.add_doc(self.db, drink, {})
Beispiel #6
0
    def test_allows_subset(self):

        configured_option = deepcopy(BASE_PRODUCT)
        configured_option[u"options"][u"color"] = u"red"

        configured_version = WinnowVersion.add_doc(self.db, configured_option, {})
        self.assertTrue(winnow.allows(self.base_version, configured_version))

        configured_option = deepcopy(BASE_PRODUCT)
        configured_option[u"options"][u"color"] = [u"red", u"green"]

        # the values for given keys are a subset
        configured_version = WinnowVersion.add_doc(self.db, configured_option, {})
        self.assertTrue(winnow.allows(self.base_version, configured_version))
        self.assertFalse(winnow.allows(configured_version, self.base_version))

        self.assertFalse(winnow.is_allowed_by(self.base_version, configured_version))
        self.assertTrue(winnow.is_allowed_by(configured_version, self.base_version))


        configured_option = deepcopy(BASE_PRODUCT)
        configured_option[u"options"][u"color"] = [u"red", u"green"]
        configured_option[u"options"][u"tool"] = [u"cnc"]

        configured_version = WinnowVersion.add_doc(self.db, configured_option, {})
        self.assertTrue(winnow.allows(self.base_version, configured_version))
Beispiel #7
0
    def test_match_taxonomy(self):

        mixer_doc = {
            u"type": u"mixers",
            u"path": u"/mixers/best",
            u"options":{
                u"stuff": u"$ref:/stuff/bodilyfluids/snot"

            }
        }

        mixer_doc_2 = {
            u"type": u"mixers",
            u"path": u"/mixers/best",
            u"options":{
                u"stuff": u"$ref:/stuff/bodilyfluids"
            }
        }

        mixer = WinnowVersion.add_doc(self.db, mixer_doc, {})
        mixer_2 = WinnowVersion.add_doc(self.db, mixer_doc_2, {})

        # try merging identical references with each other
        merged = WinnowVersion.merged(self.db, self.drink.get_doc(), {}, self.drink, mixer_2)

        self.assertEqual(merged.get_doc(), self.drink.get_doc())

        # try merging child/parent
        merged = WinnowVersion.merged(self.db, mixer_doc, {}, self.drink, mixer)
        #
        self.assertEqual(merged.get_doc(), mixer_doc)
Beispiel #8
0
    def test_default(self):

        other_dict =  {u"name": u"something",
                        u"description": u"these are other options",
                        u"options":{
                            u"color": [u"red", u"blue"],
                            u"size": [u"medium"],
                            u"tool": [u"cnc", u"laser", u"plaster"],
                            u"days": [u"tuesday", u"thursday"],
                            u"drinks": [u"beer", u"coffee"],
                            u"snacks": [u"crisps", u"cheese", u"apple"]
                        }
                    }

        expected =  {u"name": u"table",
                    u"description": u"This is a very nice table",
                    u"options":{
                        u"color": [u"blue", u"red"],
                        u"size": [u"big", u"small"],
                        u"tool": [u"cnc", u"laser"],
                        u"material": [u"metal", u"plastic", u"wood"],
                        u"days": [u"thursday", u"tuesday"],
                        u"drinks": [u"beer", u"coffee"],
                        u"snacks": [u"apple", u"cheese", u"crisps"]
                    }
                }

        other_version =  WinnowVersion.add_doc(self.db, other_dict, {})
        merged_version = WinnowVersion.merged(self.db, BASE_PRODUCT, {}, self.base_version, other_version)


        default = winnow.default_choices(merged_version, [])
Beispiel #9
0
    def test_can_merge_exception(self):

        other_dict = {
            u"name": u"something",
            u"description": u"these are other options",
            u"options": {
                u"color": [u"red", u"blue"],
                u"size": [u"medium"],
                u"tool": [u"cnc", u"laser", u"plaster"],
                u"days": [u"tuesday", u"thursday"],
                u"drinks": [u"beer", u"coffee"],
                u"snacks": [u"crisps", u"cheese", u"apple"]
            }
        }

        third_dict = {
            u"name": u"elephant",
            u"description": u"another bunch of stuff",
            u"options": {
                u"color": [u"red", u"blue"],
                u"size": [u"small"],
                u"coffee": [u"latte", u"piccolo"]
            }
        }

        expected = {
            u"name": u"table",
            u"description": u"This is a very nice table",
            u"options": {
                u"color": [u"blue", u"red"],
                u"size": [u"big", u"small"],
                u"tool": [u"cnc", u"laser"],
                u"material": [u"metal", u"plastic", u"wood"],
                u"days": [u"thursday", u"tuesday"],
                u"drinks": [u"beer", u"coffee"],
                u"snacks": [u"apple", u"cheese", u"crisps"]
            }
        }

        other_version = WinnowVersion.add_doc(self.db, other_dict, {})
        merged_version = WinnowVersion.merged(self.db, BASE_PRODUCT, {},
                                              self.base_version, other_version)
        third_version = WinnowVersion.add_doc(self.db, third_dict, {})
        merged_again = WinnowVersion.merged(self.db, merged_version.get_doc(),
                                            {}, merged_version, third_version)
        size = merged_again.get_doc()["options"]["size"]

        self.assertTrue(isinstance(size, dict))
        self.assertEqual(size["type"], "exception")
        self.assertEqual(size["values"], [[u'big', u'small'], u'medium'])
Beispiel #10
0
    def test_match(self):

        configured_product_1 = {
            u"name": u"cat",
            u"description": u"This is a very nice table",
            u"options": {
                u"color": u"red",
                u"size": u"big"
            }
        }

        configured_product_2 = {
            u"name": u"dog",
            u"description": u"This is a very nice table",
            u"options": {
                u"color": u"red",
            }
        }

        configured_product_3 = {
            u"name": u"fish",
            u"description": u"This is a very nice table",
            u"options": {
                u"color": u"red",
                u"size": u"old"
            }
        }

        configured_product_4 = {
            u"name": u"goat",
            u"description": u"This is a very nice table",
            u"options": {
                u"color": [u"red", u"green"],
                u"size": u"small"
            }
        }

        possible = [
            WinnowVersion.add_doc(self.db, configured_product_1, {}),
            WinnowVersion.add_doc(self.db, configured_product_2, {}),
            WinnowVersion.add_doc(self.db, configured_product_3, {}),
            WinnowVersion.add_doc(self.db, configured_product_4, {})
        ]

        found = self.base_version.filter_allows(possible)

        self.assertEqual(set([f.kwargs[u"doc"][u"name"] for f in found]),
                         set([u'cat', u'dog', u'goat']))
Beispiel #11
0
def get_quantified_configuration(db, product_path, choices):

    doc = {
        "schema": "https://opendesk.cc/schemata/options.json",
        "type": "choice",
        "name": "paul's choices",
        "options": choices
    }

    choice_document = WinnowVersion.add_doc(db, doc)

    product = WinnowProduct.get_from_path(db, product_path)

    qc_doc = deepcopy(product.get_doc())
    product_doc = product.get_doc()

    version = product_doc["version"]

    qc_doc[u"type"] = "quantified_configuration"
    qc_doc[u"schema"] = "https://opendesk.cc/schemata/options.json"
    qc_doc[u"product"] = "%s@%s.%s.%s" % (product_doc["path"], version[0],
                                          version[1], version[2])

    return WinnowQuantifiedConfiguration.merged(db, qc_doc, {}, product,
                                                choice_document)
Beispiel #12
0
    def test_merge_unexpands_unaffected_4(self):

        favorite_colours = {
            "type": "prefs",
            "path": "/prefs/favorites",
            "options":{
                "colours": "$ref:/choices/dog_choices~/options/colours",
            }
        }

        WinnowVersion.add_doc(self.db, favorite_colours, {})
        breed1 = WinnowVersion.get_from_path(self.db, "/breeds/collie")
        favs = WinnowVersion.get_from_path(self.db, "/prefs/favorites")
        merged = WinnowVersion.merged(self.db, breed1.get_doc(), {}, breed1, favs)
        merged_doc = merged.get_doc()
        self.assertEqual(merged_doc["options"]["colours"], u"$ref:/choices/dog_choices~/options/colours")
Beispiel #13
0
 def test_merge_does_expanding(self):
     
     favorite_colours = {
         "type": "prefs",
         "path": "/prefs/favorites",
         "options":{
             "colours": ["green","red", "white"]
         }
     }
     
     WinnowVersion.add_doc(self.db, favorite_colours, {})
     breed1 = WinnowVersion.get_from_path(self.db, "/breeds/collie")
     favs = WinnowVersion.get_from_path(self.db, "/prefs/favorites")
     merged = WinnowVersion.merged(self.db, breed1.get_doc(), {}, breed1, favs)
     merged_doc = merged.get_doc()
     self.assertEqual(merged_doc["options"]["colours"], ["red", "white"])
Beispiel #14
0
 def test_allows_fails(self):
     configured_option = deepcopy(BASE_PRODUCT)
     configured_option[u"options"][u"color"] = u"purple"
     configured_version = WinnowVersion.add_doc(self.db, configured_option,
                                                {})
     self.assertFalse(winnow.allows(self.base_version, configured_version))
     self.assertFalse(self.base_version.allows(configured_version))
Beispiel #15
0
    def test_allows_subset_without_a_key(self):

        configured_option = deepcopy(BASE_PRODUCT)
        del configured_option[u"options"][u"color"]
        configured_version = WinnowVersion.add_doc(self.db, configured_option,
                                                   {})
        self.assertTrue(winnow.allows(configured_version, self.base_version))
Beispiel #16
0
    def test_merge_unexpands_unaffected_2(self):

        favorite_colours = {
            "type": "prefs",
            "path": "/prefs/favorites",
            "options":{
                "colours": ["brown", "red", "white"]
            }
        }

        WinnowVersion.add_doc(self.db, favorite_colours, {})
        breed1 = WinnowVersion.get_from_path(self.db, "/breeds/collie")
        favs = WinnowVersion.get_from_path(self.db, "/prefs/favorites")
        merged = WinnowVersion.merged(self.db, breed1.get_doc(), {}, breed1, favs)
        merged_doc = merged.get_doc()
        print utils.json_dumps(merged_doc)
        self.assertEqual(merged_doc["options"]["colours"], u"$ref:/choices/dog_choices#/options/colours")
Beispiel #17
0
    def test_can_merge_exception (self):

        other_dict =  {u"name": u"something",
                        u"description": u"these are other options",
                        u"options":{
                            u"color": [u"red", u"blue"],
                            u"size": [u"medium"],
                            u"tool": [u"cnc", u"laser", u"plaster"],
                            u"days": [u"tuesday", u"thursday"],
                            u"drinks": [u"beer", u"coffee"],
                            u"snacks": [u"crisps", u"cheese", u"apple"]
                        }
                    }

        third_dict =  {u"name": u"elephant",
                        u"description": u"another bunch of stuff",
                        u"options":{
                            u"color": [u"red", u"blue"],
                            u"size": [u"small"],
                            u"coffee": [u"latte", u"piccolo"]
                        }
                    }

        expected =  {u"name": u"table",
                    u"description": u"This is a very nice table",
                    u"options":{
                        u"color": [u"blue", u"red"],
                        u"size": [u"big", u"small"],
                        u"tool": [u"cnc", u"laser"],
                        u"material": [u"metal", u"plastic", u"wood"],
                        u"days": [u"thursday", u"tuesday"],
                        u"drinks": [u"beer", u"coffee"],
                        u"snacks": [u"apple", u"cheese", u"crisps"]
                    }
                }

        other_version =  WinnowVersion.add_doc(self.db, other_dict, {})
        merged_version = WinnowVersion.merged(self.db, BASE_PRODUCT, {}, self.base_version, other_version)
        third_version =  WinnowVersion.add_doc(self.db, third_dict, {})
        merged_again = WinnowVersion.merged(self.db, merged_version.get_doc(), {}, merged_version, third_version)
        size = merged_again.get_doc()["options"]["size"]

        self.assertTrue(isinstance(size, dict))
        self.assertEqual(size["type"],"exception")
        self.assertEqual(size["values"], [[u'big', u'small'], u'medium'])
Beispiel #18
0
    def test_allows_subset_with_an_extra_key(self):

        configured_option = deepcopy(BASE_PRODUCT)
        configured_option[u"options"][u"wheels"] = [u"big", u"small"]
        configured_version = WinnowVersion.add_doc(self.db, configured_option, {})


        self.assertTrue(winnow.allows(self.base_version, configured_version))
        self.assertTrue(self.base_version.allows(configured_version))
Beispiel #19
0
    def test_allows_subset_with_an_extra_key(self):

        configured_option = deepcopy(BASE_PRODUCT)
        configured_option[u"options"][u"wheels"] = [u"big", u"small"]
        configured_version = WinnowVersion.add_doc(self.db, configured_option,
                                                   {})

        self.assertTrue(winnow.allows(self.base_version, configured_version))
        self.assertTrue(self.base_version.allows(configured_version))
Beispiel #20
0
    def test_match(self):

        configured_product_1 = {u"name": u"cat",
                   u"description": u"This is a very nice table",
                   u"options":{
                        u"color": u"red",
                        u"size": u"big"
                   }
        }


        configured_product_2 = {u"name": u"dog",
                   u"description": u"This is a very nice table",
                   u"options":{
                        u"color": u"red",
                   }
        }


        configured_product_3 = {u"name": u"fish",
                   u"description": u"This is a very nice table",
                   u"options":{
                        u"color": u"red",
                        u"size": u"old"
                   }
        }

        configured_product_4 = {u"name": u"goat",
                   u"description": u"This is a very nice table",
                   u"options":{
                        u"color": [u"red", u"green"],
                        u"size": u"small"
                   }
        }

        possible = [WinnowVersion.add_doc(self.db, configured_product_1, {}),
                   WinnowVersion.add_doc(self.db, configured_product_2, {}),
                   WinnowVersion.add_doc(self.db, configured_product_3, {}),
                   WinnowVersion.add_doc(self.db, configured_product_4, {})]

        found = self.base_version.filter_allows(possible)

        self.assertEqual(set([f.kwargs[u"doc"][u"name"] for f in found]), set([u'cat', u'dog', u'goat']))
Beispiel #21
0
def get_manufacturing_choices(db, manufacturing_spec, maker_id):

    context_paths = get_maker_contexts(maker_id)
    merged = manufacturing_spec

    for context_path in context_paths:
        context = WinnowVersion.get_from_path(db, context_path)
        merged = merged.merged(context)

    scoped = merged.scoped([u"maker"])
    return scoped
Beispiel #22
0
def get_manufacturing_choices(db, manufacturing_spec, maker_id):

    context_paths = get_maker_contexts(maker_id)
    merged = manufacturing_spec

    for context_path in context_paths:
        context = WinnowVersion.get_from_path(db, context_path)
        merged = merged.merged(context)

    scoped = merged.scoped([u"maker"])
    return scoped
Beispiel #23
0
    def setUp(self):
        self.db = MockKVStore()

        self.dog_base_choices = {
            "type": "choices",
            "path": "/choices/dog_choices",
            "options":{
                "colours": ["brown", "red", "white"],
            }
        }

        breed1 = {
            "type": "dog",
            "path": "/breeds/collie",
            "options":{
                "colours": "$ref:/choices/dog_choices#/options/colours",
                "size": ["big", "small"]
            }
        }

        breed2 = {
            "type": "dog",
            "path": "/breeds/sausage",
            "options":{
                "colours": "$ref:/choices/dog_choices#/options/colours"
            }
        }


        WinnowVersion.add_doc(self.db, self.dog_base_choices, {})
        WinnowVersion.add_doc(self.db, breed1, {})
        WinnowVersion.add_doc(self.db, breed2, {})
Beispiel #24
0
    def test_expand_key_hash_creation_2(self):

        breed1 = WinnowVersion.get_from_path(self.db, "/breeds/collie")

        kwargs={}
        expanded = breed1.__class__(breed1.db, kwargs)
        ref_hashes = winnow.expand(breed1, expanded)
        breed1.db.set(expanded.kwargs[u"uuid"], expanded.kwargs)
        value = u"$ref:/choices/dog_choices#/options/colours"
        colour_options = self.dog_base_choices["options"]["colours"]
        hash = winnow.utils.get_doc_hash(winnow.utils.json_dumps(colour_options))

        self.assertEqual(ref_hashes.get(hash), value)
Beispiel #25
0
def get_default_product_options(db, product_path, session_id):

    context_paths = get_customer_contexts(session_id)
    product = WinnowProduct.get_from_path(db, product_path)

    expanded = product.expanded() # no need to save this

    for context_path in context_paths:
        context = WinnowVersion.get_from_path(db, context_path)
        expanded = expanded.merged(context)

    scoped = expanded.scoped(u"customer")
    quantified = scoped.quantified()

    return quantified
Beispiel #26
0
def get_default_product_options(db, product_path, session_id):

    context_paths = get_customer_contexts(session_id)
    product = WinnowProduct.get_from_path(db, product_path)

    expanded = product.expanded()  # no need to save this

    for context_path in context_paths:
        context = WinnowVersion.get_from_path(db, context_path)
        expanded = expanded.merged(context)

    scoped = expanded.scoped(u"customer")
    quantified = scoped.quantified()

    return quantified
Beispiel #27
0
    def test_disallowed(self):


        SIZE_2 = {u"name": u"table",
                    u"description": u"This is a very nice table",
                    u"options":{
                        u"size": size_2,
                    }
                }

        SIZE_1 = {u"name": u"choice",
                    u"options":{
                        u"size": size_1,
                    }
                }

        table = WinnowVersion.add_doc(self.db, SIZE_2, {})
        choice = WinnowVersion.add_doc(self.db, SIZE_1, {})

        disallowed = winnow.disallowed_keys(choice, table)

        print disallowed

        self.assertEqual(len(disallowed), 0)
Beispiel #28
0
    def test_unexpand(self):

        breed1 = WinnowVersion.get_from_path(self.db, "/breeds/collie")

        ref_hashes = {}
        expanded_doc = deepcopy(breed1.get_doc())

        winnow.inline.inline_refs(expanded_doc, expanded_doc, breed1, ref_hashes)

        ref_value = u"$ref:/choices/dog_choices#/options/colours"
        colour_options = self.dog_base_choices["options"]["colours"]
        hash = winnow.utils.get_doc_hash(winnow.utils.json_dumps(colour_options))
        self.assertEqual(ref_hashes.get(hash), ref_value)
        self.assertEqual(expanded_doc["options"]["colours"], ["brown", "red", "white"])
        winnow.inline.restore_unchanged_refs(expanded_doc, ref_hashes)
        self.assertEqual(expanded_doc["options"]["colours"], ref_value)
Beispiel #29
0
def get_quantified_configuration(db, product_path, choices):

    doc = {
        "schema": "https://opendesk.cc/schemata/options.json",
        "type": "choice",
        "name": "paul's choices",
        "options":choices
    }

    choice_document = WinnowVersion.add_doc(db, doc)

    product = WinnowProduct.get_from_path(db, product_path)

    qc_doc = deepcopy(product.get_doc())
    product_doc = product.get_doc()

    version = product_doc["version"]

    qc_doc[u"type"] = "quantified_configuration"
    qc_doc[u"schema"] = "https://opendesk.cc/schemata/options.json"
    qc_doc[u"product"] = "%s@%s.%s.%s" % (product_doc["path"], version[0], version[1], version[2])

    return WinnowQuantifiedConfiguration.merged(db, qc_doc, {}, product, choice_document)
Beispiel #30
0
    def test_valid_sieve(self):

        version = WinnowVersion.add_doc(self.db, BASE_PRODUCT, {})
Beispiel #31
0
    def add_doc_at_data_path(self, path):

        with open(os.path.join(DATA_DIR, path), "r") as f:
            as_dict = json.loads(f.read())

        return WinnowVersion.add_doc(self.db, as_dict, {})
Beispiel #32
0
    def test_does_a_merge(self):

        other_dict =  {u"name": u"something",
                        u"description": u"these are other options",
                        u"options":{
                            u"color": [u"red", u"blue"],
                            u"size": [u"medium"],
                            u"tool": [u"cnc", u"laser", u"plaster"],
                            u"days": [u"tuesday", u"thursday"],
                            u"drinks": [u"beer", u"coffee"],
                            u"snacks": [u"crisps", u"cheese", u"apple"]
                        }
                    }

        expected =  {u"name": u"table",
                    u"description": u"This is a very nice table",
                    u"options":{
                        u"color": [u"blue", u"red"],
                        u"size": [u"big", u"small"],
                        u"tool": [u"cnc", u"laser"],
                        u"material": [u"metal", u"plastic", u"wood"],
                        u"days": [u"thursday", u"tuesday"],
                        u"drinks": [u"beer", u"coffee"],
                        u"snacks": [u"apple", u"cheese", u"crisps"]
                    }
                }

        other_version =  WinnowVersion.add_doc(self.db, other_dict, {})
        merged = WinnowVersion.merged(self.db, BASE_PRODUCT, {}, self.base_version, other_version)

        size = merged.get_doc()["options"]["size"]

        self.assertTrue(isinstance(size, dict))
        self.assertEqual(size["type"],"exception")
        self.assertEqual(size["values"], [[u'big', u'small'], u'medium'])

        self.assertTrue("errors" in merged.get_doc())

        print json.dumps(merged.get_doc()["errors"], indent=4)

        expected_error = [
    [
        {
            "values": [
                [
                    "big",
                    "small"
                ],
                "medium"
            ],
            "type": "exception",
            "context": {
                "source_b": {
                    "description": "these are other options",
                    "options": {
                        "snacks": [
                            "crisps",
                            "cheese",
                            "apple"
                        ],
                        "color": [
                            "red",
                            "blue"
                        ],
                        "tool": [
                            "cnc",
                            "laser",
                            "plaster"
                        ],
                        "days": [
                            "tuesday",
                            "thursday"
                        ],
                        "drinks": [
                            "beer",
                            "coffee"
                        ],
                        "size": [
                            "medium"
                        ]
                    },
                    "name": "something"
                },
                "source_a": {
                    "description": "This is a very nice table",
                    "options": {
                        "color": [
                            "red",
                            "green",
                            "blue"
                        ],
                        "tool": [
                            "cnc",
                            "laser"
                        ],
                        "material": [
                            "wood",
                            "metal",
                            "plastic"
                        ],
                        "size": [
                            "big",
                            "small"
                        ]
                    },
                    "name": "table"
                }
            },
            "key": "size"
        }
    ]
]
Beispiel #33
0
 def setUp(self):
     self.db = MockKVStore()
     self.base_version = WinnowVersion.add_doc(self.db, BASE_PRODUCT, {})
Beispiel #34
0
 def test_allows_fails(self):
     configured_option = deepcopy(BASE_PRODUCT)
     configured_option[u"options"][u"color"] = u"purple"
     configured_version = WinnowVersion.add_doc(self.db, configured_option, {})
     self.assertFalse(winnow.allows(self.base_version, configured_version))
     self.assertFalse(self.base_version.allows(configured_version))
Beispiel #35
0
    def test_allows_subset_without_a_key(self):

        configured_option = deepcopy(BASE_PRODUCT)
        del configured_option[u"options"][u"color"]
        configured_version = WinnowVersion.add_doc(self.db, configured_option, {})
        self.assertTrue(winnow.allows(configured_version, self.base_version))
Beispiel #36
0
 def setUp(self):
     self.db = MockKVStore()
     self.base_version = WinnowVersion.add_doc(self.db, BASE_PRODUCT, {})
Beispiel #37
0
    def test_does_a_merge(self):

        other_dict = {
            u"name": u"something",
            u"description": u"these are other options",
            u"options": {
                u"color": [u"red", u"blue"],
                u"size": [u"medium"],
                u"tool": [u"cnc", u"laser", u"plaster"],
                u"days": [u"tuesday", u"thursday"],
                u"drinks": [u"beer", u"coffee"],
                u"snacks": [u"crisps", u"cheese", u"apple"]
            }
        }

        expected = {
            u"name": u"table",
            u"description": u"This is a very nice table",
            u"options": {
                u"color": [u"blue", u"red"],
                u"size": [u"big", u"small"],
                u"tool": [u"cnc", u"laser"],
                u"material": [u"metal", u"plastic", u"wood"],
                u"days": [u"thursday", u"tuesday"],
                u"drinks": [u"beer", u"coffee"],
                u"snacks": [u"apple", u"cheese", u"crisps"]
            }
        }

        other_version = WinnowVersion.add_doc(self.db, other_dict, {})
        merged = WinnowVersion.merged(self.db, BASE_PRODUCT, {},
                                      self.base_version, other_version)

        size = merged.get_doc()["options"]["size"]

        self.assertTrue(isinstance(size, dict))
        self.assertEqual(size["type"], "exception")
        self.assertEqual(size["values"], [[u'big', u'small'], u'medium'])

        self.assertTrue("errors" in merged.get_doc())

        print json.dumps(merged.get_doc()["errors"], indent=4)

        expected_error = [[{
            "values": [["big", "small"], "medium"],
            "type": "exception",
            "context": {
                "source_b": {
                    "description": "these are other options",
                    "options": {
                        "snacks": ["crisps", "cheese", "apple"],
                        "color": ["red", "blue"],
                        "tool": ["cnc", "laser", "plaster"],
                        "days": ["tuesday", "thursday"],
                        "drinks": ["beer", "coffee"],
                        "size": ["medium"]
                    },
                    "name": "something"
                },
                "source_a": {
                    "description": "This is a very nice table",
                    "options": {
                        "color": ["red", "green", "blue"],
                        "tool": ["cnc", "laser"],
                        "material": ["wood", "metal", "plastic"],
                        "size": ["big", "small"]
                    },
                    "name": "table"
                }
            },
            "key": "size"
        }]]
Beispiel #38
0
    def test_valid_sieve(self):

        version = WinnowVersion.add_doc(self.db, BASE_PRODUCT, {})