Пример #1
0
 def __init__(self, level):
     self.level = level
     self.inventory = Inventory(self)
     self.x_dim = 0
     self.y_dim = 0
     self.cells = []
     self.cells_dict = {
     }  # {0: {0: <cell>, 1: <cell>}, 1: {0: <cell>, 1: <cell>},...}
     self.path = MapPath(self)
     self.enter_cell = None
     self.exit_cell = None
Пример #2
0
    def test_integration_main(self):
        blanket = Inventory(100, "blanket", 300, 100)
        blanket_details = blanket.return_as_dictionary()

        chair = Furniture(200, "chair", 200, 50, "Plastic", "S")
        chair_details = chair.return_as_dictionary()

        monitor = ElectricAppliance(300, "IPS Monitor", 500, 50, "Asus", 220)
        monitor_details = monitor.return_as_dictionary()

        self.assertEqual(100, blanket_details["product_code"])
        self.assertEqual(200, chair_details["product_code"])
        self.assertEqual(300, monitor_details["product_code"])
Пример #3
0
class GetHandler:

    def __init__(self, request):
        self.alerts = Alerts()
        self.inventory = Inventory()
        self.request = request

    def create_http_response(self):
        return HttpResponse(template.render(self.create_context(), self.request))

    def handle_get_request(self):
        pass

    def create_context(self):
        return {'alerts': self.get_alerts(), 'cve_search_url': config.get_cve_search_url()}

    def get_alerts(self):
        alerts = self.alerts.get_alerts()
        for alert in alerts:
            self.add_cpe_to_alert(alert)
            format_alert_log(alert)
        return alerts

    def add_cpe_to_alert(self, alert):
        sw = self.inventory.get_software_by_id(alert.get('software_id'))
        if sw is not None:
            alert.update({'uri': sw.get('cpe').get('uri_binding')})
            alert.update({'product': sw.get('product')})
            alert.update({'vendor': sw.get('vendor')})
            alert.update({'version': sw.get('version')})
        else:
            alert.update({'product': 'product was removed from database'})
Пример #4
0
    def test_insert_new_software_products_to_db(self):
        item = copy(NEW_SOFTWARE_1)
        item.update({'id': self.generate_expected_software_id(item)})
        self.inventory_collection.insert_one(item)

        item = copy(NEW_SOFTWARE_2)
        item.update({'id': self.generate_expected_software_id(item)})
        self.inventory_collection.insert_one(item)

        item = copy(NEW_SOFTWARE_3)
        item.update({'id': self.generate_expected_software_id(item)})
        self.inventory_collection.insert_one(item)

        with patch('config.get_database_host', return_value=DB_HOST):
            with patch('config.get_database_port', return_value=DB_PORT):
                with patch('config.get_database_name',
                           return_value=IVA_DB_NAME):
                    with patch('config.is_database_authentication_enabled',
                               return_value=False):
                        with patch('inventory.glpi_inventory.read_inventory',
                                   return_value=GLPI_DB_ITEMS):
                            self.assertEqual(3,
                                             self.inventory_collection.count())
                            Inventory().insert_new_software_products_to_db()
                            self.assertEqual(5,
                                             self.inventory_collection.count())
Пример #5
0
class InventoryWithExistingProductTest(TestCase):
    def setUp(self):
        repository = load_inmemoryrepository_with_existing_products()
        self.inventory = Inventory(repository=repository)

    def test_getproduct_returns_existing_product(self):
        expected_product_id = 1
        returned_product = self.inventory.get_product(
            whose='id', equals=expected_product_id)
        self.assertEqual(expected_product_id, returned_product.id)

    def test_getproduct_using_name_field_returns_existing_product(self):
        expected_product_id = 1
        returned_product = self.inventory.get_product(
            whose='name', equals='Existing Product')
        self.assertEqual(expected_product_id, returned_product.id)

    def test_exception_raised_if_getproduct_match_more_than_one_product(self):
        with self.assertRaises(LookupError):
            self.inventory.get_product(whose='name',
                                       equals='Duplicated Product')
