def test_create_restaurant_identity(self): self.set_datastore_hr_probability(1) root_proj = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..') branding_url = os.path.join(root_proj, 'rogerthat-backend', 'src-test', 'rogerthat_tests', 'mobicage', 'bizz', 'nuntiuz.zip') email = u"*****@*****.**" name = u"resto_soluton" service_user = users.User(email) create_service(email=email, name=name, password=u"test1", languages=[u"en"], solution=SOLUTION_FLEX, category_id=None, organization_type=ServiceProfile.ORGANIZATION_TYPE_PROFIT, fail_if_exists=False) solutionSettings = SolutionSettings(key=SolutionSettings.create_key(service_user), name=name, menu_item_color=None, address=u"lochristi", phone_number=None, currency=u"€", main_language=DEFAULT_LANGUAGE, solution=SOLUTION_FLEX) solutionSettings.holidays = [] solutionSettings.holiday_out_of_office_message = u'holiday-out-of-office' settings = RestaurantSettings(key=RestaurantSettings.create_key(service_user)) settings.language = DEFAULT_LANGUAGE stream = StringIO() stream.write(open(branding_url).read()) stream.seek(0) main_branding = SolutionMainBranding(key=SolutionMainBranding.create_key(service_user)) main_branding.blob = db.Blob(stream.read()) main_branding.branding_key = None settings.shifts = Shifts() shift = Shift() shift.name = u'shift-lunch' shift.capacity = 50 shift.max_group_size = 6 shift.leap_time = 30 shift.threshold = 70 shift.start = 12 * 60 * 60 shift.end = 14 * 60 * 60 shift.days = [1, 2, 3, 4, 5, 6, 7] shift.comment = u'shift-comment0' settings.shifts.add(shift) shift = Shift() shift.name = u'shift-dinner' shift.capacity = 50 shift.max_group_size = 6 shift.leap_time = 30 shift.threshold = 70 shift.start = 18 * 60 * 60 shift.end = 21 * 60 * 60 shift.days = [1, 2, 3, 4, 5, 6, 7] shift.comment = u'shift-comment1' settings.shifts.add(shift) put_and_invalidate_cache(solutionSettings, settings, main_branding) date_ = datetime.datetime.combine(datetime.date.today() + datetime.timedelta(days=10), datetime.datetime.min.time()) date_ = date_ + datetime.timedelta(hours=19) today_ = get_epoch_from_datetime(date_) service_identity = None user_detail = UserDetailsTO.fromUserProfile(get_user_profile(users.get_current_user())) reservationOkKey, reservationOk = \ self._test_reserve_table(service_user, service_identity, user_details=[user_detail], date=today_, people=3, name=u"text Name", phone=None, comment=u"comment", force=False) reservationTooMany = self._test_reserve_table(service_user, service_identity, user_details=[user_detail], date=today_, people=50, name=u"text Name", phone=None, comment=u"comment", force=False) self.assertEqual(STATUS_AVAILABLE, reservationOk) self.assertEqual(STATUS_TOO_MANY_PEOPLE, reservationTooMany) editReservationOk = edit_reservation(service_user, reservationOkKey, people=4, comment=None, force=False) self.assertEqual(STATUS_AVAILABLE, editReservationOk) cancel_reservation(service_user, reservationOkKey, notified=False) move_reservation(service_user, None, reservationOkKey, u'shift-lunch')
def create_solution_service(email, name, branding_url=None, menu_item_color=None, address=None, phone_number=None, solution=None, languages=None, currency=u"€", category_id=None, organization_type=1, fail_if_exists=True, modules=None, broadcast_types=None, apps=None, owner_user_email=None, search_enabled=False): password = unicode(generate_random_key()[:8]) if languages is None: languages = [DEFAULT_LANGUAGE] if menu_item_color == "branding": menu_item_color = None elif menu_item_color: try: parse_color(menu_item_color) except ValueError: raise InvalidMenuItemColorException() if branding_url: # Already download branding to validate url resp = urlfetch.fetch(branding_url, deadline=60) if resp.status_code != 200: raise BrandingNotFoundException() if not is_branding(resp.content, Branding.TYPE_NORMAL): raise BrandingValidationException( "Content of branding download could not be identified as a branding" ) # Raises if service already existed # If a solution is provided, bypass the service creator validation by calling create_service directly. if not solution: solution = validate_and_get_solution(users.get_current_user()) create_service(email, name, password, languages, solution, category_id, organization_type, fail_if_exists, supported_app_ids=apps, owner_user_email=owner_user_email) new_service_user = users.User(email) to_be_put = list() settings = get_solution_settings(new_service_user) if not settings: settings = SolutionSettings( key=SolutionSettings.create_key(new_service_user), name=name, menu_item_color=menu_item_color, address=address, phone_number=phone_number, currency=currency, main_language=languages[0], solution=solution, search_enabled=search_enabled, modules=modules or list(), broadcast_types=broadcast_types or list()) if owner_user_email: settings.qualified_identifier = owner_user_email if settings.uses_inbox(): settings.inbox_email_reminders_enabled = True settings.inbox_mail_forwarders.append( settings.qualified_identifier) settings.login = users.User( owner_user_email) if owner_user_email else None settings.holidays = [] settings.holiday_out_of_office_message = common_translate( settings.main_language, SOLUTION_COMMON, 'holiday-out-of-office') to_be_put.append(settings) main_branding = SolutionMainBranding( key=SolutionMainBranding.create_key(new_service_user)) to_be_put.append(main_branding) main_branding.branding_key = None if branding_url: main_branding.blob = db.Blob(resp.content) else: # Branding will be generated during provisioning bs = _get_default_branding_settings(new_service_user) with open( os.path.join(os.path.dirname(__file__), '..', 'templates', 'main_branding', 'logo.jpg'), 'r') as f: sl = SolutionLogo(key=SolutionLogo.create_key(new_service_user), picture=db.Blob(f.read()), is_default=True) to_be_put.extend([bs, sl]) put_and_invalidate_cache(*to_be_put) if solution == SOLUTION_FLEX: deferred.defer(service_auto_connect, new_service_user, _transactional=db.is_in_transaction()) return password, settings