Example #1
0
class Customer(db.Document):
    cid = db.IntField(unique=True)
    email = db.StringField(max_length=255, unique=True)
    password = db.StringField(max_length=500)
    first_name = db.StringField(max_length=100)
    last_name = db.StringField(max_length=100)
    contact_no = db.IntField(min_value=1000000000, max_value=9999999999)
    address = db.StringField(max_length=500)
    created_on = db.DateTimeField()
    modified_on = db.DateTimeField()
    latest_transaction_cost = db.IntField()
    driving_licence_link = db.URLField()
    QR_CODE_DATA = db.StringField(max_length=200)
    vehicles = db.ListField(
        db.ReferenceField(Vehicle, dbref=False, reverse_delete_rule=NULLIFY))
    transactions = db.ListField(
        db.ReferenceField(Transaction,
                          dbref=False,
                          reverse_delete_rule=NULLIFY))

    def __unicode__(self):
        return str(self.cid)

    def get_dict(self):
        return {
            'cid': self.cid,
            'first_name': self.first_name,
            'last_name': self.last_name,
            'contact_no': self.contact_no,
            'address': self.address,
            'latest_transaction_cost': latest_transaction_cost,
            'driving_licence_link': self.driving_licence_link
        }

    def __repr__(self):
        return 'cid ' + str(self.cid)

    def save(self, *args, **kwargs):
        if self.cid == None:
            try:
                self.cid = self.__class__.objects.order_by('-cid')[0].cid + 1
            except IndexError:
                self.cid = Customer.objects.count() + 1
        if not self.created_on:
            self.created_on = datetime.now()
        self.modified_on = datetime.now()
        self.password = hashlib.sha1(self.password).hexdigest()
        if not self.QR_CODE_DATA:
            self.QR_CODE_DATA = hashlib.sha1(
                str(self.cid) + str(self.created_on)).hexdigest()
        super(Customer, self).save(*args, **kwargs)
Example #2
0
class Action(db.Document, Executable):

    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    name = db.StringField(required=True)
    start_state = db.ReferenceField("State", required=True)
    end_state = db.ReferenceField("State", required=True)
    steps = db.ListField(db.EmbeddedDocumentField(Command), required=False)
    execution_results = []

    def execute(self, driver, config):
        logging.debug("Executing Action %s" % self.name)
        # if not self.start_state.is_state_present(driver):
        #     result =Result(step_results=self.execution_results,passed=False,message="State %s not present" % self.start_state)
        #     result.failed_state = self.start_state
        #     result.actual_state = self.start_state.get_current_state(driver)
        #     result.actual_state.save()
        #     result.html = driver.html
        #     result.screenshot = driver.get_screenshot_as_base64()
        #     return result
        result = Executable.execute(self, driver, config)
        if not result.passed:
            result.failed_state = self.start_state
            result.actual_state = self.start_state.get_current_state(driver)
            result.actual_state.save()
            result.html = driver.html
            result.screenshot = driver.get_screenshot_as_base64()
        return result
Example #3
0
class Result(db.EmbeddedDocument):
    total_indents = 0

    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    passed = db.BooleanField(required=True)
    message = db.StringField(required=True)
    exception = db.StringField(max_length=255, required=False)
    step_results = db.ListField(db.EmbeddedDocumentField('self'))
    failed_state = db.ReferenceField('State', required=False)
    actual_state = db.ReferenceField('State', required=False)
    html = db.StringField(required=False)
    screenshot = db.StringField(required=False)

    def __str__(self):
        Result.total_indents += 1
        message = "Executable Passed=%s %s \r\n" % (self.passed, self.message)
        for result in self.step_results:
            for indent in range(0, Result.total_indents):
                message += " "
            message += str(result)
        Result.total_indents -= 1
        return message

    def __repr__(self):
        return "Result(%s,%s)" % (self.passed, self.message)