class GetHandler:
    def __init__(self, request):
        self.cpe_inventory = SoftwareCPE()
        self.request = request
        self.inventory = Inventory()

    def create_http_response(self):
        context = self.create_context()
        return HttpResponse(template.render(context, self.request))

    def create_context(self):
        return {
            'inventory':
            self.inventory.get_software_products_with_assigned_cpe()
        }
Пример #7
0
class PostHandler:
    def __init__(self, request):
        self.sw_cpe = SoftwareCPE()
        self.wfn_converter = WFNConverter()
        self.inventory = Inventory()
        self.request = request
        self.decoder = Decoder()

    def handle_request(self):
        if not self.request.POST.get('check'):
            sw_cpe_dict = self.sw_cpe.create_sw_cpe_dict(self.get_wfn())
            self.sw_cpe.assign_cpe_to_software(sw_cpe_dict,
                                               self.get_software_id())
            return self.create_http_response_for_add_cpe(sw_cpe_dict)
        return self.create_http_response_for_verify_cpe_exists()

    def get_wfn(self):
        return self.wfn_converter.create_wfn_from_user_input(self.request.POST)

    def get_software_id(self):
        return self.request.POST.get('software_id')

    def create_http_response_for_verify_cpe_exists(self):
        uri = self.wfn_converter.convert_wfn_to_uri(self.get_wfn())
        software = self.sw_cpe.get_software_cpe_by_uri(uri)
        if software is not None:
            return JsonResponse({
                'result':
                'exist',
                'uri_binding':
                self.decoder.decode_non_alphanumeric_characters(uri)
            })
        return JsonResponse({
            'result':
            'not_exist',
            'uri_binding':
            self.decoder.decode_non_alphanumeric_characters(uri)
        })

    def create_http_response_for_add_cpe(self, cpe_doc):
        return HttpResponse(
            software_cpe_template.render(
                {
                    'inventory':
                    self.inventory.get_software_products_with_assigned_cpe(),
                    'updated':
                    cpe_doc.get('uri_binding')
                }, self.request))
Пример #8
0
    def __init__(self):
        super().__init__()

        w = int(self.screen.get_width() / 1.7)
        h = convert.scale_h([5504, 3808], w)
        x = int(self.screen.get_width() / 2 - w / 2)
        y = int(self.screen.get_height() / 2 - h / 2)
        self.platform_rect = [x, y, w, h]

        self.player = Player(
            self.screen,
            [self.platform_rect[0], self.platform_rect[1], 25, 25],
            self.platform_rect,
            150,
            name='player',
            save_entity=False)

        self.inventory = Inventory()
        self.inventory_display = InventoryDisplay(self.screen, [self.player])
        self.inventory_open = False
