def setUp(self): self.user_id = 1 self.exercise_name = "Arnold Press" self.username = "******" created_on = get_timestamp() record_repository.save_workout_as_record( Record(self.exercise_name, 12, 3, self.username, created_on))
def es_get_doc(time_str, compute_type, ret_key, ret_value): timestamp = util.get_timestamp(time_str) data = { "@timestamp": timestamp, "platform": ret_key[0], "channel": ret_key[1], "count": ret_value[0], "type": compute_type } return json.dumps(data)
def setUp(self): self.test_username = "".join( random.choice(string.ascii_lowercase) for _ in range(10)) self.test_email = "".join( random.choice(string.ascii_lowercase) for _ in range(10)) self.test_password = "".join( random.choice(string.ascii_lowercase) for _ in range(10)) created_on = get_timestamp() user_repository.add_new_user( User(self.test_username, self.test_email, self.test_password, created_on))
def es_get_doc(time_str, login_count, platform, channel): timestamp = util.get_timestamp(time_str) channel = channel.lower() if channel in CHANNELS: channel = CHANNELS[channel] data = { "@timestamp": timestamp, "count": login_count, "platform": platform.lower(), "channel": channel } return json.dumps(data)
def signup_user(self, username, email, password): """Luo User-olion ja tallettaa sen tietokantaan jos ei tälläinen käyttäjänimi eikä sähköpostiosoite on varattu""" user_by_username = self._user_repo.get_user_by_usename(username) user_by_email = self._user_repo.get_user_by_email(email) if user_by_email or user_by_username: return False hash_value = encrypt_password(password) created_on = get_timestamp() result = self._user_repo.add_new_user( User(username, email, hash_value, created_on) ) return result
def es_get_doc(time_str, compute_type, ret_key, device, count): timestamp = util.get_timestamp(time_str) data = { "@timestamp": timestamp, "type": compute_type, "platform": ret_key[1], "channel": ret_key[2], "vendor": device[0], "model": device[1], "count": count } return json.dumps(data)
def save_workout(self, exercise, sets, reps, username): """Tallentaa suoritetun harjoituksen suorituksena Attributes: exercise: Kuvaa suoritetun harjoituksen nimettä sets: Kuvaa sarjojen määrää reps: Kuvaa toistojen määrää reps: Kuvaa käyttäjätunnusta """ created_on = get_timestamp() result = self._record_repo.save_workout_as_record( Record(exercise, sets, reps, username, created_on)) return result
def es_get_doc(time_str, ret_key, ret_value): timestamp = util.get_timestamp(time_str) data = { "@timestamp": timestamp, "type": ret_key[0], "platform": ret_key[1], "channel": ret_key[2] } if "churn_rate" in ret_key[0]: data["login_count"] = ret_value[0] data["create_count"] = ret_value[1] else: data["count"] = ret_value return json.dumps(data)
def es_add_track_doc(time_str, compute_type, ret_key, ret_value): path = ES_INDEX + \ "/_doc/" + es_get_doc_id( time_str, ret_key[1], ret_key[2], compute_type + "_" + ret_key[0]) data = { "@timestamp": util.get_timestamp(time_str), "type": compute_type, "sub_type": ret_key[0], "platform": ret_key[1], "channel": ret_key[2], "login_count": ret_value[0], "create_count": ret_value[1] } es.add_doc(path, json.dumps(data))
def test_add_new_user(self): test_user = { "username": "******", "email": "*****@*****.**", "password": "******", } created_on = get_timestamp() result = user_repository.add_new_user( User( test_user["username"], test_user["email"], test_user["password"], created_on, )) self.assertEqual(True, result)
def test_save_workout_as_record(self): created_on = get_timestamp() result = record_repository.save_workout_as_record( Record("test", 12, 3, "test123", created_on)) self.assertEqual(result, True)