Example #4
0
class Orders(db.Document):
    # contact info
    order_number    = db.IntField()
    name            = db.StringField(maxlength=255)
    phone_number    = db.StringField(maxlength=10)

    # cake info
    cake_info       = db.ListField()
    cake_size       = db.StringField(maxlength=255)
    price           = db.IntField()
    flavor_1        = db.StringField(maxlength=255)
    flavor_2        = db.StringField(maxlength=255)
    filling         = db.StringField(maxlength=255)
    sales_category  = db.StringField(maxlength=255, default="cake")

    # delivery info
    date_time       = db.DateTimeField(default=datetime.utcnow())

    # decoration info
    decoration      = db.StringField(maxlength=255)
    print_out       = db.BooleanField(default=False)
    celebrated_name = db.StringField(maxlength=255)
    celebrated_age  = db.IntField()
    celebrated_text = db.StringField(maxlength=255)

    def __repr__(self):
        return "<MongoEngine Document: Orders :: New Cake Order>"
Example #5
0
class ParkingLot(db.Document):
    pid = db.IntField(unique=True)
    parking_lot_name = db.StringField(max_length=100)
    cost = db.ReferenceField(Cost, dbref=False)
    two_wheeler_capacity = db.IntField()
    four_wheeler_capacity = db.IntField()
    heavy_vehicle_capacity = db.IntField()
    current_two_wheeler = db.IntField(default=0)
    current_four_wheeler = db.IntField(default=0)
    current_heavy_vehicle = db.IntField(default=0)
    transactions = db.ListField(
        db.ReferenceField(Transaction,
                          dbref=False,
                          reverse_delete_rule=NULLIFY))

    def __str__(self):
        return "Parking: {} two_wheeler :{}, four_wheeler: {}, heavy_vehicle: {}".format(
            self.parking_lot_name, self.cost.two_wheeler,
            self.cost.four_wheeler, self.cost.heavy_vehicle)

    def get_dict(self):
        return {
            'pid': self.pid,
            'parking_lot_name': self.parking_lot_name,
            'transactions': self.transactions
        }

    def save(self, *args, **kwargs):
        if self.pid == None:
            try:
                self.pid = self.__class__.objects.order_by('-pid')[0].pid + 1
            except IndexError:
                self.pid = ParkingLot.objects.count() + 1
        super(ParkingLot, self).save(*args, **kwargs)
Example #6
0
class Post(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    title = db.StringField(max_length=255, required=True)
    body = db.StringField(required=True)
    comments = db.ListField(db.EmbeddedDocumentField('Comment'))

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }
Example #7
0
class Page(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    url = db.StringField(max_length=255, required=False)
    default_state = db.ReferenceField(State, required=True)
    states = db.ListField(db.ReferenceField(State))

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }
Example #8
0
class User(db.Document, UserMixin):
    email = db.StringField(max_length=255)
    password = db.StringField(max_length=500)
    active = db.BooleanField(default=True)
    confirmed_at = db.DateTimeField()
    roles = db.ListField(db.ReferenceField(Role), default=[])

    def save(self, *args, **kwargs):
        self.password = encrypt_password(self.password)
        self.confirmed_at = datetime.now()

        super(User, self).save(*args, **kwargs)
Example #9
0
class Suite(db.Document, Executable):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    name = db.StringField(max_length=255, required=False)
    url = db.StringField(max_length=255, required=False)
    tests = db.ListField(db.ReferenceField(Test))
    suite_results = db.ListField(db.EmbeddedDocumentField(Result),
                                 required=False)
    suite_config = db.ReferenceField(SuiteConfig, required=False)

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }

    def execute(self, driver, config):
        logging.debug("Executing Suite %s" % self.id)
        self.driver = driver
        suite_result = Result(passed=True,
                              message="Passed",
                              exception="Passed")

        for test in self.tests:
            test_result = test.execute(driver, config)
            suite_result.step_results.append(test_result)
            if not test_result.passed:
                suite_result.passed = False
                suite_result.message = test_result.message
                suite_result.exception = test_result.exception
                suite_result.failed_state = test_result.failed_state
                suite_result.actual_state = test_result.actual_state
                suite_result.html = self.driver.page_source
                suite_result.screenshot = self.driver.get_screenshot_as_base64(
                )

        self.suite_results.append(suite_result)
        self.cascade_save()
        return suite_result