Пример #9
0
class CVEMatches:
    def __init__(self):
        self.inventory = Inventory()
        self.alerts = Alerts()
        self.db = Database()

    def insert_software_cve_matches(self, software_id, matches):
        new_matches = []
        matches = format_matches(matches)
        for old_match in self.get_software_cve_matches(software_id):
            is_match = False
            for match in matches:
                if old_match.get('cve_id') == match.get('cve_id'):
                    new_matches.append(old_match)
                    matches.remove(match)
                    is_match = True
                    break
            if not is_match:
                self.remove_old_cve_match_from_alert(old_match, software_id)
        new_matches.extend(matches)
        sw = self.inventory.get_software_by_id(software_id)
        self.update_matches_in_db(
            software_id,
            sort_cve_matches_by_version(new_matches, get_sw_version(sw)))

    def remove_old_cve_match_from_alert(self, old_match, software_id):
        if is_cve_match_positive(old_match):
            self.alerts.remove_cve_from_alert(software_id,
                                              old_match.get('cve_id'))

    def add_new_cve_match_to_software(self, software_id, new_match):
        cve_matches = self.get_software_cve_matches(software_id)
        self.update_matches_in_db(
            software_id,
            add_new_match_to_list(cve_matches, format_match(new_match)))

    def set_cve_matches_group_as_removed(self, software_id, cve_id_master):
        group = self.get_software_cve_matches_with_same_cpe_entries_as_cve(
            software_id, cve_id_master)
        for match in group:
            self.set_cve_match_as_removed(software_id, match.get('cve_id'))

    def set_cve_match_as_removed(self, software_id, cve_id):
        self.update_cve_match_status(software_id, cve_id, 'removed', 1)

    def restore_cve_matches_group(self, software_id, cve_id_master):
        group = self.get_software_cve_matches_with_same_cpe_entries_as_cve(
            software_id, cve_id_master)
        for match in group:
            self.restore_cve_match(software_id, match.get('cve_id'))

    def restore_cve_match(self, software_id, cve_id):
        self.update_cve_match_status(software_id, cve_id, 'removed', 0)

    def set_cve_matches_group_as_positive(self, software_id, cve_id_master):
        group = self.get_software_cve_matches_with_same_cpe_entries_as_cve(
            software_id, cve_id_master)
        for match in group:
            self.set_cve_match_as_positive(software_id, match.get('cve_id'))

    def set_cve_match_as_positive(self, software_id, cve_id):
        self.update_cve_match_status(software_id, cve_id, 'positive', 1)
        self.alerts.insert_alert(software_id, cve_id)

    def set_cve_matches_group_as_negative(self, software_id, cve_id_master):
        group = self.get_software_cve_matches_with_same_cpe_entries_as_cve(
            software_id, cve_id_master)
        for match in group:
            self.set_cve_match_as_negative(software_id, match.get('cve_id'))

    def set_cve_match_as_negative(self, software_id, cve_id):
        self.update_cve_match_status(software_id, cve_id, 'positive', 0)
        self.alerts.remove_cve_from_alert(software_id, cve_id)

    def update_cve_match_status(self, software_id, cve_id, field, status):
        matches = self.get_software_cve_matches(software_id)
        for match in matches:
            if match.get('cve_id') == cve_id:
                match.update({field: status})
                self.update_matches_in_db(software_id, matches)
                break

    def get_software_cve_matches_with_same_cpe_entries_as_cve(
            self, software_id, cve_id):
        cve_matches = self.get_software_cve_matches(software_id)
        cve_match_a = get_cve_match_from_matches(cve_id, cve_matches)
        matches_with_same_cpes = []
        for cve_match_b in cve_matches:
            if equal_removed_and_positive_status(cve_match_a, cve_match_b):
                if equal_cpe_entries(get_cpe_entries_from_cve(cve_match_a),
                                     get_cpe_entries_from_cve(cve_match_b)):
                    matches_with_same_cpes.append(cve_match_b)
        return matches_with_same_cpes

    def get_software_cve_matches(self, software_id):
        software = self.get_software(software_id)
        return get_sw_cve_matches(software)

    def get_vulnerable_software_items(self):
        vulnerable_software = []
        for software in self.get_software_items():
            if is_vulnerable(software):
                vulnerable_software.append(software)
        return vulnerable_software

    def exist_cve_matches_for_software(self, software_id):
        return len(self.get_software_cve_matches(software_id)) > 0

    def get_software_items(self):
        return self.db.get_documents_from_collection(INVENTORY_DB_COLLECTION)

    def remove_software_cve_matches(self, software_id):
        self.update_matches_in_db(software_id, [])

    def update_matches_in_db(self, software_id, matches):
        self.db.update_document_in_collection({'id': software_id},
                                              {'cve_matches': matches},
                                              INVENTORY_DB_COLLECTION)

    def get_software(self, software_id):
        return self.db.search_document_in_collection({'id': software_id},
                                                     INVENTORY_DB_COLLECTION)

    def get_cve_matches(self, filters=None):
        cve_matches = []
        for software in self.inventory.get_inventory():
            append_software_matches_to_list(software, cve_matches)
        return filter_matches(filters, cve_matches)

    def get_vendor_product_cve_matches(self,
                                       vendor='all',
                                       product='all',
                                       filters=None):
        if vendor != 'all':
            cve_matches = []
            for software in self.inventory.get_inventory():
                if is_vendor_and_product(vendor, product, software):
                    append_software_matches_to_list(software, cve_matches)
            return filter_matches(filters, cve_matches)
        return self.get_cve_matches(filters)
Пример #10
0
 def __init__(self, request):
     self.sw_cpe = SoftwareCPE()
     self.wfn_converter = WFNConverter()
     self.inventory = Inventory()
     self.request = request
     self.decoder = Decoder()
Пример #11
0
 def setUp(self):
     self.product = Product(name='foo', price=100)
     self.inventory = Inventory(repository=InMemoryRepository())
Пример #12
0
def number_new_glpi_items():
    return len(Inventory().get_software_products_without_assigned_cpe())
Пример #13
0
def get_software_products():
    return Inventory().get_software_products_with_assigned_cpe()
Пример #14
0
 def __init__(self):
     self.inventory = Inventory()
     self.alerts = Alerts()
     self.db = Database()
Пример #15
0
class CVEMatcher:
    def __init__(self):
        self.db = Database()
        self.wfn_converter = WFNConverter()
        self.inventory = Inventory()

    def search_cves_for_cpe(self, uri_binding):
        wfn = self.wfn_converter.convert_cpe_uri_to_wfn(uri_binding)
        matches_a = self.search_cves(wfn)
        matches_b = self.search_cves_with_summary(wfn)
        merge_lists(matches_a, matches_b)
        return matches_a

    def search_cves(self, wfn):
        cve_matches = []
        for vendor in self.get_vendor_candidates(wfn):
            for product in self.get_product_candidates(wfn):
                tmp_cve_matches = self.search_cves_by_product_and_vendor(
                    product, vendor)
                filtered_matches = filter_cpe_entries_in_cve_matches_by_version(
                    tmp_cve_matches, wfn)
                cve_matches.extend(filtered_matches)
        return cve_matches

    def get_vendor_candidates(self, wfn):
        candidates = []
        wfn_vendor = get_vendor_from_wfn(wfn)
        for v in self.inventory.get_vendors():
            if are_strings_similar(v, wfn_vendor):
                candidates.append(v)
        return candidates

    def get_product_candidates(self, wfn):
        candidates = []
        wfn_product = get_product_from_wfn(wfn)
        for p in self.inventory.get_products():
            if are_strings_similar(p, wfn_product):
                candidates.append(p)
        wfn_vendor = get_vendor_from_wfn(wfn)
        if wfn_vendor in wfn_product:
            candidates.append(
                remove_vendor_from_product(wfn_product, wfn_vendor))
        else:
            candidates.append(
                add_vendor_to_product(wfn_vendor, wfn_product, 'left'))
            candidates.append(
                add_vendor_to_product(wfn_vendor, wfn_product, 'right'))
        return candidates

    def search_cves_by_product_and_vendor(self, product, vendor):
        search_condition = create_search_condition(product, vendor)
        aggregation = create_aggregation(product, vendor)
        return self.db.search_documents_and_aggregate(search_condition,
                                                      aggregation,
                                                      IVA_CVE_COLLECTION)

    def search_cves_with_summary(self, wfn):
        matches = []
        for cve in self.get_cve_without_cpe_entries():
            if is_product_and_vendor_in_cve_summary(cve, wfn):
                matches.append(cve)
        return matches

    def get_cve_without_cpe_entries(self):
        return self.db.search_documents_in_collection(
            {'cpe_entries': {
                '$size': 0
            }}, IVA_CVE_COLLECTION)