Example #10
0
class SuiteConfig(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    start_after = db.DateTimeField(default=datetime.datetime.now,
                                   required=True)
    configs = db.ListField(db.EmbeddedDocumentField(RunConfig, required=True))

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }

    @staticmethod
    def default():
        suite = SuiteConfig(configs=[RunConfig(browser="Firefox")])
        suite.save()
        return suite
Example #11
0
class FoodCost(db.Document):
    category = db.StringField(maxlength=255)
    menu_item = db.StringField(maxlength=255)
    url = db.StringField(maxlength=255)
    created_on_date = db.StringField(maxlength=255)
    last_updated_on = db.StringField(maxlength=255)
    portions_size = db.StringField(maxlength=255)
    cost_per_portion = db.DecimalField(precision=2)
    sales_price = db.DecimalField(precision=2)
    food_cost_percent = db.StringField()
    recipe_quantity = db.IntField()
    total_recipe_cost = db.DecimalField(precision=2)
    total_gross_sales = db.DecimalField(precision=2)
    ingredients = db.ListField(db.DictField(db.ReferenceField(Ingredient)))

    def __repr__(self):
        return "<MongoEngine Document: FoodCost>"
Example #12
0
class Test(db.Document, Executable):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    name = db.StringField(max_length=255, required=False)
    actions = db.ListField(db.ReferenceField(Action))

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }

    def execute(self, driver, config):
        logging.debug("Executing Test %s" % self.name)
        self.steps = self.actions
        suite_results = Executable.execute(self, driver, config)
        return suite_results

    def get_steps(self):
        return self.actions
Example #13
0
class ElementState(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    html = db.StringField(required=False)
    locators = db.ListField(db.EmbeddedDocumentField(Locator))
    screenshot = db.StringField(required=False)
    location = db.EmbeddedDocumentField(Location, required=False)
    type = db.StringField(required=False)

    def __unicode__(self):
        return self.locators

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }

    def __str__(self):
        repr = "ElementState: "
        for locator in self.locators:
            repr += "{}, ".format(str(locator))
        return repr

    def __eq__(self, other):
        if other is None:
            return False
        for locator in self.locators:
            if locator in other.locators:
                return True
        return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def set_location(self, element):
        self.location = Location(x=element.location['x'],
                                 y=element.location['y'],
                                 width=element.size['width'],
                                 height=element.size['height'])
Example #14
0
class Event(db.Document):
    query_class = EventQuery
    tag = db.StringField()
    name = db.StringField()
    description = db.StringField()
    venue = db.DocumentField(Venue)
    time = db.StringField()
    date = db.StringField()
    image = db.StringField()
    owner = db.DocumentField(User)
    visibility = db.DocumentField(Visibility)
    gests = db.ListField(db.StringField())
    requirement = db.ListField(db.DocumentField(Requirement))
    capacity = db.IntField()

    def hasAccess(self, user):
        log.info(
            "Verificar acceso del Usuario: {'%s'} al Evento con: {'tag':'%s'}"
            % (user, self.tag))
        return self.visibility.isPublic() or (
            user is not None
            and self.owner == user) or user.username in self.gests

    def hasAvailability(self):
        return self.availability() > 0

    def availability(self):
        log.info("Calcular la disponibilidad del Evento con: {'tag':'%s'}" %
                 self.tag)
        return self.capacity - Assistance.query.get_amount_by_event(self.tag)

    def lackRequirements(self):
        log.info(
            "Suma todos los requisitos que los usuarios se comprometieron a llevar al evento."
        )
        lack = []
        requirements = Assistance.query.get_requirements_by_event_tag(self.tag)
        keyfunc = lambda r: r.name

        for req in requirements:
            req.quantity = -req.quantity
        requirements += self.requirement
        requirements.sort(key=keyfunc)

        for name, reqs in groupby(requirements, key=keyfunc):
            lack.append(
                Requirement(name=name,
                            quantity=sum(req.quantity for req in reqs)))
        return lack

    def addGest(self, user):
        self.gests.append(user.username)

    def addGests(self, users):
        self.gests.extend(map(lambda user: user.username))

    def getAppearanceAssistance(self):
        appearance = AssistanceEvent(tag=self.tag,
                                     name=self.name,
                                     venue=self.venue.name,
                                     time=self.time,
                                     date=self.date,
                                     image=self.image)
        return appearance