Пример #16
0
class Map(object):
    """The map that a player will navigate."""
    def __init__(self, level):
        self.level = level
        self.inventory = Inventory(self)
        self.x_dim = 0
        self.y_dim = 0
        self.cells = []
        self.cells_dict = {
        }  # {0: {0: <cell>, 1: <cell>}, 1: {0: <cell>, 1: <cell>},...}
        self.path = MapPath(self)
        self.enter_cell = None
        self.exit_cell = None

    def __build_cells(self, x_dim, y_dim):
        """Build collection of cells based on x and y dimensions."""

        for x in range(x_dim):
            if x not in self.cells_dict:
                self.cells_dict[x] = {}
            for y in range(y_dim):
                if y not in self.cells_dict[x]:
                    cell = MapCell(self, x, y)
                    self.cells_dict[x][y] = cell
                    self.cells.append(cell)

    def build(self):
        """Build the map from the config for the provided level number."""

        tool_factory = ToolFactory()
        part_factory = PartFactory()
        artifact_factory = ArtifactFactory()

        map_config = level_config[self.level.number]['map']

        self.x_dim = map_config['x_dimension']
        self.y_dim = map_config['y_dimension']
        enter_coord = map_config['coord_enter']
        exit_coord = map_config['coord_exit']

        self.__build_cells(self.x_dim, self.y_dim)

        self.enter_cell = self.get_cell(*enter_coord)
        self.exit_cell = self.get_cell(*exit_coord)

        for path_cell_config in map_config['path_cells']:
            path_cell = self.get_cell(*path_cell_config['coordinates'])
            path_cell.story = path_cell_config['story']
            self.path.add_cell(path_cell)

        for system_interface in self.level.system.interfaces:
            interface_cell = self.get_cell(*system_interface.location)
            interface_cell.add_interface(system_interface)

        for system_device in self.level.system.devices:
            device_cell = self.get_cell(*system_device.location)
            device_cell.add_device(system_device)

        for tool_config in map_config['tools']:
            new_tool = tool_factory.make_from_config(self, tool_config)
            self.inventory.add_item(new_tool)

        for part_config in map_config['parts']:
            new_part = part_factory.make_from_config(self, part_config)
            self.inventory.add_item(new_part)

        for artifact_config in map_config['artifacts']:
            new_artifact = artifact_factory.make_from_config(
                self, artifact_config)
            self.inventory.add_item(new_artifact)

        for map_tool in self.inventory.get_tools():
            tool_cell = self.get_cell(*map_tool.location)
            tool_cell.add_tool(map_tool)

        for map_part in self.inventory.get_parts():
            part_cell = self.get_cell(*map_part.location)
            part_cell.add_part(map_part)

        for map_artifact in self.inventory.get_artifacts():
            artifact_cell = self.get_cell(*map_artifact.location)
            artifact_cell.add_artifact(map_artifact)

    @property
    def interfaces(self):
        """Interfaces from all map cells"""

        return [i for c in self.cells for i in c.interfaces]

    @property
    def devices(self):
        """Devices from all map cells"""

        return [d for c in self.cells for d in c.devices]

    @property
    def components(self):
        """Components from all map cells."""

        return [o for c in self.cells for o in c.components]

    @property
    def tools(self):
        """Tools from all map cells"""

        return [t for c in self.cells for t in c.tools]

    @property
    def parts(self):
        """Parts from all map cells"""

        return [p for c in self.cells for p in c.parts]

    @property
    def artifacts(self):
        """Artifacts from all map cells"""

        return [a for c in self.cells for a in c.artifacts]

    @property
    def items(self):
        """Items from all map cells."""

        return [i for c in self.cells for i in c.items]

    def get_cell(self, x, y):
        """Return the cell at the provided coordinates if it exists, otherwise None."""

        try:
            return self.cells_dict[x][y]
        except KeyError:
            return None

    def get_d4_cells(self, x, y):
        """Return the cells above, right, below, and left of the provided coordinates."""

        d4_cells = []
        d4_coords = [(x, y - 1), (x + 1, y), (x, y + 1), (x - 1, y)]

        for coord in d4_coords:
            d4_cells.append(self.get_cell(*coord))
        return d4_cells

    def get_d4_interfaces(self, x, y):
        """Return the interfaces for the d4 cells around the provided coordinates."""

        d4_interfaces = []
        for cell in self.get_d4_cells(x, y):
            if isinstance(cell, MapCell):
                d4_interfaces.append(cell.interfaces)
            else:
                d4_interfaces.append([])
        return d4_interfaces

    def get_d4_devices(self, x, y):
        """Return the devices for the d4 cells around the provided coordinates."""

        d4_devices = []
        for cell in self.get_d4_cells(x, y):

            if isinstance(cell, MapCell):
                d4_devices.append(cell.devices)
            else:
                d4_devices.append([])

        return d4_devices

    def get_d4_components(self, x, y):
        """Return the components for the d4 cells around the provided coordinates."""

        d4_interfaces = self.get_d4_interfaces(x, y)
        d4_devices = self.get_d4_devices(x, y)
        d4_components = [
            items[0] + items[1] for items in zip(d4_interfaces, d4_devices)
        ]
        return d4_components

    def get_d4_tools(self, x, y):
        """Return the tools for the d4 cells around the provided coordinates."""

        d4_tools = []
        for cell in self.get_d4_cells(x, y):
            if isinstance(cell, MapCell):
                d4_tools.append(cell.tools)
            else:
                d4_tools.append([])
        return d4_tools

    def get_d4_parts(self, x, y):
        """Return the tools for the d4 cells around the provided coordinates."""

        d4_parts = []
        for cell in self.get_d4_cells(x, y):
            if isinstance(cell, MapCell):
                d4_parts.append(cell.parts)
            else:
                d4_parts.append([])
        return d4_parts

    def get_d4_artifacts(self, x, y):
        """Return the artifacts for the d4 cells around the provided coordinates."""

        d4_artifacts = []
        for cell in self.get_d4_cells(x, y):
            if isinstance(cell, MapCell):
                d4_artifacts.append(cell.artifacts)
            else:
                d4_artifacts.append([])
        return d4_artifacts

    def get_d4_items(self, x, y):
        """Return the items for the d4 cells around the provided coordinates."""

        d4_tools = self.get_d4_tools(x, y)
        d4_parts = self.get_d4_parts(x, y)
        d4_artifacts = self.get_d4_artifacts(x, y)
        d4_items = [
            items[0] + items[1]
            for items in zip(d4_tools, d4_parts, d4_artifacts)
        ]
        return d4_items
Пример #17
0
 def __init__(self, request):
     self.alerts = Alerts()
     self.inventory = Inventory()
     self.request = request
Пример #18
0
 def __init__(self):
     self.db = Database()
     self.wfn_converter = WFNConverter()
     self.inventory = Inventory()
Пример #19
0
    def __init__(self, screen, entities):
        self.screen = screen
        self.entities = entities  # list with objects
        self.current_entity = -1  # what current entity are we working with
        self.length = 4
        self.margin = int(self.screen.get_width() / 288)
        self.inventory = Inventory()

        # Inventory elements
        # Inventory background
        # 1. Global inventory
        self.inventory_rect = [
            self.screen.get_width() / 2 -
            int(self.screen.get_width() / 3.5 / 2),
            int(self.screen.get_height() / 3),
            int(self.screen.get_width() / 3.5),
            scale_h([1, 1], int(self.screen.get_width() / 3.5))
        ]
        self.page = 0

        # Text and Buttons
        self.button_page_up = Button('>', [
            self.inventory_rect[0] + self.inventory_rect[2],
            self.inventory_rect[1],
            int(self.inventory_rect[2] / 6), self.inventory_rect[3]
        ],
                                     self.screen,
                                     colors=[(105, 105, 105), (169, 169, 169)])
        self.button_page_down = Button('<', [
            self.inventory_rect[0] - int(self.inventory_rect[2] / 6),
            self.inventory_rect[1],
            int(self.inventory_rect[2] / 6), self.inventory_rect[3]
        ],
                                       self.screen,
                                       colors=[(105, 105, 105),
                                               (169, 169, 169)])
        self.page_text = Text(
            self.screen,
            str(self.page + 1), [
                self.inventory_rect[0], self.inventory_rect[1] - 50,
                self.inventory_rect[2], 50
            ],
            font_size=42)
        self.button_delay_1 = time.time() + 0.15
        self.button_delay_2 = time.time() + 0.15
        self.click_delay = time.time() + 0.15

        # 2. Preview
        self.preview_image = None
        self.preview_rect = []

        self.box_width = None
        # slots
        # weapon
        self.weapon_rect = []
        self.weapon_placeholder = None
        self.weapon_equipped = None

        # helmet
        self.helmet_rect = []
        self.helmet_placeholder = None
        self.helmet_equipped = None

        # chestplate
        self.chestplate_rect = []
        self.chestplate_placeholder = None
        self.chestplate_equipped = None

        # boots
        self.boots_rect = []
        self.boots_placeholder = None
        self.boots_equipped = None

        # Center box
        self.center_box = []

        # Grid
        self.grid = []

        self.mouse_down = False

        # Set value to everything
        self.scale()