Example #15
0
class Assistance(db.Document):
    query_class = AssistanceQuery
    eventTag = db.StringField()
    event = db.DocumentField(AssistanceEvent)
    user = db.StringField()
    requirements = db.ListField(db.DocumentField(Requirement))
Example #16
0
class State(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    html = db.StringField(required=False)
    screenshot = db.StringField(required=False)
    elements = db.ListField(db.ReferenceField(ElementState))
    actions = db.ListField(db.ReferenceField(Action))
    init_actions = db.ListField(db.ReferenceField(Action), required=False)
    url = db.StringField(max_length=255, required=True)
    name = db.StringField(max_length=255, required=False)

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at','-url'],
        'ordering': ['-created_at', '-url'],
    }

    def __eq__(self, other):
        if other is None:
            return False
        for element in self.elements:
            if element not in other.elements:
                return False
        return True

    def __sub__(self, other):
        """
        Returns a State representing the difference in elements
        :param other:
        :return:
        """
        new_elements = []
        for element in self.elements:
            if element not in other.elements:
                new_elements.append(element)
        return State(elements=new_elements, url=self.url)

    def __add__(self, other):
        """
        Combines two states together
        :param other:
        :return:
        """
        all_elements = self.elements.extend(other.elements)
        return State(elements=all_elements,url=self.url)

    def __div__(self, other):
        """
        Returns the elements not shared with the second state
        :param other:
        :return:
        """
        new_elements = []
        for element in self.elements:
            if element in other.elements:
                new_elements.append(element)
        return State(elements=new_elements,url=self.url)

    def __repr__(self):
        return "State(url=%s) %s Elements %s" % (self.url, len(self.elements),self.elements)

    def get_web_elements(self, driver):
        webelements = []
        for element in self.elements:
            webelement = WebElement(driver, element.locators)
            webelement.element_state = element
            webelements.append(webelement)
        return webelements

    def verify_state(self,driver):
        logging.debug("Verifying state %s %s" % (self.id, self.url))
        for element in self.elements:
            WebElement(driver,element.locators).highlight()

    def is_state_present(self, driver):
        logging.debug("Is state Present: %s %s" % (self.id, self.url))
        for element in self.elements:
            if not WebElement(driver,element.locators).is_present(5):
                logging.debug("Element not present: %s" % element.locators)
                return False
            else:
                logging.debug("Element is present: %s" % element.locators)
        return True

    def get_missing_elements(self,driver):
        missing_elements = []
        for element in self.elements:
            if not WebElement(driver,element.locators).is_present():
                missing_elements.append(element)
        return missing_elements

    def get_replaced_elements(self,driver, new_state):
        replaced_elements = []
        for element in new_state.elements:
            if element not in self.elements:
                replaced_elements.apppend(element)
        return replaced_elements

    def update_element(self, old_element, new_element):
        self.elements.remove(old_element)
        self.elements.append(new_element)

    def remove_element(self, element):
        self.elements.remove(element)

    def add_element(self, element):
        self.elements.append(element)

    def get_html_info(self):
        self.element_html = []
        for element in self.elements:
            self.element_html.append(element.html)

    def initialize_state(self, driver,config):
        for action in self.init_actions:
            action.execute(driver,config)
        self.verify_state(driver)



    def get_current_state(self, driver):
        try:
            return self.get_state(driver)
        except Exception as e:
            logging.exception(str(e))
            return self.get_state(driver)

    def get_state(self, driver):
        parser = PageParser(driver)
        locator_elements = []
        elements = parser.get_all_elements()
        print "Found %s elements " % len(elements)
        for element in elements:
            builder = LocatorBuilder(driver, element)
            locators = builder.get_locators()
            if(len(locators)) > 0:
                new_element = ElementState(locators=locators, html=element.html[:255], screenshot=element.screenshot_as_base64)
                new_element.set_location(element)
                new_element.save()
                locator_elements.append(new_element)
                WebElement(driver,new_element.locators).highlight()
        screenshot = driver.get_screenshot_as_base64()
        state = State(elements=locator_elements,url=driver.current_url, html=driver.html, screenshot = screenshot)
        return state

    def get_blank_state(self):
        return State.objects(url="").first()