Пример #20
0
    def add_tabs(self):
        """
        adds new tabs
        """
        global logger
        if ('Inventory', True) in self.access:
            logger.info('initiating Inventory')
            icon = QIcon()
            icon.addPixmap(QPixmap(":/images/inventory.png"), QIcon.Normal,
                           QIcon.Off)
            from inventory.inventory import Inventory

            inventory = Inventory()
            # inventory.inventory_tab_1.setToolTip("Inventory Section")
            self.main_tabWidget.addTab(inventory.inventory_tab_1, icon, "")
            inventory.inventory_detail_tabWidget.setCurrentIndex(0)
        else:
            self.inventory_frame_1.setVisible(False)
        self.progress.setLabelText('Inventory Done....')
        self.progress.setValue(2)

        if ('Billing', True) in self.access:
            logger.info('initiating Billing')
            icon1 = QIcon()
            icon1.addPixmap(QPixmap(":/images/billing.png"), QIcon.Normal,
                            QIcon.Off)
            from billing.billing import Billing

            bill = Billing()
            # bill.billing_tab_2.setToolTip("Billing Section")
            self.main_tabWidget.addTab(bill.billing_tab_2, icon1, "")
            bill.billing_detail_tabWidget.setCurrentIndex(0)
        else:
            self.billing_frame_2.setVisible(False)
        self.progress.setLabelText('Billing Done...')
        self.progress.setValue(3)

        if ('Employee', True) in self.access:
            logger.info('initiating Employee')
            icon2 = QIcon()
            icon2.addPixmap(QPixmap(":/images/employee.png"), QIcon.Normal,
                            QIcon.Off)
            from employee.employee import Employee

            employee = Employee()
            # employee.employee_tab_3.setToolTip("Employee Section")
            self.main_tabWidget.addTab(employee.employee_tab_3, icon2, "")
            employee.employee_detail_tabWidget.setCurrentIndex(0)
        else:
            self.employee_frame_3.setVisible(False)
        self.progress.setLabelText('Employee Done...')
        self.progress.setValue(4)

        if ('Menu', True) in self.access:
            logger.info('initiating Menu')
            icon3 = QIcon()
            icon3.addPixmap(QPixmap(":/images/menu.png"), QIcon.Normal,
                            QIcon.Off)
            from menu.menu import Menu

            menu = Menu()
            # menu.menu_tab_4.setToolTip("Menu Section")
            self.main_tabWidget.addTab(menu.menu_tab_4, icon3, "")
            menu.menu_detail_tabWidget.setCurrentIndex(0)
        else:
            self.menu_frame_4.setVisible(False)
        self.progress.setLabelText('Menu Done....')
        self.progress.setValue(5)

        if ('Report', True) in self.access:
            logger.info('initiating Report')
            icon4 = QIcon()
            icon4.addPixmap(QPixmap(":/images/report.png"), QIcon.Normal,
                            QIcon.Off)
            from report.report import Report

            report = Report()
            # report.report_tab_5.setToolTip("Report Section")
            self.main_tabWidget.addTab(report.report_tab_5, icon4, "")
            report.report_detail_tabWidget.setCurrentIndex(0)
        else:
            self.report_frame_5.setVisible(False)
        self.progress.setLabelText('Report Done....')
        self.progress.setValue(6)

        if ('Waste', True) in self.access:
            logger.info('initiating Waste')
            icon5 = QIcon()
            icon5.addPixmap(QPixmap(":/images/waste.png"), QIcon.Normal,
                            QIcon.Off)
            from waste.waste import Waste

            waste = Waste()
            # waste.waste_tab_6.setToolTip("Waste Section")
            self.main_tabWidget.addTab(waste.waste_tab_6, icon5, "")
            waste.waste_detail_tabWidget.setCurrentIndex(0)
        else:
            self.waste_frame_6.setVisible(False)
        self.progress.setLabelText('Waste Done....')
        self.progress.setValue(7)
 def __init__(self, request):
     self.cpe_inventory = SoftwareCPE()
     self.request = request
     self.inventory = Inventory()
Пример #22
0
 def setUp(self):
     repository = load_inmemoryrepository_with_existing_products()
     self.inventory = Inventory(repository=repository)
Пример #23
0
 def test_inventory(self):
     inv = Inventory("1", "one", "2.99", "rentalprice")
     self.assertEqual("1", inv.return_as_dictionary()["product_code"])
Пример #24
0
class InventoryTest(TestCase):
    def setUp(self):
        self.product = Product(name='foo', price=100)
        self.inventory = Inventory(repository=InMemoryRepository())

    def test_adds_product(self):
        self.inventory.add(self.product)
        self.assertTrue(self.product in self.inventory)

    def test_exception_raised_when_product_not_found(self):
        some_product_id_that_hasnt_been_added = 9999
        with self.assertRaises(LookupError):
            self.inventory.get_product(
                whose='id', equals=some_product_id_that_hasnt_been_added)

    def test_exception_raised_when_attempt_to_add_product_with_id(self):
        self.product.id = 1
        with self.assertRaises(ValueError):
            self.inventory.add(self.product)

    def test_containment_checks_for_product_id(self):
        product_with_identical_data_but_different_id = Product(name='foo',
                                                               price=100)
        self.inventory.add(self.product)
        self.assertFalse(
            product_with_identical_data_but_different_id in self.inventory)

    def test_getproduct_returns_same_product_but_different_object(self):
        product = Product(name='New Product', price=1)
        self.inventory.add(product)
        returned_product = self.inventory.get_product(whose='id',
                                                      equals=product.id)
        self.assertNotEqual(id(returned_product), id(product))

    def test_multiple_insertions_at_once(self):
        products = [
            Product(name='test multiple insertions 1', price=1),
            Product(name='test multiple insertions 2', price=2),
            Product(name='test multiple insertions 3', price=3),
        ]
        self.inventory.add_many(products)
        self.assertTrue(all(product in self.inventory for product in products))

    def test_raise_exception_if_any_product_passed_to_addmany_has_id(self):
        products = [
            Product(name='test multiple insertions 1', price=1),
            Product(name='test multiple insertions 2', price=2, id_=1),
            Product(name='test multiple insertions 3', price=3),
        ]
        with self.assertRaises(ValueError):
            self.inventory.add_many(products)
Пример #25
0
 def get_software(self):
     return Inventory().get_software_by_id(self.software_id)
Пример #26
0
 def get_software(self):
     return Inventory().get_software_by_id(self.request.GET.get('id'))